var activeProduct, newProduct, numproducts;

function resetSlidey() {
	if ($(".scroll").html() != null) {
		if ($(".scroll").scrollLeft() > 0) {
			$(".scroll").scrollLeft(0);
		}
	}
	if ($(".scroll .wrapper").html() != null) {
		if ($(".scroll .wrapper").scrollLeft() > 0) {
			$(".scroll .wrapper").scrollLeft(0);
		}
	}
}

/*--------------------------- Product Pop ----------------------------*/

function prodPop(defaultParam, thisProduct) {

	if(thisProduct){
	} else {
		thisProduct = $(this);
	}
		
	// id is in the form "productboxpop_[product]"
	newProduct = thisProduct.children(".container").attr("id").substring(5);

	// Only kick off billboard slidey if selecting a non-active product;
	if(newProduct == activeProduct)
		return true;
	
	var productboxpop, productcontent;
	
	numproducts = thisProduct.parent("div").hasClass("four") && 4 || thisProduct.parent("div").hasClass("three") && 3 || 	thisProduct.parent("div").hasClass("two") && 2 || 5;

	if ($("#sign_in_box .hdr_open").css("display") == "none") {
		$("#sign_in_box .hdr_close").click();
	}
	
	// Reset active productboxpop display and functionality
	if(activeProduct) {
		productboxpop = $("#prod_" + activeProduct).parent("div");
		
		productboxpop.removeClass("prodActive");
		productboxpop.find(".recommendedFor").css("margin-top","0px");
		productboxpop.find(".fs-smaller").addClass("fs-smallest").removeClass("fs-smaller");
		productboxpop.find(".fs-small").addClass("fs-smaller").removeClass("fs-small");
		productboxpop.find(".fs-normal").addClass("fs-small").removeClass("fs-normal");
		productboxpop.find(".fs-larger").addClass("fs-large").removeClass("fs-larger");
		productboxpop.find(".fs-largest").addClass("fs-larger").removeClass("fs-largest");
		productboxpop.find(".lh-normal").addClass("lh-small").removeClass("lh-normal");
		productboxpop.find(".lh-large").addClass("lh-normal").removeClass("lh-large");
		productboxpop.find(".productFeatures").removeClass("ie6_margin");
	}
	
	productboxpop = thisProduct;	
	prodActivate(productboxpop, newProduct);
	
}

function prodUnPop() {
	
}

function prodActivate(productboxpopId, newProduct) {

	productboxpop = $(productboxpopId);
	activeProduct = newProduct;

	productboxpop.addClass("prodActive");	
	
	$(".billboard").slideTo("#bb_" + newProduct);	
	
	numproducts = productboxpop.parent("div").hasClass("four") && 4 || productboxpop.parent("div").hasClass("three") && 3 || 	productboxpop.parent("div").hasClass("two") && 2 || 5;

	productboxpop.find(".recommendedFor").css("margin-top","12px");
	productboxpop.find(".lh-normal").addClass("lh-large").removeClass("lh-normal");	
	productboxpop.find(".lh-small").addClass("lh-normal").removeClass("lh-small");
	productboxpop.find(".fs-larger").addClass("fs-largest").removeClass("fs-larger");
	productboxpop.find(".fs-large").addClass("fs-larger").removeClass("fs-large");
	productboxpop.find(".fs-small").addClass("fs-normal").removeClass("fs-small");	
	productboxpop.find(".fs-smaller").addClass("fs-small").removeClass("fs-smaller");
	productboxpop.find(".fs-smallest").addClass("fs-smaller").removeClass("fs-smallest");
	productboxpop.find(".productFeatures").addClass("ie6_margin");

	return true;
}

/*-------------------------- Image Preload -----------------------------*/

jQuery.preloadImages = function() {
	var prefix = "";
	//only use akamai for http
	if(location.protocol == 'http:')
		prefix = "http://images.turbotax.intuit.com";
	
	for(var i = 0; i<arguments.length; i++)	{
		jQuery("<img>").attr("src", prefix + arguments[i]);
	}
}



/*-------------------------- Slidey ----------------------------*/

jQuery.fn.slideTo = function(target_id, settings) {
	settings = jQuery.extend({
     easeTime: 400
  }, settings);
	var container = jQuery(this);
	$.each( container.find(".section"), function(i, n){
		$(n).attr("rel",i);
	});
	var width = container.width();
	var z = $(target_id).attr("rel");
	var cnt = - (width*z);
	if (isNaN(cnt)) cnt = 0;

	container.find(".itab_content").animate({left:cnt}, {
		duration: 600,
		easing: "easeInOutQuint",
		complete: function() {
			var left = $(this).css("left");
			var distance = left.split("px");
			if (distance[0] > -500) $(this).css("left",0);
		}
	});		
}

