
//WELCOMEMAT
var millisecBetweenAutoSlide = 5000;	// 1 second
var welcomematTimer;
var numOfImages;
var currentPos;

jQuery(document).ready(function($){
		
		
		
		//WELCOMEMAT
		welcomematTimer = 0;
		numOfImages = jQuery("#welcomemat").attr("numOfImages");
		currentPos = 0;
		
		hideButtons();
		welcomematAnimate();
		jQuery("#welcomemat-container").hover(function(){clearTimeout(welcomematTimer);showButtons();},function(){welcomematAnimate();hideButtons();}); //pause autosliding when mouseover, show buttons
		jQuery("#welcomemat-left").click(function(){WelcomematGoLeft();});
		jQuery("#welcomemat-right").click(function(){WelcomematGoRight();});
		jQuery("#welcomemat-left").hover(function(){jQuery(this).css('background-position','right')}, function(){jQuery(this).css('background-position','left')});
		jQuery("#welcomemat-right").hover(function(){jQuery(this).css('background-position','left')}, function(){jQuery(this).css('background-position','right')});




		//FOOTER CAROSEL
		jQuery('#mycarousel').jcarousel({ start: 1 });
			
			
			
		//TOP MENU DROPDOWNS
		jQuery("ul.menus li").hover(function () {
			jQuery(this).find("ul").show();
		}, function () {
			jQuery(this).find("ul").hide();
		});
		
		
		
});



			





//WELCOMEMAT
function welcomematAnimate()
{
		clearTimeout(welcomematTimer);
		welcomematTimer = setTimeout('WelcomematGoRandom()', millisecBetweenAutoSlide);
}
function WelcomematGoLeft()
{		
		currentPos--;if(currentPos<0)currentPos=numOfImages-1;
		jQuery("#welcomemat").animate( { marginLeft:'-'+(1000*currentPos)+'px'}, 800 );
}
function WelcomematGoRight()
{		
		currentPos++;if(currentPos>=numOfImages)currentPos=0;
		jQuery("#welcomemat").animate( { marginLeft:'-'+(1000*currentPos)+'px'}, 800 );
}
function WelcomematGoRandom()
{		
		jQuery("#welcomemat").animate( { marginLeft:getRandomPos()}, 800 );
		welcomematAnimate();
}
function getRandomPos()
{
		var randomn = getARandom(); while (randomn==currentPos){randomn = getARandom();}	//continually try to get a random that is not the current position
		currentPos = randomn;
		return '-'+(1000*randomn)+'px';
}
function getARandom(){return Math.floor(Math.random()*numOfImages);}
function showButtons()
{
		jQuery("#welcomemat-left").show();
		jQuery("#welcomemat-right").show();
}
function hideButtons()
{
		jQuery("#welcomemat-left").hide();
		jQuery("#welcomemat-right").hide();
}







