

$(document).ready(function() {
	
	swfobject.embedSWF("/media/images/camco_timeline_228.swf", "swfHist", "572", "191", "9.0.0");
// ===========
// = New more widget
// ===========
$('.moreBiog dd').hide();
$('.moreBiog .moreLink').click(function(){newMoreWidget($(this).parents('.moreBiog'))});
	
// ===========
// = Contact form
// ===========
	$('div.contactList div.table').hide();

	$('div.contactList div.title').click(function(){contactClick($(this))});
	
// ===========
// = Captcha =
// ===========
	$('li#whatIsCaptcha').hide();
	$("fieldset.question").hover(
      function(){
       $('li#whatIsCaptcha').slideDown();
      }, 
      function(){
        $('li#whatIsCaptcha').slideUp();
      });
    
// ==================
// = Download Hover =
// ==================
	$('a.download').hover(
		function(){
			$(this).children('span.downloadhover').css({display:'block'});
		},
		function(){
			$(this).children('span.downloadhover').css({display:'none'});
		});
// ==================
// = Sites Dropdown =
// ==================
	$("ul#SitesList li#headlink").hoverIntent(headlink);

// ===========
// = Tooltip =
// ===========
	/* create markup needed */
	$("div.MDescription").wrap('<div class="MDescOutWrap"></div>');
	$("div.MDescription").after("<div class='MDBottom'> </div>");
	/* override non-javascript styles */
	$("ul.TeamList li").css({width:'106px',height:'195px',minHeight:'auto',float:'left',padding:'0 6px 0 0',margin:'0 0 1px 0',clear:'none',position:'relative'});
	$("div.Member").css({width:'auto'});
	$("div.MDescription").css({background:'#e31937',width:'228px',margin:'0',color:'#FFFFFF'});
	$("div.MDescription p").css({padding:'0 12px 10px',margin:'0',fontSize:'11px',lineHeight:'17px'})

	$("ul.TeamList").each(function(){
		for(i = 0; i < $(this).children('li').length; i++) {
			if((i%5)%3 == 0 && (i%5) !=0 ) {
				$(this).children('li').eq(i).children('div.Member').addClass('last');
			}
			else if((i%5)%4 == 0 && (i%5) != 0) {
				$(this).children().eq(i).children('div.Member').addClass('last');
			}
		}
	});

		
		$("div.Member").children("div.MDescOutWrap").css({position:'absolute',top:'0',right:'-223px',width:'228px',background:'url(/media/images/bg_tooltip_top_128.png) no-repeat left top',padding:'12px 0 0 18px',zIndex:'98',display:'none'});
		$("div.Member").children("div.MDescOutWrap").addClass("png");
		$("div.Member div.MDescOutWrap").children("div.MDBottom").css({clear:'both',background:'url(/media/images/bg_tooltip_bottom_129.png) no-repeat left top',height:'12px',width:'228px'});
		$("div.Member div.MDescOutWrap").children("div.MDBottom").addClass("png");
		$("div.Member").children("div.MDetails").css({position:'absolute',top:'137px',left:'0'});
		
		$("div.last").children("div.MDescOutWrap").css({position:'absolute',top:'0',right:'112px',width:'228px',background:'url(/media/images/bg_tooltip_top_l_130.png) no-repeat right top',padding:'12px 18px 0 0px',zIndex:'98',display:'none'});
		$("div.last").children("div.MDescOutWrap").addClass("png");
		$("div.last div.MDescOutWrap").children("div.MDBottom").css({clear:'both',background:'url(/media/images/bg_tooltip_bottom_l_131.png) no-repeat left top',height:'12px',width:'228px'});
		$("div.last div.MDescOutWrap").children("div.MDBottom").addClass("png");
		$("div.last").children("div.MDetails").css({position:'absolute',top:'137px',left:'0'});
		

	
	/* activate the tooltip */
	$("ul.TeamList li div.Member").hoverIntent(tooltip);
	$("div.NonTextBody").fadeIn('fast');

// ================
// = Facts Picker =
// ================
	var li_height = $("li.quote").css("height");
	var current_quote = 0;
	var old_quote = 0;
	var quote_count = $("li.quote").size();
	var ul_height = li_height*quote_count;
	li_height = "-" + parseInt(li_height)
	$("div.RightTopBlockInner span.cover").fadeOut("fast");
	
	setInterval(function(){
		current_quote = current_quote +1;
		if(current_quote < quote_count){
			$("div.RightTopBlockInner span.cover").fadeIn("fast", function(){
				$("div.RightTopBlockInner ul").animate({top:current_quote * li_height +"px"}, "fast", function(){
					$("div.RightTopBlockInner span.cover").fadeOut("fast");
				});
			});
		}else{
			$("div.RightTopBlockInner span.cover").fadeIn("fast", function(){
				$("div.RightTopBlockInner ul").animate({top: "0px"}, "fast", function(){
					$("div.RightTopBlockInner span.cover").fadeOut("fast");
				});
			});
			current_quote = 0;
		}	
	},15000);	

// ===================
// = Top Nav=
// ===================
	
	$('ul#TopNavigation li div.dropnav').each(
		function(){
			$(this).width($(this).parents('li').width());
		}
	)
	
	$('ul#TopNavigation li').hover(
	function(){
		$(this).addClass('hovered');
		$(this).children('div.dropnav').css({"left":"-6px"});
	},
	function(){
		if($())
		$(this).removeClass('hovered');
		$(this).children('div.dropnav').css({"left":"-999em"});
	});

// ===================
// = World Map Calls =
// ===================
	$('div#WorldMap div').hoverIntent( worldmap );
	$('div#countriesList ul li a').hoverIntent( worldmap );
	
// ===================
// = DL show list calls =
// ===================
	$('div.questionsWidget dl dt').click(function(){dtClick($(this))});


// =====================
// = Contact Map Calls =
// =====================
	$('div#ctcWorldMap div').hoverIntent( contact );
// =======================
// = Case Studies Boxout =
// =======================
	$('div.RedBox').hover(function(){
		
	},function(){
		$('div.CSinfo').fadeOut("fast");
		$('div.CSinfo').removeClass('Open');
	});
	
	$('div.RBContent ul li a').hoverIntent(CaseStudy);
	
// ==========
// = Search =
// ==========	
	$('div.top button').click(function(){
		$('ul.advSearch').slideDown("fast");
		$(this).hide();
		return false
	})
// ==================
// = More Widget... =
// ==================
	
	$('div.moreWidget').hide();
	$('a.moreLink').css({display:'block'});
	$('a.moreLink').click(function(){
		if($(this).is('.open')){
			$('div.moreWidget').slideUp('fast',function(){
				$('a.moreLink').text('More...');
			});
			$(this).removeClass('open');
			return false
		}else{	
			$('div.moreWidget').slideDown('fast',function(){
				$('a.moreLink').text('Less...');
			});
			$(this).addClass('open');
			return false
		};
	});

}); // END OF DOC READY FUNCTION


// =======================
// = World Map Functions =
// =======================
var worldmap = {
	sensitivity: 5,
	interval: 0, 
	over: faderIn, 
	timeout: 0,
	out: faderOut};
var p_name;

function faderIn(){
if($(this).is('div')){
	$(this).children().children("span").show();
	p_name = 'a#' + $(this).children().children("span").attr('id') + '_link';
	$(p_name).addClass('hovered');
}else{
	$(this).addClass('hovered');
	p_name = 'span#' + $(this).attr('id');
	p_name = p_name.slice(0, -5)
	$(p_name).show();
}
};
function faderOut(){
if($(this).is('div')){
	$(this).children().children("span").hide();
	p_name = 'a#' + $(this).children().children("span").attr('id') + '_link';
	$(p_name).removeClass('hovered');
}else{
	$(this).removeClass('hovered');
	p_name = 'span#' + $(this).attr('id');
	p_name = p_name.slice(0, -5)
	$(p_name).hide();
}
};	
// =======================
// = Contact Map Functions =
// =======================
var contact = {
	sensitivity: 5,
	interval: 100, 
	over: ctcfaderIn, 
	timeout: 100,
	out: ctcfaderOut};
var p_name;
function ctcfaderIn(){
	p_name = 'p#' + this.id + 'text';
	$(p_name).fadeIn(700);
	$(this).children().children("span").fadeIn(700);
};
function ctcfaderOut(){
	$(p_name).fadeOut(500);
	$(this).children().children("span").fadeOut(500);
};
// =============================
// = Global Dropdown functions =
// =============================
var headlink = {
	sensitivity: 5,
	interval: 100, 
	over: headlinkdown, 
	timeout: 800,
	out: headlinkup
}
function headlinkdown(){$(this).children("ul").slideDown("fast")};
function headlinkup(){$(this).children("ul").slideUp("fast")};

// ========================
// = Case Study Functions =
// ========================
var CaseStudy = {
		sensitivity: 10,
		interval: 50, 
		over: CasestudyOver, 
		timeout: 50,
		out: CasestudyUp}
function CasestudyOver(){
	current = $(this).parent().siblings('div.CSinfo')
	if(current.is('.Open')){
		return false;
	}else{
		$('div.Open').fadeOut("fast",function(){$(this).removeClass('Open')});
		current.fadeIn("fast",function(){current.addClass('Open')});
		return false;
	};
};
function CasestudyUp(){
	
};
// ===========================
// = HoverIntent for Tooltip =
// ===========================
var tooltip = {
	sensitivity: 10,
	interval: 50, 
	over: Toolover, 
	timeout: 50,
	out: Tooloff
};
function Toolover () {
    $(this).children("div.MDescOutWrap").fadeIn('fast');
	$("ul.TeamList li").css({zIndex:'-1'});
	$(this).parent("li").css({zIndex:'98'});
  }
  function Tooloff() {
    $(this).children("div.MDescOutWrap").fadeOut('fast',function(){$("ul.TeamList li").css({zIndex:'98'});});
  }
 
 // ===========================
// = questions widget clicker functions =
// ============================
function dtClick(e){
	if(e.is('.open')){
		e.next('dd').slideUp('fast');
		e.removeClass('open');		
	}else{
		e.next('dd').slideDown('fast');
		e.addClass('open');
	}
}

 // ===========================
// = contact map clicker functions =
// ============================
function contactClick(e){
	if(e.is('.openTitle')){
		e.next('div.table').slideUp('fast');
		e.removeClass('openTitle');		
	}else{
		e.next('div.table').slideDown('fast');
		e.addClass('openTitle');
	}
}
// ===================
// = new more widget =
// ===================
function newMoreWidget(e){
	if(e.is('.open')){
		e.children('.rightContent').children('dl').children('dd').slideUp('fast');
		e.removeClass('open');
		e.children('.rightContent').children('.moreLink').html('More');	
	}else{
		e.children('.rightContent').children('dl').children('dd').slideDown('fast');
		e.addClass('open');
e.children('.rightContent').children('.moreLink').html('Less');
	}
}


$(document).ready(function() {$(".userform").validate();})


$(document).ready(function(){

	if($("div.homewidgetslider").length > 0 ){homeWidget();};

});

function homeWidget(){
	
	 jQuery('#mycarousel').jcarousel({
    	auto: 6,
    	wrap: 'circular',
        initCallback: mycarousel_initCallback,
        itemFirstInCallback: {
  			onBeforeAnimation: hideSelected,
  			onAfterAnimation: selectBox
		}
    });
	
		$('div.sliderarticle').show();
		
	$(".jcarousel-item").click(function(e){
	 	
		$('.selectedbox').removeClass('selectedboxselected');
		$('li.jcarousel-item').removeClass('slideSelected');
		$(this).addClass('slideSelected');
		var slidenumber = $(this).attr('jcarouselindex');
		if(slidenumber>0){
		slidenumber= slidenumber%3;
		if(slidenumber == 1){$('.selectedboxleft').addClass('selectedboxselected');}
		if(slidenumber == 2){$('.selectedboxcenter').addClass('selectedboxselected');}
		}
		
		if(slidenumber<0){
		slidenumber= slidenumber*-1;
		slidenumber= slidenumber%3;
		if(slidenumber == 2){$('.selectedboxleft').addClass('selectedboxselected');}
		if(slidenumber == 1){$('.selectedboxcenter').addClass('selectedboxselected');}
		}
		
		if(slidenumber == 0){$('.selectedboxright').addClass('selectedboxselected');}
		
		slidecontent=$(this).find(".slideContent").clone();
		
		$(".slideContentContainer").empty();
		$(".slideContentContainer").append(slidecontent);
		$(".slideContentContainer .slideContent").fadeIn(300);
	}); 
}

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

function hideSelected(){

	$('.selectedbox').removeClass('selectedboxselected');
	$(".slideContentContainer .slideContent").fadeOut(600);
	$('li.jcarousel-item').removeClass('slideSelected');

}

function selectBox(jcarousel_object, li_object, index, state){

	$('.selectedboxleft').addClass('selectedboxselected');
	slidecontent=$(li_object).find(".slideContent").clone();
	$(li_object).addClass('slideSelected');
		
		$(".slideContentContainer").empty();
		$(".slideContentContainer").append(slidecontent);
		$(".slideContentContainer .slideContent").fadeIn(300);
}




