var kvFreezeTimer=false;
var kvAmount=3;
var nowKV=Math.floor(Math.random()*kvAmount)+1;
var mouseIsOut=true;

function switchKV(w){
	if(kvFreezeTimer){
		clearTimeout(kvFreezeTimer);
	}
	nowKV=w;
	var left=(nowKV==1 || nowKV==3)? "0" : "-490px";
	var top=(nowKV==1 || nowKV==2)? "0" : "-316px";
	$("#homeKV").css({"background-position":left+" "+top, opacity:0}).animate({opacity:1}, {duration:"normal", queue:false, complete:function(){
		if(mouseIsOut){
			var nextKV=(nowKV==kvAmount)? 1 : (nowKV+1);
			kvFreezeTimer=setTimeout(function(){
				switchKV(nextKV);
			}, 3000);
		}
	}});
}

$(document).ready(function(){
	$("#header ul li.home a").addClass("now");
	switchKV(nowKV);
	$("#homeLogo li a").each(function(i){
		$(this).data("n", i+1);
		$(this).mouseover(function(){
			mouseIsOut=false;
			switchKV($(this).data("n"));
		}).mouseout(function(){
			mouseIsOut=true;
			var nextKV=(nowKV==kvAmount)? 1 : (nowKV+1);
			switchKV(nextKV);
		});
	});
});



