/*********************************************************************************************************************************/
/* DOCUMENT READY CALLS **********************************************************************************************************/
/*********************************************************************************************************************************/

$(document).ready(function(){
	
	/* EXTERNAL LINKS start ***********************************************************/
	$('a[rel="external"]').click(function(){
		this.target = "_blank";
	});
	/* EXTERNAL LINKS end *************************************************************/
	
	/* NAVIGATION start ***************************************************************/
	$('#nav ul ul ul').hide();
	$('#nav ul ul').hide();
	//hover show next level
	$('#nav ul > li').hover(function() { 
		$('ul:first', this).show();
	 	$('a:first',this).addClass('hover'); },
	 	function() {
			$('ul:first', this).hide(); 
			$('a:first',this).removeClass('hover'); 
	});
	//add class for flyouts
	if ($('#nav ul ul ul,#nav-top ul ul ul').length > 0) { $('#nav ul ul ul',this).prev().parent().addClass('flyout'); }
	/* NAVIGATION end ****************************************************************/
	
	/* SLIDESHOW start ***************************************************************/
	setInterval( "slideSwitch()", 5000 );
	if($('#services').length){
		setInterval( "slideSwitchLanding()", 5000 );
	}
	/* SLIDESHOW end *****************************************************************/
		
}); //close document.ready

/*********************************************************************************************************************************/
/* DOCUMENT READY FUNCTIONS ******************************************************************************************************/
/*********************************************************************************************************************************/

/* SLIDESHOW function start *********************************************************/
function slideSwitch() {
	var $active = $('#slideshow span.active');

	if ( $active.length == 0 ) $active = $('#slideshow span:last');

	var $next =  $active.next('span').length ? $active.next()
			: $('#slideshow span:first');

	$active.addClass('last-active');
	
	$next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 500, function() {
			 $active.removeClass('active last-active');
	});
	
}
function slideSwitchLanding() {
	var $services = $('#services li');
	if($services.hasClass('active1')){ $services.removeClass('active1'); slideSwitchLandingAnimate($services,2); }
	else if($services.hasClass('active2')){ $services.removeClass('active2'); slideSwitchLandingAnimate($services,3); }
	else if($services.hasClass('active3')){ $services.removeClass('active3'); slideSwitchLandingAnimate($services,1); }	
}
function slideSwitchLandingAnimate($services,num){
	
	$services.css({opacity: 0.0})
			.addClass('active'+num)
			.animate({opacity: 1.0}, 500);
}
/* SLIDESHOW function end ***********************************************************/