QuickSale.HeaderAds = function(){
	var headerAds = [];
	var currentAdIdx = null;
	var that;
	var timer = null;
	
	return {
		init : function(){
			that = this;
			jQuery("#header_ad .ad").hide().each(function(i){
				headerAds.push( this );
			});
			currentAdIdx = Math.floor( Math.random() * headerAds.length );
			jQuery("#header_ad").hover(
				function(){
					clearTimeout(timer);
				},
				function(){
					timer = setTimeout(that.cycle, 5000);
				}
			);
			
			this.cycle();
		},
		
		cycle : function(){
			var prevAdIdx = currentAdIdx; 
			currentAdIdx++;
			if(currentAdIdx == null){
				currentAdIdx = Math.floor( Math.random() * headerAds.length );
			} else {
				if(currentAdIdx >= headerAds.length){
					currentAdIdx = 0;
				}
			}
			var currentAd = jQuery(headerAds[prevAdIdx]);
			/*
			currentAd.fadeOut("fast", function(){
				jQuery(headerAds[currentAdIdx]).fadeIn("fast");
			});
			*/
			currentAd.slideUp("fast");
			jQuery(headerAds[currentAdIdx]).slideDown("fast");
			
			timer = setTimeout(that.cycle, 10000);
		}
	}
}();
