// Custom jQuery
// Author: Jonathan Marzullo

// JTM open browser window
function ofc_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// Start of Image Replacement on Image Path Error 
function ImgError(source){
	source.src = "graphics/00000001/no-image-path-error_tn.jpg";
	source.onerror = "";
	return true;
}

// Start of jump menu 
function ofc_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

// End of Image Replacement on Image Path Error

$(document).ready(function() {

// adds title attr to zomm image
$("#ZoomBox img#ZoomImage").attr('title','click me to close');
						   
// autocomplete ofc	 
   $("div#ofc_search #search").autocomplete("../includes/mysql.php", {
		width: 278,
        delay: 300,
		selectFirst: false
	});

   		
// side nav - show/hide menus

        /*$('#mini_cart').hide();*/
        /*$('#productsbox').hide();*/
          $('#mainbox').hide();
          $('#suninfobox').hide();

  $("a#products-toggle").toggle(
      function () {
        $("a#products-toggle img").attr({ src: "images/h3_arrow2.gif" });
		$('#productsbox').slideToggle('slow');
      },
      function () {
        $("a#products-toggle img").attr({ src: "images/h3_arrow.gif" });
		$('#productsbox').slideToggle('slow');
      }
    ); 
	
	
   	$("a#main-toggle").toggle(
      function () {
        $("a#main-toggle img").attr({ src: "images/h3_arrow2.gif" });
		$('#mainbox').slideToggle('slow');
      },
      function () {
        $("a#main-toggle img").attr({ src: "images/h3_arrow.gif" });
		$('#mainbox').slideToggle('slow');
      }
    ); 
		   
		   
	$("a#suninfo-toggle").toggle(
      function () {
        $("a#suninfo-toggle img").attr({ src: "images/h3_arrow2.gif" });
		$('#suninfobox').slideToggle('slow');
      },
      function () {
        $("a#suninfo-toggle img").attr({ src: "images/h3_arrow.gif" });
		$('#suninfobox').slideToggle('slow');
      }
    );
	

   	$("a#shoppanel-toggle").toggle(
      function () {
        $("a#shoppanel-toggle img").attr({ src: "images/h3_arrow.gif" });
		$('#mini_cart').slideToggle('slow');
      },
      function () {
        $("a#shoppanel-toggle img").attr({ src: "images/h3_arrow2.gif" });
		$('#mini_cart').slideToggle('slow');
      }
    ); 
	
// category description - show/hide
	$("a.show_product_info").toggle(
      function () {
        $("div.hidden_object").addClass("jonnybox").show("slow");
        $("a.show_product_info").text("Close Product Information");
      },
      function () {
        $("div.hidden_object").removeClass("jonnybox").hide("slow");
        $("a.show_product_info").text("Click Here For Product Information");	
      }
    ); 
	
// Tell Friend - show/hide
$("a.show_tell_friend").toggle(
      function () {
        $("a.show_tell_friend").text("Close");
        $("div.hidden_object_tf").addClass("jonnybox_tf").show("slow");	
      },
      function () {
         $("a.show_tell_friend").text("Tell a Friend");
        $("div.hidden_object_tf").removeClass("jonnybox_tf").hide("slow");	
      }
    );	

// tabs product pages

	$(".menu > li").click(function(e){
		switch(e.target.id){
			case "specs":
				//change status & style menu
				$("#specs").addClass("active");
				$("#description").removeClass("active");
				$("#relatedproducts").removeClass("active");
				//display selected division, hide others
				$("div.specs").fadeIn();
				$("div.description").css("display", "none");
				$("div.relatedproducts").css("display", "none");
			break;
			case "description":
				//change status & style menu
				$("#specs").removeClass("active");
				$("#description").addClass("active");
				$("#relatedproducts").removeClass("active");
				//display selected division, hide others
				$("div.description").fadeIn();
				$("div.specs").css("display", "none");
				$("div.relatedproducts").css("display", "none");
			break;
			case "relatedproducts":
				//change status & style menu
				$("#specs").removeClass("active");
				$("#description").removeClass("active");
				$("#relatedproducts").addClass("active");
				//display selected division, hide others
				$("div.relatedproducts").fadeIn();
				$("div.specs").css("display", "none");
				$("div.description").css("display", "none");
			break;
		}
		//alert(e.target.id);
		return false;
	});
		
// check all / uncheck all search page
	$('#checkAllAuto').click( function() {
      	$("input[type='checkbox']").attr('checked', $('#checkAllAuto').is(':checked'));   
   	})
	

// JTM targets for styling of volume pricing
	
	    $("#productForm div.volume_pricing_prod table:first").addClass("volume_pricing_table");
	    $("#productForm div.volume_pricing_prod table.volume_pricing_table table:first").addClass("volume_pricing_table_two");
        $("#productForm div.volume_pricing_prod table.volume_pricing_table").removeAttr("width").attr("width","90%").css("margin","0 auto");
		$("#productForm div.volume_pricing_prod table.volume_pricing_table table.volume_pricing_table_two tr:eq(0) th:first").css("background-color","#019348");
		$("#productForm div.volume_pricing_prod table.volume_pricing_table table.volume_pricing_table_two tr:eq(0) th font").removeAttr("size");
		$("#productForm div.volume_pricing_prod table.volume_pricing_table table.volume_pricing_table_two tr:eq(1) th").css({"background-color" : "#DDDDDD", "font-size" : "11px" });
			$("#productForm div.volume_pricing_prod table.volume_pricing_table table.volume_pricing_table_two tr:eq(1) th font").css("font-size","11px");
		$("#productForm div.volume_pricing_prod table.volume_pricing_table table.volume_pricing_table_two tr:eq(1) th").removeAttr("align").attr("align","center");
		$("#productForm div.volume_pricing_prod table.volume_pricing_table table.volume_pricing_table_two tr:eq(2)").css("background-color","#EDEDED");
		$("#productForm div.volume_pricing_prod table.volume_pricing_table table.volume_pricing_table_two tr:eq(2) td").removeAttr("align").attr("align","center").css("padding","5px 0px");
		$("#productForm div.volume_pricing_prod table.volume_pricing_table table.volume_pricing_table_two tr:eq(2) td font").removeAttr("size");
		
		$("#productForm div.volume_pricing_prod table.volume_pricing_table table.volume_pricing_table_two tr:eq(3) td").removeAttr("align").attr("align","center").css("padding","5px 0px");
		$("#productForm div.volume_pricing_prod table.volume_pricing_table table.volume_pricing_table_two tr:eq(3) td font").removeAttr("size");
		
		$("#productForm div.volume_pricing_prod table.volume_pricing_table table.volume_pricing_table_two tr:eq(4)").css("background-color","#EDEDED");
		$("#productForm div.volume_pricing_prod table.volume_pricing_table table.volume_pricing_table_two tr:eq(4) td").removeAttr("align").attr("align","center").css("padding","5px 0px");
		$("#productForm div.volume_pricing_prod table.volume_pricing_table table.volume_pricing_table_two tr:eq(4) td font").removeAttr("size");
		
// JTM - product attributes	target styles	
	
		$("#content_ofc div.product_attributes > table.prod_attr_table").attr({ width: "500" }).css({"margin" : "25px 15px 0px 0px", "padding" : "0px"});
        
		$("#content_ofc div.product_attributes > table.prod_attr_table tr td:nth-child(1)").attr({ 
          align: "right",
          valign: "top"
        }).css({"white-space" : "nowrap", "padding-right" : "5px" });
	
		$("#content_ofc div.product_attributes > table.prod_attr_table").before("<h3 class='prod_attr_heading'>Product Options</h3>");


	
});