$(document).ready(function(){
    
    //News Link
    $('.1081').css('color','#F1912B');
    
    //Twetememe Iframe General IE Fix
	if(navigator.appName == "Microsoft Internet Explorer"){
	    $('iframe').attr('allowTransparency','true');
    }
    
	if($('div.exp').length){$('div.exp').hide();}
	if($('div.exp:first').length){$('div.exp:first').animate({height:'toggle'});}
	
	if($('div.exp').length){$('div.exp:first').prev().animate({'padding-top':'30'},300);}
	
	if($('div.togglewrap img:first').length){$('div.togglewrap img:first').attr('src','/images/tab-white-close.png');}
	if($('#anaresults').length){$('#anaresults').hide();}
	if($('#menuwrap').length){$('#menuwrap').hide();}
	if($('div.info').length){$('div.info').hide();}
	if($('div.clientwrapper').length){$('div.clientwrapper').hide();}
	
	if($('#profilepic1').length){$('#profilepic1').css('opacity','0');}
	if($('#profilepic2').length){$('#profilepic2').css('opacity','0');}
	if($('#profilepic3').length){$('#profilepic3').css('opacity','0');}
	
	if($('ul.clientlist').length){$('ul.clientlist li').css('opacity','0');}
	if($('div.more').length){$('div.more div.thumb').css('opacity','0');}
	
	if($('img.toggletab').length){
		$('img.toggletab').click(function(){
			if ($(this).is('.orange')) {
				if ($(this).prev().css('display')=='none') {
					$(this).attr('src','/images/tab-white-close.png');
				 } else {
					$(this).attr('src','/images/tab-white-open.png');
				 }
			} else {
				if ($(this).prev().css('display')=='none') {
					$(this).attr('src','/images/tab-orange-close.png');
				} else {
					$(this).attr('src','/images/tab-orange-open.png');
				}
			}
			$($(this).prev()).animate({height:'toggle'});
		});
	}
	
	if($('img.toggletab').length){
		$('img.toggletab').hover(function() {
			$(this).css('cursor','pointer');
		}, function() {
			$(this).css('cursor','auto');
		});
	}
	
	if($('ul.topmenu li a.drop').length){
		$('ul.topmenu li a.drop').click(function(){
			$('#menuwrap').animate({height:'toggle'},500,'easeInOutQuad');
			return false;
		});
	}
	
	if($('a.home').length){
		$('a.home').click(function(){
			$('#menuopener ul li a').removeClass('on');
			$('#menuopener ul li a.home').addClass('on');
		});
	}
	
	if($('a.1081').length){
		$('a.1081').click(function(){
			$('#menuopener ul li a').removeClass('on');
			$('#menuopener ul.1081 li a').addClass('on');
		});
	}

	if($('a.1082').length){
		$('a.1082').click(function(){
			$('#menuopener ul li a').removeClass('on');
			$('#menuopener ul.1082 li a').addClass('on');
		});
	}

	if($('a.1085').length){
		$('a.1085').click(function(){
			$('#menuopener ul li a').removeClass('on');
			$('#menuopener ul.1085 li a').addClass('on');
		});
	}

	if($('a.1086').length){
		$('a.1086').click(function(){
			$('#menuopener ul li a').removeClass('on');
			$('#menuopener ul.1086 li a').addClass('on');
		});
	}
	
	if ($('div.subnav a').length) {
		$('div.subnav a:last').css('border','none');
	}
	
	if (('#questionbox').length) {
		var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
		$("#questionbox").autocomplete(months, {
			minChars: 0,
			max: 5,
			autoFill: true,
			mustMatch: true,
			matchContains: false,
			scrollHeight: 220,
			formatItem: function(data, i, total) {
				// don't show the current month in the list of values (for whatever reason)
				if ( data[0] == months[new Date().getMonth()] ) 
					return false;
				return data[0];
			}
		});
	}

	$('img').imagesLoaded(function(){
		if($('#profilepic1').length){$('#profilepic1').pause(100).animate({opacity:1},1000);}
		if($('#profilepic2').length){$('#profilepic2').pause(250).animate({opacity:1},1000);}
		if($('#profilepic3').length){$('#profilepic3').pause(400).animate({opacity:1},1000);}

		if($('ul.clientlist').length){
			var counter = 0;
			$('ul.clientlist li').each(function(){
				counter += 75;
				$(this).pause(counter).animate({opacity:1},300);
			});
		}

		if($('div.more').length){
			var counter = 0;
			$('div.more div.thumb').each(function(){
				counter += 75;
				$(this).pause(counter).animate({opacity:1},300);
			});
		}

	});
	
	if($('ul.clientlist').length){
		$('ul.clientlist li a img').tooltip({
			track:true,
			showURL:false,
			fixPNG:true
		})
	}
	
	if($('a.viewmore').length){
		$('a.viewmore').click(function(){
			$('div.clientwrapper').animate({height:'toggle'},1000);
			return false;
		});
	}
	
	if ($('div.togglesectionwrap')){
		$('div.togglewrap img').toggle(function(){
			var stateBool = ($(this).parent().parent().find('div.exp').css("display"))=="none";
			var state = stateBool ? "close":"open";
			var header = $(this).parent().parent().find('p.header');
			var col;
			if ($(this).parent().parent().hasClass("orange")) {
				col = "orange";
			} else if ($(this).parent().parent().hasClass("lightorange")) {
				col = "lightorange";
			} else {
				col = "white";
			}
			$(this).attr("src","/images/tab-"+col+"-"+state+".png");
			$(this).parent().parent().find('div.exp').animate({height:'toggle'},300);
			stateBool ? header.animate({'padding-top':'30'},300) : header.animate({'padding-top':'15'},300);
		},
		function(){
			var stateBool = ($(this).parent().parent().find('div.exp').css("display"))=="none";
			var state = stateBool ? "close":"open";
			var header = $(this).parent().parent().find('p.header');
			var col;
			var state = stateBool ? "close":"open";
			var header = $(this).parent().parent().find('p.header');
			var col;
			if ($(this).parent().parent().hasClass("orange")) {
				col = "orange";
			} else if ($(this).parent().parent().hasClass("lightorange")) {
				col = "lightorange";
			} else {
				col = "white";
			}
			$(this).attr("src","/images/tab-"+col+"-"+state+".png");
			$(this).parent().parent().find('div.exp').animate({'height':'toggle'},300);
			stateBool ? header.animate({'padding-top':'30'},300) : header.animate({'padding-top':'15'},300);
		}
		);
	}
	
	$(".carousel").jCarouselLite({
		btnNext: ".carousel-next",
		btnPrev: ".carousel-prev",
		easing: "easeInOutQuad",
		speed: 1000,
		scroll: 3
	});
	
	$(".left .smlcarousel").jCarouselLite({
		btnNext: "div.left img.previous",
		btnPrev: "div.left img.next",
		easing: "easeInOutQuad",
		speed: 1000,
		scroll: 3
	});
	
	$(".right .smlcarousel").jCarouselLite({
		btnNext: "div.right img.previous",
		btnPrev: "div.right img.next",
		easing: "easeInOutQuad",
		speed: 1000,
		scroll: 3
	});
	
});

$.fn.imagesLoaded = function(callback){
  var elems = this.filter('img'),
  len = elems.length;
  elems.bind('load',function(){
      if (--len <= 0){ callback.call(elems,$(this)); }
  }).each(function(){
      if (this.complete || this.complete === undefined){ this.src = this.src; }
  });
}

$('img.toggletab').hover(function() {
	$(this).css('cursor','pointer');
}, function() {
	$(this).css('cursor','auto');
});

$.fn.pause = function(duration) {
    $(this).animate({ dummy: 1 }, duration);
    return this;
};
