
var currentFeatTab = "boxFeaturesItem1";
var featTimerID;

/* Switch Features Box */
function switchFeatureTab(tabObj)
{
	$("#boxFeaturesButtons li").removeClass();	
	$(tabObj).addClass("selectedFeature");
	$(".boxFeat").not(":hidden").each(function(i,n){
		$(this).hide();		
		$('#'+$(tabObj).attr("rel")).fadeIn("fast");
	});
}

/* Rotating Features Timer */
function startFeatTimer(intv)
{
	featTimerID = setInterval(function(){
		var oldTabNumb = parseInt(currentFeatTab.substr(currentFeatTab.length-1,1));
		var newTabNumb;		
		(oldTabNumb == 3)?(newTabNumb = 1):(newTabNumb = (oldTabNumb + 1));
		currentFeatTab = currentFeatTab.substr(0,currentFeatTab.length-1) + "" + newTabNumb;
		switchFeatureTab($("#boxFeatures ul li[@rel="+currentFeatTab+"]"));	
	}, (!intv)?6000:intv);
}		


$(function() {
	/* Change Logo */
	$("#logo").attr("src", "/images/logo_b4p.png");

    loadPics();

	/* Featured Items Control */
	$(".boxFeat").hide();
	$("#boxFeaturesButtons li:eq(0)").addClass("selectedFeature");
	$(".boxFeat:eq(0)").show();
	startFeatTimer();
	

/* Old click handler
	$("#boxFeatures ul li").click(function(){
		clearInterval(featTimerID);
		
		currButton = this;
		currentFeatTab = $(this).attr("rel");
		
		switchFeatureTab(this);
	});
*/

	/* Features Box mouse events */
	$("#boxFeatures ul li").hover(
		function(){
			switchFeatureTab(this);
			currentFeatTab = $(this).attr("rel");
			clearInterval(featTimerID);
		},
		function(){
			clearInterval(featTimerID);
			startFeatTimer();
		}
	);
	
	/* Mouse over main images */
	$(".boxFeat").not("div.bidBox").hover(function(){
		clearInterval(featTimerID);
	},function(){
		startFeatTimer();
	});

	/* More Prizes Control */
	$(".morePrizesSelected").hide();
	$("#moreMenu li:eq(0)").addClass("moreSelected");
	$(".morePrizesSelected:eq(0)").show();
    $("#moreMenu ul li").click(function(){
		currButton = this;
		$("#moreMenu li").removeClass("moreSelected");
		$(currButton).addClass("moreSelected");
		$(".morePrizesSelected").not(":hidden").each(function(i,n){
			$(this).fadeOut("fast", function(){
				$('#'+$(currButton).attr("rel")).fadeIn("fast");
			});
		});
	});	
	
	/* How To Play Control */
	$("#howToPlayContainer").hide();
    $("#howToPlayButton").mouseover(function(){
	    currButton = this;
	    $("#howItWorksContainer").hide();
	    $("#howToPlayContainer").show();  	       
    });		       		
    
    
    $("#bodyTopRightCol").mouseout(function(){
	    currButton = this;
	    currButton = this;
	    $("#howToPlayContainer").hide();
	    $("#howItWorksContainer").show();  
    });		    
    
		
	
	/* Feature Click */
	/*
	$("#boxFeaturesItem1").not("div.bidBox").click(function(){document.location = $(this).attr("rel");}).css("cursor","pointer");
	$("#boxFeaturesItem2:not(#boxFeaturesItem2 .bidBox)").click(function(){document.location = $(this).attr("rel");}).css("cursor","pointer");
	$("#boxFeaturesItem3:not(#boxFeaturesItem3 .bidBox)").click(function(){document.location = $(this).attr("rel");}).css("cursor","pointer");
	*/
	
	/* Prizes Tabs */
	$("#endingSoon").tabs({
		fxFade: false,
		fxSpeed: 'fast',
		onClick: function(i, n) {
			
			/* $(n).attr("rel") *//* Set the selected tab */
			
			/* alert($(n).attr("rel")); */
		}
	});
	
	/* Auto Tab - Phone */
	$("#bodyTopRightColFields .txtCellBox1").autotab({ target: $("#bodyTopRightColFields .txtCellBox2"), format: "numeric" });
	$("#bodyTopRightColFields .txtCellBox2").autotab({ target: $("#bodyTopRightColFields .txtCellBox3"), format: "numeric", previous: $("#bodyTopRightColFields .txtCellBox1") });
	$("#bodyTopRightColFields .txtCellBox3").autotab({ format: "numeric", previous: $("#bodyTopRightColFields .txtCellBox2") });


	/* Bid Box */
	$("#ctl00_mainContentPlaceholder_boxFeaturesItem1 .txtBidAmount").autotab({format: "numeric"});
	$("#ctl00_mainContentPlaceholder_boxFeaturesItem3 .txtBidAmount").autotab({format: "numeric"});
	$("#endingSoonBidArea .txtBidAmount").autotab({format: "numeric"});
	
	/* Bid Hint */	
	$(".bidBox .tt").Tooltip({
		track: true,
		delay: 0,
		showURL: false,
		opacity: 1,
		fixPNG: true,
		showBody: " - ",
		extraClass: "fancysmall",
		top: -15,
		left: 5
	});
});