$(function(){
	$('.sub-menu').hide().parent('li').hover(function(){
		$(this).children('.sub-menu').show();													 
	},
	function(){
		$(this).children('.sub-menu').hide();		
	});	
		
	var timerSetting = [];
	var i = 0;
	
	timerSetting[i] = 8;
	timerSetting[++i] = 6;
	timerSetting[++i] = 6;
	timerSetting[++i] = 6;
	
	function rotateBanner(){
		var iDex = $('.rotatebanner:visible').index('.rotatebanner');
		if(focused){				
			$('.rotatebanner').eq(iDex).css('z-index',3).hide("slide", { direction: "left" }, 500);
			$('#homebannercounter').children('img').eq(iDex).attr('src', 'img/hdr/gray-dot.png');
			iDex++;
			if(iDex >= $('.rotatebanner').length){ iDex = 0; }
			$('.rotatebanner').eq(iDex).css('z-index',2).show("slide", { direction: "right" }, 500);
			$('#homebannercounter').children('img').eq(iDex).attr('src', 'img/hdr/yellow-dot.png');
		}
		var delay = timerSetting[iDex] * 1000;
		setTimeout(rotateBanner, delay);		
	}
	setTimeout(rotateBanner, timerSetting[0]*1000);	
	
	var focused = true;
	window.onblur = function(){ focused = false; };
	window.onfocus = function(){ focused = true; };
	$('.rotatebanner').hover(function(){
		focused = false;								  
	}, function(){
		focused = true;
	});

	$('#homebannercounter').children('img').click(function(){
		var icon = $(this);
		icon.siblings().each(function(){
			var offSrc = $(this).attr('src').replace('yellow','gray');
			$(this).attr('src', offSrc);							  
		});
		var iDex = icon.index();
		var src = icon.attr('src').replace('gray', 'yellow');
		icon.attr('src',src);
		$('.rotatebanner:visible').css('z-index',3).hide("slide", { direction: "left" }, 500);
		$('.rotatebanner').eq(iDex).css('z-index',2).show("slide", { direction: "right" }, 500);
	}).hover(function(){ $(this).css('cursor', 'pointer'); });
	
});

