/*********************************************************************************************************************************/
/* DOCUMENT READY CALLS **********************************************************************************************************/
/*********************************************************************************************************************************/

$(document).ready(function(){
	
	/* EXTERNAL LINKS start ***********************************************************/
	$('a[rel="external"],#nav-blog a').click(function(){
		this.target = "_blank";
	});
	/* EXTERNAL LINKS end *************************************************************/
	
	$('html').addClass('js');

	/*SEARCH start ********************************************************************/
	$('#search input[type="text"]').val('Search');
	$('#search input[type="text"]').focus(function(){ if(this.value=='Search') { $(this).val('');} });
	$('#search input[type="text"]').blur(function(){ if(this.value =='') { $(this).val('Search');} });
	/*SEARCH end **********************************************************************/
	
	/* find solution*/
	$('#find-solution h3').click(
		function(){
			$('h3').removeClass('active');
			$('h3').next('ul').removeClass('active');
			$display = $(this).next('ul');
			
			if($(this+':not(.active)')){
				$(this).addClass('active');
				$display.addClass('active');
			}
		}
	);
	/* find solution*/
	
	/* SLIDESHOW start ***************************************************************/
	var slideshow_photos = setInterval( "slideSwitch('#slideshow','p',800,'Next')", 8000 );
	var slideshow_nav = setInterval( "slideSwitch('#slideshow .nav','a',100,'Next')", 8000 );
	$('#slideshow .nav a').click(
		function(){
			clearInterval(slideshow_photos);
			clearInterval(slideshow_nav);
			$('#slideshow p').removeClass('active');
			$('#slideshow .nav a').removeClass('active');
			var photo = $(this).attr('rel');
			$('#'+photo).addClass('active');
			$(this).addClass('active');
		}
	);
	/* SLIDESHOW end *****************************************************************/
	if($('#page-gallery').length){
		$('#page-gallery .carousel .display').jCarouselLite({ btnNext: "#page-gallery .carousel .right", btnPrev: "#page-gallery .carousel .left",speed: 500,visible: 2,scroll: 2,circular:false });
	}
	
}); //close document.ready

/* ******************************************************************************************************************************* */
/* DOCUMENT READY FUNCTIONS ****************************************************************************************************** */
/* ******************************************************************************************************************************* */
Cufon.replace('#intro > h2,#page-title');

/* SLIDESHOW function start *********************************************************/
function slideSwitch(selector,element,opacity_speed,direction) {
	var selector = selector+' '+element;
	var $active = $(selector+'.active');

	if ( $active.length == 0 ) $active = $(selector+':first');
	
	if(direction == 'Next' || direction == null){ var $next = $active.next(element).length ? $active.next(element) : $(selector+':first'); }
	else if(direction == 'Previous') { var $next = $active.prev(element).length ? $active.prev(element) : $(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 ***********************************************************/
