/*********************************************************************************************************************************/
/* DOCUMENT READY CALLS **********************************************************************************************************/
/*********************************************************************************************************************************/

$(document).ready(function(){
	
	/* EXTERNAL LINKS start ***********************************************************/
	$('a[rel="external"]').click(function(){
		this.target = "_blank";
	});
	/* EXTERNAL LINKS end *************************************************************/
	
	$('html').addClass('js');
	
	if( $('#landing').length >0 ){
		$('html').addClass('landing');
	}
	
	/* SLIDESHOW start ***************************************************************/
	var slideshow = setInterval( "slideSwitch('#slideshow span',500,'Next')", 5000 );
	$('#slideshow .nav a').click(
		function(){
			clearInterval(slideshow);
			var direction = $(this).attr('title');
			slideSwitch(direction);
		}
	);
	/* SLIDESHOW end *****************************************************************/
		
}); //close document.ready

/*********************************************************************************************************************************/
/* DOCUMENT READY FUNCTIONS ******************************************************************************************************/
/*********************************************************************************************************************************/
Cufon.replace('#content > h1,#main > h1');

/* SLIDESHOW function start *********************************************************/
function slideSwitch(selector,opacity_speed,direction) {
	var $active = $(selector+'.active');

	if ( $active.length == 0 ) $active = $(selector+':first');	
	
	if(direction == 'Next' || direction == null){ var $next = $active.next().length ? $active.next() : $(selector+':first'); }
	else if(direction == 'Previous') { var $next = $active.prev().length ? $active.prev() : $(selector+':last'); }	

	$active.addClass('last-active');

	$next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, opacity_speed, function() {
			 $active.removeClass('active last-active');
	});
	
}
/* SLIDESHOW function end ***********************************************************/
