var ischrome =  /chrome/.test( navigator.userAgent.toLowerCase() );
var isBadBrowser = ($.browser.msie && $.browser.version.substr(0,1)<7)?true:false;
var isIE7 =  ($.browser.msie && $.browser.version.substr(0,1)<=7)?true:false;
var isIE8 =  ($.browser.msie && $.browser.version.substr(0,1)<=8)?true:false;
var deviceAgent = navigator.userAgent.toLowerCase();
var isIOS = deviceAgent.match(/(iphone|ipod|ipad)/);
var isHovering = [false,false];
var timerId = null;
var currentBtn = 0;
var oldBtn = 1;

function rolloverButton(btnId) {
	var	elem = $("#splashbutton"+btnId);
	
	var h1= elem.find("h1");
	var h2= elem.find("h2");
	var theMask = elem.find(".thumbimage .mask");
	h1.stop().animate({
		opacity: 0.0,
		left: '-300px'
	  }, 700, function() {
		
		
	  });
	h2.css({left:'100px', opacity:'0.0',display:'block'});
	h2.stop().delay(100).animate({
		opacity: 1.0,
		left: '0'
	  }, 700, function() {
		
		
	  });
	theMask.fadeOut();
	isHovering[btnId]=true;
}
function rolloutButton(btnId) {
	var	elem = $("#splashbutton"+btnId);
	var h1= elem.find("h1");
	var h2= elem.find("h2");
	var theMask = elem.find(".thumbimage .mask");
	theMask.show();
	h2.stop().animate({
		opacity: 0.0,
		left: '-200px'
	  }, 700, function() {
		// Animation complete.
		
	  });
	h1.css({left:'100px', opacity:'0.0',display:'block'});
	h1.stop().delay(100).animate({
		opacity: 1.0,
		left: '0'
	  }, 700, function() {
		// Animation complete.
	  });
	 isHovering[btnId]=false;
}

function loopMotion() {
	if (currentBtn>2) currentBtn = 0;
	if (oldBtn == 0 || oldBtn == 1) {
		if (isHovering[oldBtn])  {
			rolloutButton(oldBtn)
		}
	}
	if (currentBtn == 0 || currentBtn == 1) {		
		rolloverButton(currentBtn);
	}
	oldBtn = currentBtn;
	currentBtn++;
    timerId = setTimeout(loopMotion, 5000);	
}
$(document).ready(function() {
	 $("a.splashbutton").hover(
		 function(){
			clearTimeout(timerId);
			timerId = setTimeout(loopMotion, 15000);
			var btnId = $(this).attr("rel");
			rolloverButton(btnId);
		 },
		 function(){
			clearTimeout(timerId);
			timerId = setTimeout(loopMotion, 15000);
			var btnId = $(this).attr("rel");
			rolloutButton(btnId)
		 }
	);
	 
	timerId = setTimeout(loopMotion, 3000);
});
