// JavaScript Document
var hsPos = 1;
var hsTime = 0;
var holdShow = 0;
$(document).ready(function () {
	
	elements = $('a.slideShowNav');
	elements.each( function() { 
		$(this).click( function(){ 			
			 var num = $(this).attr('data');
			 hsPos = num;			 
			 hsTime = Math.round(new Date().getTime() / 1000);
			 
			 num = '-' + ((num-1) * 930) + 'px';
			 $('#slideShowHome').animate({left:num });		
		
				$('a.slideShowNav').css('background-color','#111');
				$(this).css('background-color','#333');
		 });		
	});
	
	
	
	elements = $('img.subImage');
	elements.each( function() { 
		$(this).click( function(){ 
			
			$('#mainImage'+$(this).attr('data')).attr('src', $(this).attr('src') );	
		
		  } );
		  
		  
				
	});	
	
	setTimeout('homeTimer()',4200);	
	
	$('.homeFeatured').mouseover( function() {  holdShow = 1;  } );
	$('.homeFeatured').mouseout( function() {  holdShow = 0;  } );
			
  
});


function homeTimer()
{
	
	if(holdShow==1)
	{
		
		setTimeout('homeTimer()',3900);	
		return;
		
	}
	var cTime =  Math.round(new Date().getTime() / 1000);
	var lTime = hsTime;
	
	var diff = cTime - lTime;
	

	if(diff<10)
	{
		setTimeout('homeTimer()',3900);	
		return;
	}

	//alert(diff);
	
	var count = $('#slideShowHome').attr('data-count');
	var pos = parseFloat(hsPos);
		
	var nextPos = parseFloat(pos) + 1;
	if(nextPos > count)
		nextPos = 1;
		
	//alert(hsPos + ' ' + nextPos);
		
	hsPos = nextPos;	
	//alert(nextPos);
		
	
		
	var  num = '-' + ((nextPos-1) * 930) + 'px';
	$('#slideShowHome').animate({left:num });
	$('a.slideShowNav').css('background-color','#111');
	$('#hsLink-'+nextPos).css('background-color','#333');

	setTimeout('homeTimer()',4400);	
}

