/*
	This function is called, when program wgprodlist is ready
	It defines what to do when hovering over one image in the product list
	www.silverjeans.com
*/

//--------------------------------------------------------------------------------Mouse roll over of thumbnail images in wgprdolist
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//------------------------------------------------------------------------------------End of Mouse over function\

function prodlst(e)
{
	jQuery("body").append("<div id=\"imgpreload\" style=\"display:none\"></div>");
	// preload all M size images 
	jQuery(".prodimg").each(function() {
		var imgstr = jQuery(this).children("a").children("img").attr("zhvr");
		var imgstrhover = jQuery(this).children("a").children("img").attr("hoverstr");
		
		if (imgstr != "")
		{
			var img = new Image();
		
			jQuery(img).load(function() {
					jQuery(this).hide();
					jQuery("#imgpreload").append(this);
			}).attr("src", imgstr);
			
			/*jQuery.swapImage(".swapImage");
			jQuery.swapImage(".swapImageClick", true, true, "click");
			jQuery.swapImage(".swapImageDoubleClick", true, true, "dblclick");
			jQuery.swapImage(".swapImageSingleClick", true, false, "click");
			jQuery.swapImage(".swapImageDisjoint");*/
			

			// KAB 20100820 - changed to mouseover event on parent .prodimg div, instead of image, 
			//	so that Quickview link does not interfere with events
			/*
			jQuery(this).find(".prodimage").hover(
		      function () {
		        $(this).attr("src", imgstrhover);
		      }, 
		      function () {
		        $(this).attr("src", imgstr);
		      }
		    );
			*/
			
			/* KAB 20100820 - moved to prodimgcpl mouseover
			jQuery(this).mouseover(function ()
			{
				jQuery(this).find('.prodimage').attr('src', imgstrhover);

			}).mouseout(function ()
			{
				jQuery(this).find('.prodimage').attr('src', imgstr);
			});
			*/

		}
			
			
	});
	


	// KAB 20100809 - add hover behaviour for product listings
	jQuery('.prodimgcpl').mouseover(function ()
	{
		jQuery(this).find('.proddesc').addClass('highlighted');
		
		// KAB 20100820 - swap image to backside
		jQuery(this).find('.prodimage').attr('src', jQuery(this).find('a img').attr('hoverstr'));

		// KAB 20100820 - show Quickview link
		//jQuery(this).find('.quickview-link').css('cursor', 'pointer').show();
		// JDP 20100907 - changed to use CSS classes to hide/show
		jQuery(this).find('.quickview-link').css('cursor', 'pointer');
		jQuery(this).find('.quickview-link').removeClass('nondisp');


	}).mouseout(function ()
	{
		jQuery(this).find('.proddesc').removeClass('highlighted');

		// KAB 20100820 - reset original frontside image	
		jQuery(this).find('.prodimage').attr('src', jQuery(this).find(' a img').attr('zhvr'));

	
		// KAB 20100820 - hide Quickview link
		//jQuery(this).find('.quickview-link').css('cursor', 'auto').hide();
		// JDP 20100907 - changed to use CSS classes to hide/show
		jQuery(this).find('.quickview-link').css('cursor', 'auto');
		jQuery(this).find('.quickview-link').addClass('nondisp');

});

	// KAB 20100820 - add click event for Quickview link
	jQuery('.quickview-link').click(function ()
	{
		// DDP 20100902 - create the iframe
		//alert('test');
		
		jQuery("#quickview-container div.iframe-container").html("<iframe src=\"wgdetail.pgm?task=quickview&stsku="+jQuery(this).attr('sku')+"\" scrolling=\"no\" frameborder=\"0\"></iframe>");
		// load the Quicview iframe
		//jQuery('#quickview-container iframe').attr('src', 'wgdetail.pgm?task=quickview&stsku=' + jQuery(this).attr('sku'));

		// show the Quickview window
		jQuery('#quickview-container').show();

		return false;
	});


	// KAB 20100826 - add click event for Quickview CLOSE link
	jQuery('#quickview-container .close-link').click(function ()
	{
		// hide the Quickview window
		jQuery('#quickview-container').hide();

		return false;
	});



	/* LR  20091110 No longer used, due to new layout	
	//first function defines what happens, when hovering in the div, second function
	//defines what happens, when hovering out of the div

	jQuery(".prodimg").hover(function() {
		
		//take the image path from the small image and split it on every _
		//var imgstr = jQuery(this).children("a").children("img").attr("src");
		var imgstr = jQuery(this).children("a").children("img").attr("zhvr");
		
		//when there is a product image, show the larger image M1
		if (imgstr != "")
		{ 
			jQuery("#imgbig").addClass("loading");
			
			// until images is completely loaded, display "spinner.gif" (class loading)
			jQuery(function() {
		    	var img = new Image();
		    	jQuery(img)
		    		.load(function() {
		    			jQuery(this).hide();
		    			jQuery("#imgbig").html("");
		    			jQuery("#imgbig")
		    				.removeClass("loading")
		    				.append(this);
		    			jQuery(this).show();
		    		})
		    		.error(function() {
		    			//alert("something's wrong");
		    		})
		    		.attr("src", imgstr)
		    });
		    		
			//set the border of the div
			jQuery("#imgbig").css({"border":"1px solid #cccccc"});
			//to set the position of the image (it can't be displayed always in the top right corner of the page)
			var postop = jQuery(this).position().top - jQuery("div.prodimg:first").position().top;
			
			//if this is the last image in the product listing reduce the position from top by additional 120
			//get the index of the current parent div
			var thindex = jQuery("div.prodimgcpl").index(jQuery(this).parent());
			
			//display first 12 images at the top, then start positioning relative
			//12 images are displayed in paging, if view all, we need to position relative
			if (thindex >= 12)
			{
				
				//there are 4 images in one row, so loop through 4 times
				for(var i=0; i<4; i++)
				{
					//if the div with the next image has content (it exists) AND the top position is the same
					//as from the last div AND the top position is not the same as the position from the first div
					if (jQuery("div.prodimgcpl:gt("+(thindex + i)+")").html() == null &&
					jQuery(this).position().top == jQuery("div.prodimg:last").position().top &&
					jQuery(this).position().top != jQuery("div.prodimg:first").position().top)
					{
						// set i to 4 to stop loop
						i = 4;
						// set new position
						postop = postop - 160;
					}
				}
				//set the new position of the big preview image
				jQuery("#imgbig").css({"position":"relative", "top": postop + "px"});
			}
			else
			{
				jQuery("#imgbig").css({"position":"relative", "top": "0px"});
			}
		}
		
	}, function() {
		//when hovering out of the div, clear the div for the preview image
		jQuery("#imgbig").html("");
		//and remove the border of the div
		jQuery("#imgbig").css({"border":"0px"});
	});*/
}

/*
	This function is called, when program wgdetail is ready
	It adds the zoom effect to the product image, it adds scrolling to the three image sections
	when there are more then 3, 4 or 5 images and defines what happens when clicked on a color,
	size, inseam, add to cart or add to wishlist button
*/
function proddtl()
{

	// KAB 20100827 - add col1 and col2 divs around data for formatting and borders
	jQuery('#data-container').prepend('<div id="col2" />');	
	jQuery('#data-container').prepend('<div id="col1" />');	
	jQuery('#col1').prepend(jQuery('#main-description'));
	jQuery('#col2').prepend(jQuery('#size, #colour, #inseam, #availability, #quantity, #sizechart, #addtocart, #checkout-btn, #shopthisfit, #shopthiswash, #facebook, #emaillink, #addwlst'));
	
	// KAB 20100827 - group main product image and additional views together in a container div
	jQuery('#content-body').prepend('<div id="main-images" />');
	jQuery('#main-images').prepend(jQuery('#productimage, #additional-views, #wear-together'));

	if(jQuery('.hdl2').text() == "Recently viewed")
	{
		jQuery(this).attr("id", "rcviewed");
	}
	//add zoom option to main product image
	// DDP 20100830 - changed element id to #productimage - based on new structure
	/*
	if (jQuery("#productimage > img").attr("jqimg") != "" && typeof jQuery("#productimage > img").attr("jqimg") != "undefined")
	{
		jQuery("#productimage").jqueryzoom({xzoom: "203px", yzoom:"250px"});
	}*/
	$(".jqzoom").jqzoom();

	// KAB 20100828 - add "shop this link" click functionality
	jQuery('#shopthisfit a').click(function ()
	{
		document.location = 'wgprodlist.pgm?style=' + jQuery(this).attr('stylecode');
		return false;

	});


	// KAB 20100828 - add "shop this wash" click functionality



	
	//if there are more than 3 items in the first image scrolling div (additional product images)
	//add the option to scroll through those images
	//when scrolling through the images call function prevnextlink, that sets the previous and next 
	//link to visibility:hidden when at the beginning or at the end of the image list
	// KAB 20100829 - externalize number of items to var scrl1count
	var scrl1count = 2;
	if (jQuery("#scrlimg1 > .items > a").length > scrl1count) {
		jQuery("#scrlimg1").scrollable({size: scrl1count, 
			onSeek: function()  { 
				prevnextlink("scrlimg1", this.getStatus().index, scrl1count, this.getStatus().total);
			}   
		}); 
	}
	
	//if there are more than 4 items in the second image scrolling div (wear them together images)
	//add the option to scroll through those images
	// KAB 20100829 - externalize number of items to var scrl2count
	var scrl2count = 2;
	if (jQuery("#scrlimg2 > .items > a").length > scrl2count ) {
		jQuery("#scrlimg2").scrollable({size: scrl2count , 
			onSeek: function()  { 
				prevnextlink("scrlimg2", this.getStatus().index, scrl2count , this.getStatus().total);
			}   
		}); 
	}
	
	//if there are more than 5 items in the third image scrolling div (recently viewed images)
	//add the option to scroll through those images
	// KAB 20100829 - externalize number of items to var scrl3count
	var scrl3count = 3;
	if (jQuery("#scrlimg3 > .items > a").length > scrl3count ) {
		jQuery("#scrlimg3").scrollable({size: scrl3count , 
			onSeek: function()  { 
				prevnextlink("scrlimg3", this.getStatus().index, scrl3count , this.getStatus().total);
			}   
		});
	}
	
	if (jQuery("#scrlimg1 > div:first > .__scrollable > a:gt(" + (scrl2count -1) + ") > img").attr("src"))
	{
		jQuery("#scrlimg1 > .next").css("visibility", "visible");
	}
	
	if (jQuery("#scrlimg2 > div:first > .__scrollable > a:gt(" + (scrl2count -1) + ") > img").attr("src"))
	{
		jQuery("#scrlimg2 > .next").css("visibility", "visible");
	}
	
	if (jQuery("#scrlimg3 > div:first > .__scrollable > a:gt(" + (scrl3count -1) + ") > img").attr("src"))
	{
		jQuery("#scrlimg3 > .next").css("visibility", "visible");
	}
	
	
	//if the div id stslprc does have a class (it doesn't exist, when the saleprice is 0)
	//line-through the normal price of the product
	if (typeof jQuery("#stslprc").attr("class") != "undefined")
	{
		jQuery("#stmsprc").css("text-decoration", "line-through");
	}
	
	if (jQuery(".prodclr").length == 1)
	{
		//first remove the class sltcolor from every child-div
		jQuery(".prodclr > div").removeClass("sltcolor");
		
		//get the current background color
		var bgclr = jQuery(".prodclr:first").children("div").css("background-color");
		
		//add the class sltcolor to the selected color div
		jQuery(".prodclr:first").children("div").addClass("sltcolor");
		
		//get the color name of the selected color and writes it in a span next to the headline "Color:"
		jQuery("#prodclrnm").html(jQuery(".prodclr:first").children("div").attr("clr"));
		
		//populate the object with the selected color code
		sltwi["color"] = jQuery(".prodclr:first").children("div").attr("clrcod");
		
		//now check the availability of the item
		checkavail();
	}
	
	//add click function to list items for waist and inseam size selection
	//and populate an object with the name of the parent class and the value selected
	//this object is called again, when the availability is checked
	//the object is initialized in the program wgdetail as a global variable
	jQuery(".sltw > li > a, .slti > li > a").click(function () {
		//get the class name of the div surrounding the list items. 
		//it's either sltw (waist size) or slti (inseam size)
		var wstism = jQuery(this).parent().parent().attr("class");
		//populate the object
		sltwi[wstism] = jQuery(this).html();
		//first remove the class active from every link in the selected div
		jQuery("." + wstism + " > li > a").removeClass("active");
		//add the class active to the currently selected link
		jQuery(this).addClass("active");
		//now check the availability of the item
		checkavail();
        //SSR 20091201 - add return false to prevet the page from jumping
		return false;
	});
	
	//add the click function to the color selection div
	//it sets the new style (a smaller div with a border) and populates the same object as above with the
	//color selected and checks the availibility of the product selected
	jQuery(".prodclr").click(function () {
			//get the current background color
		var bgclr = jQuery(this).children("div").css("background-color"),
			stsku = jQuery("#stsku").val(),
			// JEL 20100826 - added seq to ensure correct #prdtimg is updated
			seq = jQuery(this).children("div").attr("seq");
		
		//first remove the class sltcolor from every child-div
		jQuery(".prodclr > div").removeClass("sltcolor");
		
		//add the class sltcolor to the selected color div
		jQuery(this).children("div").addClass("sltcolor");
		
		//get the color name of the selected color and writes it in a span next to the headline "Color:"
		jQuery("#prodclrnm").html(jQuery(this).children("div").attr("clr"));
		
		//populate the object with the selected color code
		sltwi["color"] = jQuery(this).children("div").attr("clrcod");
		
		jQuery.ajax({
			type: "GET",
			url: "wgdetail.pgm",
			cache: false,
			data: "task=getimg&clcolor=" + sltwi["color"] + "&stsku=" + stsku + "&seq=" + seq,
			success: function (response) {
/*			// JEL 20100826 - updated product-colour change to update the alternate images below the preview
				var imgsrcsplit = response.split("&&");
				jQuery("#prdtimg").attr("src", imgsrcsplit[0]);
				jQuery("#prdtimg").attr("jqimg", imgsrcsplit[1]);
*/
				// evaluate the response to script, it will be an array of objects
				response = eval(response);
				// the first object is the image being displayed as img#prdtimg
				var currentImg = response[0],
					length = response.length,
					seq,
					S,
					M = currentImg.M,
					L = currentImg.L;
				
				// set the attributes of the preview image
				jQuery("#prdtimg").attr("src", M);
				jQuery("#prdtimg").attr("jqimg", L);
				
				// update the alternate images by parsing the rest of the response array
				for (seq = 1; seq < length; seq += 1) {
					currentImg = response[seq];
					S = currentImg.S;
					M = currentImg.M;
					L = currentImg.L;
					
					// the individual alternate image thumbs are identified by their sequence number
					// use the position [seq] in the response array to match up the new images with the thumbnail
					jQuery("#scrlimg1 a[seq=" + seq + "]").attr("imgl", L);
					jQuery("#scrlimg1 a[seq=" + seq + "]").attr("imgm", M);
					jQuery("#scrlimg1 a[seq=" + seq + "] img").attr("src", S)
				}
				
			},
			error: function (XMLHttpRequest, textStatus, errorThrown) {
				var foo = XMLHttpRequest,
					bar = textStatus,
					baz = errorThrown;
			}
		});
		
		//now check the availability of the item
		checkavail();

		// KAB 20100829 - added, so the href of # does not execute and jump the user to the top of the page
		return false;

	});
	
	//add click function to the add to cart button
	//makes an ajax call to save the product selected in the transaction set
	jQuery("#addcart").click(function () {
        // JEL 20091215 - don't continue if input button is disabled
        if (jQuery(this).hasClass("disabled") === true) {
            jQuery("#qty").css({"color":"#ff0000", "font-weight":"bold"});
            return false;
        }
		//get the values of the selected product (sku, quantity, color, size and inseam)
		var sku = jQuery("#stsku").val();
		var qty = jQuery("#stqty").val();
		var color = sltwi["color"];
		if (sltwi["color"] == "999") {
			color = "";
		}
		var size = sltwi["sltw"];
		var inseam = sltwi["slti"];
		if (typeof sltwi["slti"] === "undefined") {
			inseam = "";
		}
		
		// make the ajax call using method get and passing the parameters
		// updates the number of items in the cart
		jQuery.get(
		"wgcart1.pgm",
		{
			task: "ajaxadditem",
			rnd: Math.floor(Math.random() * 10001),
			sku: sku,
			qty: qty,
			color: color,
			size: size,
			inseam: inseam
		},
		function (numitems) {

			// update shopping cart item count
			if (numitems != "N") {
				jQuery('#cartcount').html(numitems);
			}
			
			// populate with current cart contents
			jQuery.get(
				"WGCART1.pgm",
				{
					task: 'wrtminicart',
					rnd: Math.random()
				},
				function (returnhtml)
				{
					jQuery('#minicart').html(returnhtml);
			
				}
			);	
			
			jQuery('#minicart').fadeIn('slow');	
			
			// clear any existing timed events, and start the "hide cart" timed event
			window.clearTimeout(trackerID);
			trackerID = window.setTimeout('hideCart()',3000);
			
		});
	});
	
	//add click function to the add to wishlist button
	//makes an ajax call to save the product selected in the transaction set for the wishlist
	jQuery("#addwlst input").click(function () {

		// JEL 20091215 - don't continue if input button is disabled
        if (jQuery(this).hasClass("disabled") === true) {
            jQuery("#qty").css({"color":"#ff0000", "font-weight":"bold"});
            return false;
        }
		//get the values of the selected product (sku, quantity, color, size and inseam)
		jQuery("#wlsku").val(jQuery("#stsku").val());
		var color = sltwi["color"];
		if (sltwi["color"] == "999")
		{
			color = "";
		}
		jQuery("#wlcolor").val(color);
		jQuery("#wlsize").val(sltwi["sltw"]);
		jQuery("#wlinseam").val(sltwi["slti"]);
		jQuery("#wlform").submit();
	});
	
	// display form to send details to a friend
	// reset iframe source before displaying the div
	jQuery(".emlfrnd").click(function () {
		jQuery("#emailfriend > iframe").attr("src", "wgdetail.pgm?task=emlfrnd&STSKU=" + jQuery("#emailfriend").attr("stsku"));
		jQuery("#emailfriend").css("display", "block");
	});
	
	// when clicked on "Cancel" in "email to friend" form, clear all fields and hide the div
	jQuery("#emlcncl").click(function () {
		jQuery("#emlfrnd_form :text").val("");
		jQuery("#emlfrnd_txtarea").val("");
		parent.document.getElementById("emailfriend").style.display = "none";
	});
	
	// when clicked on "Submit" hide the div
	jQuery("#emlsbmt").click(function () {
		parent.document.getElementById("emailfriend").style.display = "none";
	});
	
	// preload all images sizes M and L
	jQuery("#scrlimg1 > div:first > .__scrollable > a").each(function () {
		var imgm = jQuery(this).attr("imgm");
		
		if (imgm != "")
		{
			var img = new Image();
		
			jQuery(img)
				.load(function () {
					jQuery(this).hide();
					jQuery("#imgpreload").append(this);
				})
				.attr("src", imgm);
		}
			
		var imgl = jQuery(this).attr("imgl");
		
		if (imgl != "")
		{
			var img = new Image();
		
			jQuery(img)
				.load(function () {
					jQuery(this).hide();
					jQuery("#imgpreload").append(this);
				})
				.attr("src", imgl);
		}
	});

}

/*
	this function is called when a size or color has been selected to check the availability of that item
	it uses an ajax call to the program and displays the result
*/
function checkavail() {

	if (jQuery("#stmsprc").html() != "Sold Out")
	{
		//get the sku of the product
		var stsku = jQuery("#stsku").val();
		//if the product is a pair of pants and a waist size is selected and an inseam size is selected and (there is no color
		//or if there is a color it has to be selected) then make the ajax call
		if (jQuery("#PRODCLS").val() == "pants" && typeof sltwi["sltw"] != "undefined" && typeof sltwi["slti"] != "undefined"
			&& (jQuery("#colorcnt").val() == "no" || typeof sltwi["color"] != "undefined"))
		{
			//if there is no color to select, set the value of color to 999
			if (jQuery("#colorcnt").val() == "no")
			{
				sltwi["color"] = "999";
			}
			//now call the program passing the parameters using the get method
			var getstr = "task=checkavail&stsku="+stsku+"&color="+sltwi["color"]+"&waist="+sltwi["sltw"];
			getstr+= "&inseam="+sltwi["slti"]+"&pants=pants";
			jQuery.ajax({
				type: "GET",
				url: "wgdetail.pgm",
				cache: false,
				data: getstr,
				success: function(response) {
					//call the function that populates the spans and divs according to the response of the call
					response_avail(response);
				}
			});
			
			//jQuery.get("wgdetail.pgm", {task: "checkavail", stsku: stsku, color: sltwi["color"], waist: sltwi["sltw"], inseam: sltwi["slti"], pants: "pants"}, function(response) {
			
			//	
			//});
		}
		
		//if the product is not a pair of pants and a size has been selected and (there is no color or a color 
		//has been selected) then make the ajax call and display the result
		if (jQuery("#PRODCLS").val() != "pants" && typeof sltwi["sltw"] != "undefined" 
			&& (jQuery("#colorcnt").val() == "no" || typeof sltwi["color"] != "undefined"))
		{
			
			//if there is no color to select, set the value of color to 999
			if (jQuery("#colorcnt").val() == "no")
			{
				sltwi["color"] = "999";
			}

			//now call the program passing the parameters using the get method
			var getstr = "task=checkavail&stsku="+stsku+"&color="+sltwi["color"]+"&waist="+sltwi["sltw"];
			getstr+= "&inseam=&pants=nopants";
			jQuery.ajax({
				type: "GET",
				url: "wgdetail.pgm",
				cache: false,
				data: getstr,
				success: function(response) {
					//call the function that populates the spans and divs according to the response of the call
					response_avail(response);
				}
			});
			
			
			//jQuery.get("wgdetail.pgm", {task: "checkavail", stsku: stsku, color: sltwi["color"], waist: sltwi["sltw"], inseam: "", pants: "nopants"}, function(response) {
			
			//	response_avail(response);
			//});
		}
	}
	else
	{
		//display the message the item is out of stock in both the availability div and the quantity selection div
		jQuery("#avail, #qty").html("Out of Stock");
		// JEL 20091215 - disable the buttons add to cart and add to wishlist with a class
		jQuery("#addwlst input, #addcart").addClass("disabled");
	}
}

/*
	this function populates the divs and spans and sets the disabled property of the buttons add to cart
	and add to wishlist according to the response of the ajax call
*/
function response_avail(response)
{

	//if the item is not out of stock, split the response string on the _ to get the max quantity and 
	//the text in stock and display these
	if (response != "N")
	{
		//split the response string on _
		var qty_instk = response;
		//populate a new variable with the select
		var select = "<select name=\"qty\" id=\"stqty\" size=\"1\">";
		//add option to the select until the max quantity is reached (1-12)
		for(var i=1; i<=(qty_instk-1+1);i++)
		{
			select+= "<option value=\"" + i + "\">" + i + "</option>";
		}
		//add the last closing select to the string
		select+= "</select>";
		//write the drop down box to the div 
		jQuery("#qty").html(select);
		//display the text in stock
		jQuery("#avail").css("display", "inline"); //DDP 20100830 span is hidden if nothing is selected
		jQuery("#avail").html("In Stock");
		// JEL 20091215 - changed to class
        // enable the buttons add to cart and add to wishlist (they are disabled by default)
		jQuery("#addwlst input, #addcart").removeClass("disabled");
	}
	else
	{
		//display the message the item is out of stock in both the availability div and the quantity selection div
		jQuery("#avail, #qty").html("Out of Stock");
		//disable the buttons add to cart and add to wishlist
		// JEL 20091215 - changed to class
		jQuery("#addwlst input, #addcart").addClass("disabled");
	}
}

/*
	this function changes the main product image when a different product image (from the list below) is selected
*/
function chgimg(aobj) {
	var imgm = jQuery(aobj).attr("imgm"),
		imgl = jQuery(aobj).attr("imgl"),
		// JEL 20100902 - added seq
		seq = jQuery(aobj).attr("seq");

	//set the new source of the image
	if (imgm != "") {
		jQuery("#prdtimg").attr("src", imgm);
	}
	
	//set the new big image source of the image for the zooming option
	if (imgl != "") {
		//jQuery("#prdtimg").attr("jqimg", imgl);
		// DDP 20100907 - HTML structure has changed "big image" is now located in href attribute
		// on wgdetail.pgm:
		jQuery("#productimage > a").attr("href", imgl);
		// for quickview:
		jQuery("#productimagequickview > a").attr("href", imgl);
	}
	
	// JEL 20100826 - update the selected sequence #
	jQuery(".prodclr div").attr("seq", seq);
}

/*
	this function is called when clicking on "OVERVIEW" or "SIZE & FIT" tab, to display selected content and hide the other
*/
function chgtab()
{
	//switch classes for divs tabcontent and tab
	//there are only two tabs, that allow the use of the function toggleClass
	jQuery(".tabcntt").toggleClass("hide");
	jQuery(".tab").toggleClass("tabactive");
}

/*
	when scrolling through the images, this functin is called to check if the last or first image is displayed
	to hide or display the previous or next link
*/
function prevnextlink(id, index, size, total)
{
	//the index is set by the scrolling function. it's always the number of the first image in the row.
	//at the beginning the index is 0, to check if the last image is displayed, add the size (number of images
	//in the div) to the index and compare that to the total number of images in the scrolling div
	
	//if we are at the beginning of the list
	if (index == 0)
	{
		//hide the previous link
		jQuery("#"+id).children(".prev").css("visibility", "hidden");
		//display the next link
		jQuery("#"+id).children(".next").css("visibility", "visible");
		// Note: can probably be removed, the scrolling option is only available when there are more images
		// Note: than displayable in a row. if the scrolling is at the beginning, the next link has to be displayed.
		/*
   		if ((index + size) == total)
   		{
   			jQuery("#"+id).children(".next").css("visibility", "hidden");
   		}*/
	}
	else
	{
		//if the index of the first visible image is not 0
		//display the previous link
		jQuery("#"+id).children(".prev").css("visibility", "visible");
		//hide the next link
		jQuery("#"+id).children(".next").css("visibility", "hidden");
		//is the current index + the visible number of images less then the total number of images, display
		//the next link. 
		//e.g. current index: 2 (the third image is at the beginning of the scrolling visible
		//e.g. size (number of images visible): 3
		//e.g. total number of images in the div:6 
		//the result of these numbers display the next link. 
		if ((index + size) < total)
		{
			jQuery("#"+id).children(".next").css("visibility", "visible");
		}
	}
}

/*
	function is called from wgwishlist program
*/
function wishlist() {
	// adds item to the cart, but checks before that for availability 
	jQuery(".additem").click(function () {
		var wdseq = jQuery(this).attr("seq");
		var whlistid = jQuery("#WHLISTID").val();
		
		var product = this;
		
		jQuery.ajax({
			type: "GET",
			url: "wgwishlist.pgm",
			cache: false,
			data: "task=getdtl&wdseq="+wdseq+"&whlistid="+whlistid,
			success: function(response) {
				if (response != "N")
				{
					var parms = response.split("=");
					
					//make the ajax call using method get and passing the parameters
					//updates the number of items in the cart
					jQuery.get(
					"wgcart1.pgm",
					{
						task: "ajaxadditem",
						rnd: Math.floor(Math.random()*10001),
						sku: parms[0],
						qty: "1",
						color: parms[1],
						size: parms[2],
						inseam: parms[3]
					},
					function(numitems) {
						// update shopping cart item count
						if (numitems != "N")
						$('#cartcount').html(numitems);
					}
					);
					
					jQuery(product).html("added to cart");
				}
				else
				{
					alert("Product is no longer available.");
				}
			}
		});
		
	});
	
	// changes private/public wishlist setting
	jQuery(".chgwhpriv").click(function () {
		var whpriv = jQuery(this).val();
		var whlistid = jQuery("#WHLISTID").val();
		
		jQuery.ajax({
			type: "GET",
			url: "wgwishlist.pgm",
			cache: false,
			data: "task=ajaxchgwhpriv&whpriv="+whpriv+"&whlistid="+whlistid,
			success: function(response) {
				jQuery("#whprivrpn").html(response);
			}
		});
	});
}