//our brand rotator
function theRotator() {
	//Set the opacity of all h3 to 0.5
	$('.batches h3').css({opacity: 0});
	
	//Get the first h3 and display it (gets set to full opacity)
	$('.batches h3:first').css({opacity: 1.0});
	
	//Set the opacity of all li to 0.5
	$('.intro ul li').css({opacity: 0});
	
	introstr = '';
	$('.intro ul li').each(function(i,o){
		introstr += '<a href="#" title='+ i + ' class="slidePoint1"></a> ';
	});
	
	$('.intro').after(introstr);
	
	//Get the first li and display it (gets set to full opacity)
	$('.intro ul li:first').css({opacity: 1.0});
	
	//Set the opacity of all li to 0.5
	$('.innerGallery ul li').css({opacity: 0});
	
	//Get the first li and display it (gets set to full opacity)
	$('.innerGallery ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next div after 6 seconds
	setInterval('rotate()',6000);
	
	//Call the rotator function to run the slideshow, 10000 = change to next div after 6 seconds
	HPGalleryInterval = setInterval('rotateHPGallery()',8000);
	
	//Call the rotator function to run the slideshow, 6000 = change to next div after 6 seconds
	setInterval('rotateGalleryInner()',5000);
	
}

//Home page sidebar features
function rotate() {	
	//Get the first image
	var current = ($('.batches h3.show')?  $('.batches h3.show') : $('.batches h3:first'));
 
	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('.batches h3:first') :current.next()) : $('.batches h3:first'));
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);
 
	//Hide the current image
	current.animate({opacity: 0}, 1000)
	.removeClass('show');	
};

//Home page gallery
function rotateHPGallery() {	

	if(HPGalleryStop == 0){
		//Get the first image
		var current = ($('.intro ul li.show')?  $('.intro ul li.show') : $('.intro ul li:first'));
	 
		//Get next image, when it reaches the end, rotate it back to the first image
		var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('.intro ul li:first') :current.next()) : $('.intro ul li:first'));
		
		//Set the fade in effect for the next image, the show class has higher z-index
		next.css({opacity: 0})
		.addClass('show')
		.animate({opacity: 1.0}, 1000);
	 	idNext = $(next).index();
	 	
	 
		//Hide the current image
		current.animate({opacity: 0}, 1000)
		.removeClass('show');	
		if(idNext == 1 || idNext == 2)
	 		$("#internetCoupon").fadeOut();
	 	else
	 		$("#internetCoupon").fadeIn();
	 	$(".slidePoint1").removeClass('sel');
	 	$(".slidePoint1[title="+idNext+"]").addClass('sel');
	 }
};

//Inner page gallery
function rotateGalleryInner() {	
	//Get the first image
	var current = ($('.innerGallery ul li.show')?  $('.innerGallery ul li.show') : $('.innerGallery ul li:first'));
 
	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('.innerGallery ul li:first') :current.next()) : $('.innerGallery ul li:first'));
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);
 
	//Hide the current image
	current.animate({opacity: 0}, 1000)
	.removeClass('show');	
};
 
 
var HPGalleryStop = 0;
var HPGalleryInterval;
$(document).ready(function() {		
	//Load the slideshow
	theRotator();
	//Load the home page slideshow
	rotateHPGallery();
	
	$(".slidePoint1").live('click', function(i,o){
		clearInterval(HPGalleryInterval);
		HPGalleryStop = 1;
		var slideNo = $(this).attr('title');
		var current = ($('.intro ul li.show')?  $('.intro ul li.show') : $('.intro ul li:first'));
		var next = $('.intro ul li').eq(slideNo);
		
		if($(current).index() != slideNo){
			next.css({opacity: 0})
			.addClass('show')
			.animate({opacity: 1.0}, 1000);
			
			idNext = $(next).index();
		 	
		 
			//Hide the current image
			current.animate({opacity: 0}, 1000)
			.removeClass('show');	
			if(idNext == 1 || idNext == 2)
		 		$("#internetCoupon").fadeOut();
		 	else
		 		$("#internetCoupon").fadeIn();
		 	$(".slidePoint1").removeClass('sel');
	 		$(this).addClass('sel');
		}
		return false;
	});
	$(".stopRotatorAndOpenThickbox").live('click', function(){
		clearInterval(HPGalleryInterval);
		HPGalleryStop = 1;		
		//return false;
	});
	
});



