//PRODUCT PAGE JAVASCRIPT

	function productTab(which) {
	    $(".products_content, .productsTab").hide();
	    $(which).show();
	}

	$(document).ready(function () {

	    createPacks();
	    $("#viva_testimonial_right").click(function () { nextTestimonial() });
	    $("#viva_testimonial_left").click(function () { prevTestimonial() });

	    $("#products_tab_packSizes").click(function () {
	        productTab('#products_packSizes, #packSizes');
	        $("#products_tab_packSizes").addClass("active");
	        $("#products_tab_Prints").removeClass("active");			
	    });

	    $("#products_tab_Prints").click(function () {
	        productTab('#products_Prints, #printsDesigns');
	        $("#products_tab_Prints").addClass("active");
	        $("#products_tab_packSizes").removeClass("active");
	        $("#products_tab_printsDesigns").addClass("active");
	        $("#products_tab_seasonal").removeClass("active");
	    });

	    $("#products_tab_printsDesigns").click(function () {
	        $('#printsSeasonal').hide();
	        $('#printsDesigns').show();
	        $("#products_tab_printsDesigns").addClass("active");
	        $("#products_tab_printsSeasonal").removeClass("active");
	    });

	    $("#products_tab_printsSeasonal").click(function () {
	        $('#printsDesigns').hide();
	        $('#printsSeasonal').show();
	        $("#products_tab_printsSeasonal").addClass("active");
	        $("#products_tab_printsDesigns").removeClass("active");
	    });

	    //if (($.browser.msie && $.browser.version != "7.0") || !$.browser.msie) {
	        $(".products_wtb").hover(function () { btn_wtb_mo() });
	        $(".products_wtb").mouseout(function () { btn_wtb_out() });
	    //}
	    $(".products_wtb").click(function () { btn_wtb_click() });

	});
	
	function btn_wtb_mo()
	{
		$(".products_wtb").animate({top: '0pc'}, 'fast');
	}
	function btn_wtb_out()
	{
		$(".products_wtb").animate({top: '-5px'}, 'fast');
    }
    function btn_wtb_click() {
        var thisPage = window.location.pathname;
        thisPage = thisPage.substring(thisPage.lastIndexOf('/') + 1);

        switch (thisPage) {
            case "choose-a-size.aspx":
                prodVar = "cas";
                break;
            case "designs.aspx":
                prodVar = "designs";
                break;
            case "white.aspx":
                prodVar = "white";
                break;
        }

        document.location = "/where-to-buy/default.aspx?productType=" + prodVar;
    }

    function viva_attr_click(which) {
       // document.getElementById(which + ".h").style.display = "block";
	    //Early versions of IE don't listen to to mouseover events set via attributes
        //document.getElementById(which).setAttribute("onmouseout", "viva_attr_hide('"+which+"')");
        document.getElementById(which).onmouseout = function () {
            var thisH = document.getElementById(which).getAttribute("rel");
            viva_attr_hide(thisH);
        };
	}
	function viva_attr_hide(which) {
	  //  document.getElementById(which + ".h").style.display = "none";
	    //Early versions of IE don't listen to to mouseover events set via attributes
	    //document.getElementById(which).setAttribute("onmouseout", "viva_attr_hide('"+which+"')");
	    document.getElementById(which).onmouseout = function () {
	        var thisH = document.getElementById(which).getAttribute("rel");
	        viva_attr_click(thisH);
	    };
	}

	function createPacks()
	{
		
		var contBox;
		var opt, hov;
				
		for (cnt1=0; cnt1 < viva_attr.length; cnt1++)
		{	
			pickID = viva_attr[cnt1][0];
			thisClass = viva_attr[cnt1][1];
			thisFolder= viva_attr[cnt1][2];
			contBox = document.getElementById(pickID);
		
			document.getElementById("products_tab_"+viva_attr[cnt1][0]).style.display = "block";

			for (cnt2=3; cnt2 < viva_attr[cnt1].length; cnt2++)
			{
			    thisType = viva_attr[cnt1][cnt2][0];
			    thisSize = viva_attr[cnt1][cnt2][1];
			    thisCount = viva_attr[cnt1][cnt2][2];

				thisID = "viva."+thisType+"."+thisSize+"."+thisCount;
				thisAlt = viva_attr[cnt1][cnt2][3];
				
				opt = document.createElement("a");
				opt.setAttribute("id", thisID);
				opt.className = thisClass+" obj"+cnt2;
				opt.style.backgroundImage = "url(/_images/products/productImages/"+thisFolder+thisID+".png)";
				//Early versions of IE don't listen to to mouseover events set via attributes
                //opt.setAttribute("onmouseover", "viva_attr_click('" + thisID + "')");

                opt.setAttribute("rel", thisID);
				
                opt.onmouseover = function () {
                    var thisH = this.getAttribute("rel");
				    viva_attr_click(thisH);
				};

                opt.href = "/where-to-buy/default.aspx?productType="+thisType+"&rollType="+thisSize+"&packSize="+thisCount;

					hov = document.createElement("div");
					//hov.setAttribute("id", thisID + ".h");
					//hov.style.backgroundImage = "url(/_images/products/productImages/"+thisFolder+thisID+".h.png)";
			    
				opt.appendChild(hov);

                contBox.appendChild(opt);
				
			}
		}
	}

	var testimonialTimer;

	function nextTestimonial()
	{
	    
        //get the next testimonial to show
		var viva_test = parseInt($("#viva_testimonial_id").html());
		if (viva_test < jsonTestimonials.length - 1)
		{
			viva_test++;
		}
		else
		{
			viva_test = 0;
		}
		
		$("#viva_testimonial_id").html(viva_test);
		doTestimonial(viva_test);	
	}

	function prevTestimonial()
	{
		//get the next testimonial to show
		var viva_test = parseInt($("#viva_testimonial_id").html());
		if (viva_test > 0)
			viva_test--;
		else
			viva_test = jsonTestimonials.length - 1;
		
		$("#viva_testimonial_id").html(viva_test);
		doTestimonial(viva_test);
	}

	function doTestimonial(id)
	{
		clearTimeout(testimonialTimer);
		testimonialTimer = 0;
		
		viva_test = id;
		
		var title = jsonTestimonials[viva_test].Title;
		var text = jsonTestimonials[viva_test].Message;
		var name = jsonTestimonials[viva_test].Name;
		var location = jsonTestimonials[viva_test].Location;

		$("#viva_testimonial h5, #viva_testimonial p, #viva_testimonial span").fadeTo('fast', .01, function () {
		    $("#viva_testimonial h5").html(title);

		    $("#viva_testimonial p").html(text);

            /*
		    //judge the heights
		    curH = $("#viva_testimonial p").height();
		    $("#viva_testimonial_body_cont").animate({height: curH+'px'});
            */

		    $("#viva_testimonial span").html(name + " of " + location);

		    $("#viva_testimonial h5, #viva_testimonial p, #viva_testimonial span").fadeTo('fast', 1);

		});
		
		//testimonialTimer = setTimeout('nextTestimonial()', 5000);
	}

	
	var viva_testimonial;


