$(function(){

	$("<img>").attr('src','/sup/img/buttons/rotation_down.png');
    $("div#submit_buttons").hide();
    $("span#single_pricing").hide();

	$('a.lightbox').lightBox({fixedNavigation:true});
		
	$("span.add_more_products").click(function() {
		$(this).siblings("div.book_item:last").after($(this).siblings("div.book_item:last").clone(true).appendTo('body'));
	});
	
	$("ul#info_box_nav li").click(function() {
		$("ul#info_box_nav li.current").removeClass("current");
		$(this).addClass("current");
		$("div.info_box_content.block").removeClass("block");
		/*console.debug($(this).children().html().toLowerCase().split(' ')[0]);*/
		$("div#info_box_"+$(this).children().html().toLowerCase().split(' ')[0]).addClass("block");
	});
	/* swaps preview image based on the thumbnail clicked */
	/* 
	$("ul#preview_thumbnails img").click(function() {
		image_name = $(this).attr("src").toLowerCase().split("/")[4].split("_")[1].split(".")[0];

		$("div#large_preview a img").attr("src","/sup/img/textbooks/"+image_name+".jpg");
		$("div#large_preview a").attr("href","/sup/img/textbooks/hero_"+image_name+".jpg");
	});
	*/
	
	/*START FOR CAR_V3*/

	$("span#single_pricing").click(function(){

		if ($("td.book_i_price").css("color") == "rgb(255, 255, 255)" || $("td.book_i_price").css("color") == "#ffffff") {
			$(this).css('left', '-13px').children("img").attr('src','/sup/img/buttons/rotation_down.png');
			$("td.book_i_price").css("color",'#636363');
		} else {
			$(this).css('left', '-12px').children("img").attr('src','/sup/img/buttons/rotation_next.gif');
			$("td.book_i_price").css("color",'#ffffff');
		}
	});
	
	
	$("h2.book_collection").click(function(){
	    
		if ($("table#" + $(this).attr('id') + "_table").is(":visible")) {
		
			$(this).removeClass("open");
			$(this).children("span").html("View Pricing");
			$("table#" + $(this).attr('id') + "_table").hide();
			$("#lastOpenTable").val($("#lastOpenTable").val().replace("|||" + $(this).attr('id'),""));
 			// alert($("#lastOpenTable").val());
		
		} else {
		
			$(this).addClass("open");
			$(this).children("span").html("Qty");
			$("table#" + $(this).attr('id') + "_table").show();
			if ($("div#submit_buttons").is(":hidden")){
			    $("div#submit_buttons").show();
			    $("span#single_pricing").show();

			 }
            $("#lastOpenTable").val(($("#lastOpenTable").val() + "|||" + $(this).attr('id')));
            // alert($("#lastOpenTable").val());
		}
	});
	
	
	$("table.book_collection_table tr").hover(function(){
		var bg_color = $(this).css('background-color','#eeeeee').children("td.spacer").css('background-color','#ffffff').siblings('td.book_i_price').css('color');
		if(bg_color == "rgb(255, 255, 255)" || bg_color == "#ffffff"){
			$(this).children('td.book_i_price').css('color','#eeeeee');
		}
	},
	function(){
		var bg_color = $(this).css('background-color','#ffffff').children("td.spacer").css('background-color','#ffffff').siblings('td.book_i_price').css('color');
		if(bg_color == "rgb(238, 238, 238)" || bg_color == "#eeeeee"){
			$(this).children('td.book_i_price').css('color','#ffffff');
		}
	});	
	/*END OF CAR_V3*/
	
	var Prefixcounter = $("#Prefixcounter"); 
	//var totalproduct = $("#TotalProduct");
	
	//modified on 2/2/2010 to make Step-by-step Math Kit view pricing tag closed by default 
	var title = $("#title"); 
	var source = $("#source");
	if(Prefixcounter.val()<2)
	{
	   /* if (totalproduct.val() == 0)
	    {
	        alert(totalproduct.val());
	        $("div#orderform").show();
	    }*/
	    if (source.val() == 'SSemail20100203' && title.val()== 'stepmathkit')
	    {
	    }
	    else
	    {
	    $("div#orderform").show();
	    $("table#0_table").show();
	    $("div#submit_buttons").show();
	    $("span#single_pricing").show();
	    
	   $("h2.book_collection").addClass("open");
	   $("h2.book_collection").children("span").html("Qty");
       $("#lastOpenTable").val("0");
       /*alert(Prefixcounter.val());*/
       }
       
	}
	else
	{
	    if ($("#lastOpenTable").length!=0)
	    {
	      var pArray1 = $("#lastOpenTable").val().split("|||");
	          jQuery.each(pArray1, function() {
                if ($(this).length!=0)
                {
	                $("table#" + this + "_table").show();
	                $("div#submit_buttons").show();
                    $("span#single_pricing").show();
                    $("h2#" + this).addClass("open");
			        $("h2#" + this).children("span").html("Qty");

                }
              });

	    }
	   
	}
	
	
});
