$(document).ready(function(){

	$(".products_link").mouseover(function(){
		$(".sub_navigation").slideDown("slow");
		$(this).toggleClass("active");
	});	 
	
	$("#login_popup").fancybox({
		'padding'			: 0,
		'margin'			: 0,
		'overlayColor'      :'#000',
		'titlePosition'		: 'inside',
		'transitionIn'		: 'none',
		'transitionOut'		: 'none'
	});	
	
	totalfooters = $('.slider2_module').length;
	totalfooterwidth = (totalfooters*327)+10;
	$('.footer_longslider').css('width',totalfooterwidth+'px');
	currentfooter = totalfooters;
	if(totalfooters > 3)
	{
		currentfooter = 3;
	}
	
	totalhomebanners = $('.slider_module').length;
	totalhomebannerswidth = (totalhomebanners*476);
	$('.home_longslider').css('width',totalhomebannerswidth+'px');
	currenthomebanner = 1;
	
	fullScreenWidth = $('.slider').css('width');
	fullScreenWidth = fullScreenWidth.replace('px','');
	
	greyScaleHolder = ( 4000 - parseInt( fullScreenWidth ) );
	greyScaleHolder = ( greyScaleHolder-( greyScaleHolder /2 ) -12 );
	$('.greyholder').css('left','-'+ greyScaleHolder +'px');
	leftoff = 476*( totalhomebanners /2 );
	leftOffset = ( ( ( fullScreenWidth-453 ) /2 ) ); <!-- Comment; Credit BugFix: Stuart Dantzic -->
		
	$('.home_longslider').css('left',fullScreenWidth + 'px');
	$('.home_longslider').delay(800).animate({'left':leftOffset + 'px'}, 700,'easeInOutExpo',function(){
		
		$('.caption_'+currenthomebanner).fadeIn();
		
	});
	
	allowAutoSlider = 1;
	previoushomebanner = currenthomebanner;
	
	
});

var currentfooter, totalfooters, totalfooterwidth;
var currenthomebanner, totalhomebanners, totalhomebannerswidth, fullScreenWidth,greyScaleHolder,leftOffset,leftoff,allowAutoSlider,previoushomebanner,captionTextAlign;

function doTheSlide(theval)
{
	$('.caption_'+previoushomebanner).fadeOut(function(){
		
		previoushomebanner = currenthomebanner;
		
		$('.home_longslider').animate({'left':theval},700,'easeInOutExpo',function(){
			
			$('.caption_'+currenthomebanner).fadeIn();
			
		});
		
	});
}

function nextArrow()
{
	if(currenthomebanner < totalhomebanners)
	{
		allowAutoSlider = 0;
			doTheSlide('-=476px');
		currenthomebanner++;
	} return false;
}

function prevArrow()
{
	if(currenthomebanner > 1)
	{
		allowAutoSlider = 0;
			doTheSlide('+=476px');
		currenthomebanner--;
	} return false;
}

function nextFooterArrow()
{
	if(totalfooters > currentfooter)
	{
		$('.footer_longslider').animate({'left':'-=327px'},300);
		currentfooter++;
	} return false;
}

function prevFooterArrow()
{
	if(currentfooter > 3)
	{
		$('.footer_longslider').animate({'left':'+=327px'},300);
		currentfooter--;
	} return false;
}

function doAutoSlider()
{
	if(allowAutoSlider)
	{
		if(currenthomebanner < totalhomebanners)
		{
			doTheSlide('-=476px');
			currenthomebanner++;
		} else {
			doTheSlide(leftOffset+'px');
			currenthomebanner = 1;
		}
	}
}


