// JavaScript Document

var initShow = false;
var disabledShow = false;

var initPromo = false;
var disabledPromo = false;

function showSlide(slide){
	
	//	animate to "slide" param, and disable the auto advancement 
	//	since the user clicked a slide manually	
	$('#slide_show').cycle(slide);	
	if (!disabledShow) {
		$('#slide_show').cycle('toggle');
		disabledShow = !disabledShow;
	}
}

function showPromo(slide){
	
	//	animate to "slide" param, and disable the auto advancement 
	//	since the user clicked a slide manually	
	$('#promo_show').cycle(slide);	
	if (!disabledPromo) {
		$('#promo_show').cycle('toggle');
		disabledPromo = !disabledPromo;
	}
}

function showNav(slide, elem){
	// Remove '.selected' class from the nav elements
	$(elem).each(function(){
		if($(this).is('.selected')){
			$(this).stop(true, true).removeClass('selected');	
		}
	});
	
	// Add '.selected' class to right nav element
	slide++;
	$(elem+':nth-child('+slide+')').stop(true, true).addClass('selected',300);
}


// Jquery functinos for front page
$(document).ready(function(){ 
	
	// slide show					   
	$('#slide_show').cycle({ 
		fx:    'fade',
		timeout:11000,
		sync: 0,
		autostop:true,
		autostopCount:5,
		before: function(currSlideElement, nextSlideElement, opts, forwardFlag){
				(initShow) ? (showNav(opts.nextSlide,'#slide_show_nav ul li')) : (initShow = !initShow);				
			}
	});
	
	//promo slide show
	$('#promo_show').cycle({ 
		fx:    'fade',
		timeout:6000,
		sync: 0,
		before: function(currSlideElement, nextSlideElement, opts, forwardFlag){
			(initPromo) ? (showNav(opts.nextSlide,'#promo_show_nav ul li')) : (initPromo = !initPromo);				
		}
	});

	
});
