// JavaScript Document

$(document).ready(function(){
	var currentProtocol = (("https:" == document.location.protocol) ? "https:" : "http:");
	/* 2010-02-19
	* sometimes this pagetracker causes an error in IE, probably IE6 but unsure
	* error is "pagetracker is null or not an object"
	* so use a try/catch just in case */
	try { _gaq.push(['_trackEvent', 'Products', 'Product Viewed', prodID ]); } catch (error) {}
	

	// test item 5364
	
	// flash 360 images
	if ( $("#flash360").length ) {
		// there is an enlarged image available
		$("#flash360").click(function(event){
			event.preventDefault();
			var theFlash360 = $(this).attr("href");
			//alert(currentProtocol + theFlash360);
			$("#largeImageContent").load(theFlash360);
			jqSlideLayer( "largeImage", "slow", 0 );
			try { _gaq.push(['_trackEvent', 'Products', '360 Flash Viewed', prodID ]); } catch (error) {}
		});
	}
	
	if ( $(".reviewImage").length || $("#custImages").length ) {
		// someone has submitted a review with an image
		// use .live instead of .click to make sure the action is attached to
		// new elements as well
		$(".reviewImage").live( "click", function(event){
			event.preventDefault();
			try { _gaq.push(['_trackEvent', 'Products', 'Review Image Viewed', prodID ]); } catch (error) {}
			//if ( $("#reviewImages").dialog( "option", "height" ) ) {
			if ( dialogCreated( $("#reviewImages") ) ) {
				$("#reviewImages").dialog( "destroy" );
			}
			$("#reviewImages").dialog({
				bgiframe: true,
				height: 500,
				width: 600,
				modal: true
			}).load( $(this).attr("href") );
			return false;
		});
	} // if ( $(".reviewImage").length ) {
	
	if ( $("#viewAllReviews").length ) {
		$("#viewAllReviews").click(function(event){
			event.preventDefault();
			try { _gaq.push(['_trackEvent', 'Products', 'All Reviews Viewed', prodID ]); } catch (error) {}
			//if ( !$("#allReviewsDialog").dialog( "option", "height" ) ) {
			if ( !dialogCreated( $("#allReviewsDialog") ) ) {
				$("#allReviewsDialog").dialog({
					bgiframe: true,
					height: 545,
					width: 675,
					modal: true
				}).html("<p style=\"text-align: center;\"><img src=\"/images/misc/loadingAnimation.gif\"></p>").load( $(this).attr("href"), function(){
					$(document).ready(function(){
						$("head").append("<link rel=\"stylesheet\" href=\"/jquery/css/datatables/demos.css\" type=\"text/css\" />");
						$("#allReviewsTable").dataTable({
							"bPaginate": false,
							"bFilter": false,
							"aaSorting": [[1,'desc']],
							"aoColumns": [
								null,
								{ "iDataSort": 2 },
								{ "bVisible": false },
								{ "bSortable": false }
							]
						});
						if ( testSetAttributeIgnoresNameAttribute() ) {
							// IE <= 7 looks like garbage, so we need to apply the fixes below
							//$("body").append("<br>this is IE7 or less");
							$("#allReviewsTable_wrapper").css( "height", "95%" );
							$("#allReviewsTable_wrapper").css( "overflow", "scroll" );
							$("#allReviewsDialog").css( "overflow", "hidden" );
						}
					});
				});
			} else {
				$("#allReviewsDialog").dialog( "open" );
			}
			return false;
		});
	} //if ( $("#viewAllReviews").length ) {
	
	// additional images
	if ( $(".thickbox").length ) {
		// there are extra images available
		$("head").append("<link rel=\"stylesheet\" href=\"/includes/thickbox.css\" type=\"text/css\" />");
		$.getScript( "/jquery/thickbox.unpacked.js" );
		/*$(".extraImages").click(function(event){
			event.preventDefault();
			var theExtraImage = "http://www.favorfavorbaby.com/pscripts/extraImage.php?image=";
			theExtraImage += currentProtocol;
			theExtraImage += "//www.favorfavorbaby.com";
			theExtraImage += $(this).attr("href");
			var theExtraImages = $(".extraImages").attr("href");
			alert(theExtraImages);
			$("#largeImageContent").load( theExtraImage );
			jqSlideLayer( "largeImage", "medium", 0 );
			try { _gaq.push(['_trackEvent', 'Products', 'Extra Image Viewed', prodID ]); } catch (error) {}
		});*/
	}
	
	//transit time
	if ( $("#transitTimeShow").length ) {
		// there is a transit time calculator available
		$("#transitTimeShow").click(function(event){
			event.preventDefault();
			jqSlideLayer( "transitTimePop", "fast", 0 );
		});
		
		$("#transitTimePopClose").click(function(event){
			jqSlideLayer( "transitTimePop", "fast", 0 );
		});
		
		$("#from").keypress(function(event){
			if ( ( event.which && event.which == 13 ) || ( event.keyCode && event.keyCode == 13 ) ) {
				// they hit enter, which won't trigger a click in IE for some reason
				document.getElementById("transitTimeButton").click();
				event.preventDefault();
				return false;
			} else {
				return true;
			}
		});
		
		$("#transitTimeButton").click(function(event){
			event.preventDefault();
			jqToggleLayer( "transitTimeLoading", "fast", 0 );
			//try { _gaq.push(['_trackEvent', 'Products', 'Transit Time Calculator Used', prodID ]); } catch (error) {}
			var theShipZip = $("#to").val();
			//get manufacturer and availability from href query string
			var theIncURL = $("#transitTimeShow").attr("href");
			var theAvailability = $.getQueryString({id:"availability",theURL: theIncURL});
			var manufacturer = $.getQueryString({id:"from",theURL: theIncURL});
			var pTags = document.getElementById("tags").checked;
			// now use manufacturer to determine the from zip
			switch ( manufacturer ) {
			case "Designing Ducks":
				var theFromZip = "19484";
				break;
			case "Designing%20Ducks":
				var theFromZip = "19484";
				break;
			case "Fashioncraft":
				var theFromZip = "11791";
				break;
			case "JBS":
				var theFromZip = "55340";
				break;
			case "JDS":
				var theFromZip = "55340";
				break;
			case "Chandler Candle":
				var theFromZip = "95623";
				break;
			case "Chandler%20Candle":
				var theFromZip = "95623";
				break;
			case "Elsies Daughter":
				var theFromZip = "05462";
				break;
			case "Elsies%20Daughter":
				var theFromZip = "05462";
				break;
			case "Event Blossom":
				var theFromZip = "92780";
				break;
			case "Event%20Blossom":
				var theFromZip = "92780";
				break;
			case "Impressions by Brianna":
				var theFromZip = "13760";
				break;
			case "Impressions%20by%20Brianna":
				var theFromZip = "13760";
				break;
			case "Kate Aspen":
				var theFromZip = "30097";
				break;
			case "Kate%20Aspen":
				var theFromZip = "30097";
				break;
			case "Levie":
				var theFromZip = "10001";
				break;
			case "Pixior":
				var theFromZip = "92780";
				break;
			case "The Mint Box":
				var theFromZip = "21784";
				break;
			case "The%20Mint%20Box":
				var theFromZip = "21784";
				break;
			case "The Wedding Pen Company":
				var theFromZip = "37064";
				break;
			case "The%20Wedding%20Pen%20Company":
				var theFromZip = "37064";
				break;
			case "Wedding Ship":
				var theFromZip = "92780";
				break;
			case "Wedding%20Ship":
				var theFromZip = "92780";
				break;
			default:
				var theFromZip = "11791";
			}
			var thePostURL = currentProtocol + "/pscripts/UPS/timeInTransit.php";
			$.post( thePostURL, {
				   to: theShipZip,
				   from: theFromZip,
				   availability: theAvailability,
				   tags: pTags,
				   jQSubmit: "1"
				   },
				   function(returnData){
						$("#transitTimeResults").html( returnData );
						jqToggleLayer( "transitTimeLoading", "fast", 0 );
				   });
			/*theURL += "?Screen=CALCSHIPPING&Store_Code=FFB&calcship=1&ShipZip=" + theShipZip + "&shipcountry=" + theShipCountry;
			$.post( theURL, {
				   nothing: "nothing"
				   },
				   function(returnData){
					   $("#calcShipResults").html( returnData );
				   });*/
			//jqSlideLayer ( "transitTimePop", "medium", 0 );
		});
		
		
	} // if ( $("#transitTimeShow").length ) {
		
	//ups maps
	if ( $("#mapShow").length ) {
		// there should always be a map, but you never know
		$("#mapShow").click(function(event){
			event.preventDefault();
			try { _gaq.push(['_trackEvent', 'Products', 'UPS Map Viewed', prodID ]); } catch (error) {}
			if ( $("#upsMapPopup").length ) {
				$("#upsMapPopup").dialog( "open" );
			} else {
				$("body").append("<div id=\"upsMapPopup\" title=\"UPS Transit Map\"></div>");
				$("#upsMapPopup").dialog({
					bgiframe: true,
					height: 500,
					width: 600,
					modal: true
				}).load( $(this).attr("href") );
			}
			return false;
		});
	}
	
	//wish list
	if ( $("#wishListButton").length ) {
		// it should also always be there
		$("#wishListButton").click(function(event){
			event.preventDefault();
			$("#wishListDescription").load( "/includes/ajax/whatIsThisProd2.php", function(){
				$(document).ready(function(){
					//if ( !$("#wishListDescription").dialog( "option", "height" ) ) {
					if ( !dialogCreated( $("#wishListDescription") ) ) {
						$("#wishListDescription").dialog({
							bgiframe: true,
							height: 250,
							width: 350,
							modal: true
						});
					} else {
						$("#wishListDescription").dialog( "open" );
					}
				});
			});
			return false;
		});
	}
		
	//glass date format
	if ( $("#glassDateButton").length ) {
		// it should also always be there
		$("#glassDateButton").mouseover(function(event){
			jqToggleLayer( "glassDatePop", null, 0 );
		});
		$("#glassDateButton").mouseout(function(event){
			jqToggleLayer( "glassDatePop", null, 0 );
		});
	}
	
	// personalization designs 
	if ( $("#showDesigns").length ) {
		$("#showDesigns").click(function(event){
			jqToggleLayer( 'coffee-favors', null, 1 );
			//jqSlideLayer( "coffee-favors", "slow", 1 );
			
			/*** personalized tags by FC ***/
			/* do not load on fly (non-ajax) method */
			if ( $(".popLink").length ) {
				// bind the links in coffee-favors with their behaviors below
				$(".popLink").click( function(event) {
					event.preventDefault();
					var theURL = $(this).attr("href");
					$("#personalitypopimage").load(theURL);
					//jqSlideLayer( 'personalitypop', 'slow', 0 );
					jqToggleLayer( 'personalitypop', null, 0, "show" );
				});
			}
			/* end do not load on fly (non-ajax) method */

			/****** LOAD ON THE FLY USING .LOAD ********/
			/*
			if ( $(".popLink").length == 0 ) { // only load it the first time (popLink will be > 0 after first load )
				$("#coffee-favors").load("//www.favorfavor.com/includes/attributes/FC/personalized-tags/allTags.php", function() {
					// rebind the links
					$(".popLink").click( function(event) {
						event.preventDefault();
						var theURL = event.target.href; // text within <a>
						if ( !theURL ) {
							theURL = event.target.parentNode.href; // <img> within <a>
						}
						$("#personalitypopimage").load(theURL);
						//jqSlideLayer( 'personalitypop', 'slow', 0 );
						jqToggleLayer( 'personalitypop', null, 0 );
					});
																															   
				});
			}
			jqSlideLayer( "coffee-favors", "slow", 1 );
			*/
			/****** END LOAD ON THE FLY USING .LOAD ********/
			
			
			/********* LOAD ON THE FLY USING .AJAX *********/
			// below is another way to do it using .ajax. this doesn't do the slide till the data is loaded
			/*
			if ( $(".popLink").length == 0 ) { // only load it the first time (popLink will be > 0 after first load )
				$.ajax({
					type: "GET",
					url: "//www.favorfavor.com/includes/attributes/FC/personalized-tags/allTags.php",
					success: function(data){
						$("#coffee-favors").html(data);
						jqSlideLayer( "coffee-favors", "slow", 1 );
						//jqToggleLayer( "coffee-favors", null, 0 );
						// rebind the links
						$(".popLink").click( function(event) {
							event.preventDefault();
							var theURL = event.target.href; // text within <a>
							if ( !theURL ) {
								theURL = event.target.parentNode.href; // <img> within <a>
							}
							$("#personalitypopimage").load(theURL);
							//jqSlideLayer( 'personalitypop', 'slow', 0 );
							jqToggleLayer( 'personalitypop', null, 0 );
						});
					}
				});
			} else {
				jqSlideLayer( "coffee-favors", "slow", 1 );
				//jqToggleLayer( "coffee-favors", null, 0 );
			}
			*/
			/********* LOAD ON THE FLY USING .AJAX *********/
		});
	}

	// personalization designs JQUI
	if ( $("#showDesignsJQUI").length || $(".showDesignsJQUI").length ) {
		$("#showDesignsJQUI,.showDesignsJQUI").click(function(event) {
			event.preventDefault();
			//if ( !$("#JQUIDialog").dialog( "option", "height" ) ) {
			if ( !dialogCreated( $("#JQUIDialog") ) ) {
				//var HW = getHW( $(this).attr("href") );
				var dialogWidth = $("#JQUIDialog").css("width") != "auto" && $("#JQUIDialog").css("width") != "" ? $("#JQUIDialog").css("width").replace( "px", "" ) : "620";
				var dialogHeight = $("#JQUIDialog").css("height") != "auto" && $("#JQUIDialog").css("height") != "" ? $("#JQUIDialog").css("height").replace( "px", "" ) : "500";
				$("#JQUIDialog").dialog({
					bgiframe: true,
					width: parseInt(dialogWidth),
					height: parseInt(dialogHeight),
					modal: true
				});
				if ( $("#JQUIDialog.personalizedTags").length ) {
					$("#JQUIDialog").load("/fashioncraft-jars/tags-showDesigns.htm");
				}
			} else {
				$("#JQUIDialog").dialog( "open" );
			}
			return false;
		});
	} // if ( $("#showDesignsJQUI").length ) {
	
	// personalization designs JQUI
	if ( $("#showDesignsJQUI2").length || $(".showDesignsJQUI2").length ) {
		$("#showDesignsJQUI2,.showDesignsJQUI2").click(function(event) {
			event.preventDefault();
			//if ( !$("#JQUIDialog2").dialog( "option", "height" ) ) {
			if ( !dialogCreated( $("#JQUIDialog2") ) ) {
				//var HW = getHW( $(this).attr("href") );
				$("#JQUIDialog2").dialog({
					bgiframe: true,
					width: 600,
					height: 500,
					modal: true
				});
			} else {
				$("#JQUIDialog2").dialog( "open" );
			}
			return false;
		});
	} // if ( $("#showDesignsJQUI2").length || $(".showDesignsJQUI2").length ) {


	// similar to above but for the mint-tin div
	if ( $("#showDesignsMint").length ) {
		$("#showDesignsMint").click(function(event){
			jqToggleLayer( 'mint-tin-favors', null, 1 );
		});
	}
	//popup designs/tags/etc -- close window buttons
	if ( $("#closeWindowTop").length ) {
		$("#closeWindowTop").click(function(event){
			jqToggleLayer('coffee-favors', null, 1);
		});
		$("#closeWindowBottom").click(function(event){
			jqToggleLayer('coffee-favors', null, 1);
		});
	}
	if ( $("#openWindowDescrip").length ) {
		$("#openWindowDescrip").click(function(event){
			jqToggleLayer('coffee-favors', null, 1);
		});
	}
	
	//similar to above but for the mint-tin div
	if ( $("#closeWindowTopMint").length ) {
		$("#closeWindowTopMint").click(function(event){
			jqToggleLayer('mint-tin-favors', null, 1);
		});
		$("#closeWindowBottomMint").click(function(event){
			jqToggleLayer('mint-tin-favors', null, 1);
		});
	}
	if ( $("#openWindowDescripMint").length ) {
		$("#openWindowDescripMint").click(function(event){
			jqToggleLayer('mint-tin-favors', null, 1);
		});
	}
	
	if ( $("#coffeeRedBag").length ) {
		// these are coffee favors with bag colors
		$("#coffeeRedBag").click(function(event){
			jqSetSelection ( "bag", "8320", "bag", null );
		});
		$("#coffeeSilverBag").click(function(event){
			jqSetSelection ( "bag", "8290", "bag", null );
		});
		$("#coffeeWhiteBag").click(function(event){
			jqSetSelection ( "bag", "8310", "bag", null );
		});
		
		$("#coffeeRedBag").hover(
			function () {
				$("#coffeeRedBag").css({ 'cursor' : 'pointer' });
			}, 
			function () {
				$("#coffeeRedBag").css({ 'cursor' : 'default' });
			}
		);
		$("#coffeeSilverBag").hover(
			function () {
				$("#coffeeSilverBag").css({ 'cursor' : 'pointer' });
			}, 
			function () {
				$("#coffeeSilverBag").css({ 'cursor' : 'default' });
			}
		);
		$("#coffeeWhiteBag").hover(
			function () {
				$("#coffeeWhiteBag").css({ 'cursor' : 'pointer' });
			}, 
			function () {
				$("#coffeeWhiteBag").css({ 'cursor' : 'default' });
			}
		);
	}
		
	// reviews #6 - #20
	if ( $("#showMoreReviews").length ) {
		$("#showMoreReviews").click(function(event){
			event.preventDefault();
			$(".moreReviews").slideDown("slow");
			$(this).hide();
			try { _gaq.push(['_trackEvent', 'Products', 'More Reviews Viewed', prodID ]); } catch (error) {}
			return false;
		});
	}
		
	// wait list signup
	if ( $("#waitListShow").length ) {
		$("#waitListShow").click(function(event){
			event.preventDefault();
			$("#waitListPop").slideToggle("normal");
			/*if ( $("#showMoreReviews").html() == "<b>show more</b>" ) {
				try { _gaq.push(['_trackEvent', 'Products', 'More Reviews Viewed', prodID ]); } catch (error) {}
				$("#showMoreReviews").html( "<b>show less</b>" );
			} else {
				$("#showMoreReviews").html( "<b>show more</b>" );
			}*/
		});
	}
		
	// show review submitted confirmation
	if ( $("#ReviewBoxPop").length ) {
		try { _gaq.push(['_trackEvent', 'Products', 'Product Review Submitted', prodID ]); } catch (error) {}
		//if ( !$("#ReviewBoxPop").dialog( "option", "height" ) ) {
		if ( !dialogCreated( $("#ReviewBoxPop") ) ) {
			var options = {};
			$("#ReviewBoxPop").dialog({
				bgiframe: true,
				height: 200,
				width: 350
			}).effect( "highlight", options, 2000 );
		} else {
			$("#ReviewBoxPop").dialog( "open" );
		}	
	} // if ( $("#ReviewBoxPop").length ) {
		
	$("#basketAdd").submit(function(){
		enableFormElements( $("#basketAdd") );
		if ( $("#Quantity").val() == "1" && prodMin > 1 ) {
			var sampleText = "SAMPLE";
			$("#pAttributes input[type=text][id!=Quantity]").each(function(i){
				if ( ($(this).val() && isNaN($(this).val())) || $(this).hasClass("required") ) {
					$(this).val(sampleText.substring(0,$(this).attr("maxlength")));
				}
			});
		}
	});
	
	if ( $("#addToBasket").length ) {
		$("#addToBasket").click(function(event){
			try {
				//try { pageTracker._trackPageview("/mm5/merchant.mvc?Screen=BASKFromProd"); } catch (error) { }
				//try { pageTracker._trackPageview("/mm5/merchant.mvc?Screen=BASK"); } catch (error) { }
			} catch(err) {
			}
		});
	}
	
	// validate quantity
	if ( $("#Quantity").length) { // this should always be true
		$("#basketAdd").validate({
			errorClass: "ui-state-error",
			/*errorContainer: "#qErrorMsg",
			errorLabelContainer: "#qErrorMsg",*/
			errorPlacement: function(error,el) {
				if ( el.attr("id") != "Quantity" ) {
					if ( !el.is("input[type='radio']") ) {
						el.parent().append("<br>").append( error ).show();
					} else {
						el.parent().parent().append("<br>").append(error).show();
					}
					if ( el.parents(".attributeLine:hidden").length ) {
						el.parents(".attributeLine").show();
					}
				} else {
					$("#qErrorMsg").html(error).show();
				}
			}
		});
		//if (  ) {
		if ( !blockSamples ) {
			if ( typeof( window.mobileSite ) == "undefined" ) { $("#Quantity").rules("add", { negativeRange: [1,prodMin] }); }
			//$("#Quantity").rules("add", { min: 5 });
			
			//$("#Quantity").rules("add", { min: 9999 });
			
			if ( $.getQueryString({id:"sampleLink", defaultvalue:""}) != "" ) {
				// lets add a link to order samples automatically...
				//$(".prodStats tr:last").after("<tr><td class=\"gBackLight\"><p class=\"darkestBlue\">Sample:</p></td><td><p class=\"darkestBlue\"><a id=\"orderSample\" href=\"javascript:void(0);\">Order a Sample</a></td></tr>");
				//$("#prodCreateAccount").before("<a id=\"orderSample\" href=\"javascript:void(0);\" style=\"margin-right: 10px;\"><img src=\"/images/buttons/order1Sample.png\" height=\"26\" width=\"120\" alt=\"Order 1 Sample\"></a>");
				//$("#pQAdd").css("width","60%");
				//$("#pSave").css("width","30%");
				//$("#addToBasket").after(" <a id=\"orderSample\" href=\"javascript:void(0);\" style=\"position:relative;top:6px;\"><img src=\"/images/buttons/order1Sample.png\" height=\"26\" width=\"120\" alt=\"Order 1 Sample\"></a>");
			}
			$("#orderSample").click(function(event){
				event.preventDefault();
				if ( !dialogCreated( $("#sampleConfirm") ) ) {
					$("body").append("<div title=\"Order a Sample\" id=\"sampleConfirm\" class=\"hideMe\"><p class=\"nomarg\" style=\"font-size: .8em;\">Please Note: we cannot personalize or honor specific color, imprint, or text selections for personalized items for samples. You will receive 1 item with random personalization.</p></div>");
					$("#sampleConfirm").dialog({
						height: 200,
						width: 500,
						modal: true,
						buttons: {
							'That\'s ok, send me a sample!': function() {
								$(this).dialog('close');
								$("#Quantity").val("1").change();
								//alert("item would now be added to cart");
								$("#basketAdd").submit();
							},
							Cancel: function() {
								$(this).dialog('close');
							}
						}
					});
				} else {
					$("#sampleConfirm").dialog( "open" );
				}
				return false;
			})/*.css("opacity",".6").hover(function(){
				$(this).css("opacity","1");
			},
			function(){
				$(this).css("opacity",".6");
			})*/;
		} else { // if ( !blockSamples ) {
			$("#Quantity").rules("add", { min: prodMin });
			//$("#orderSample").hide(); // this shouldn't exist, miva hides it
		} // if ( !blockSamples ) {
		if ( $("input#personalitytags").length ) {
			// this is the checkbox for personality tags name / dates
			// validate the name/date only if the checkbox is checked
			$("input#Names").rules("add", {
				required: {
					depends: function(element){
						return $("input#personalitytags:checked").length;
					}
				}
			});
			$("input#Date").rules("add", {
				required: {
					depends: function(element){
						return $("input#personalitytags:checked").length;
					}
				}
			});
		}
		
		// let's also hide all attributes if the quantity is changed to 1 (sample)
		// what if they're looking at an accessory item? have to deal with that also
		$("#Quantity").change(function(){
			if ( prodMin > 1 && $("#Quantity").val() == "1" && !blockSamples && $("#pAttributes p.hideMe input[name=Product_Attribute_Count]").val() >= "1" ) {
				if ( !$("#sampleMessage").length ) {
					$("#pAttributes").before("<div id=\"sampleMessage\" class=\"nomarg hideMe\" style=\"width:90%;\"><p class=\"ui-state-highlight ui-corner-all\"><span class=\"ui-icon ui-icon-info fLeft\"></span>Orders for 1 item are considered samples, and will ship with random personalization options.</p>");
					if ( $("#persTagsBox").length && $("#persTagsBox").css("display") != "none" ) {
						$("#sampleMessage p").append(" Sample personalized tags can be shipped with random personalization.");
					}
				}
				if ( !$("#persTagsBox").length || $("#persTagsBox").css("display") != "none" ) {
					// save the old values in case they change their mind										   
					var sampleText = "SAMPLE";
					$("#pAttributes input[type=text][id!=Quantity]").each(function(index){
						$(this).data( "oldValue", $(this).val() ).val(sampleText.substring(0,$(this).attr("maxlength")));
					});
					$("#pAttributes select").each(function(index){
						$(this).data( "oldValue", $(this).val() ).val("sample");
						//$("body").append("<br>" + $(this).attr("id") + " val = " + $(this).val() );
					});
				}
				//$("#pAttributes select").val("sample");
				$("#sampleMessage").show("blind", "slow");
				$("#pAttributes").hide("blind", "slow");
			} else if ( $("#sampleMessage").length && $("#pAttributes").css("display") == "none" ) {
				// check if there are old values (they filled out some data before changing quantity to 1)
				// if so, restore them
				$("#pAttributes input[type=text]").each(function(index){
					if ( $(this).data("oldValue") != "undefined" ) {
						$(this).val( $(this).data("oldValue") );
					} else {
						$(this).val("");
					}
				});
				$("#pAttributes select").each(function(index){
					if ( $(this).data("oldValue") != "undefined" && $(this).data("oldValue") != "" ) {
						$(this).val( $(this).data("oldValue") );
					} else {
						$(this).val("");
					}
				});
				$("#sampleMessage").hide("blind", "slow");
				$("#pAttributes").show("blind", "slow");
			}
		});
	}
	
	if ( $("#reviewTabs").length ) {
		// this should always be true as of 2009-06-18
		// tabify the reviews and images
		//$("#reviewTabs").tabs();
		$("#reviewTabs").tabs({ fx: { opacity: 'toggle', duration : 150 } });
		$("#reviewTabs").css({ "background-color" : "transparent", "background-image" : "none" });
		//$(".ui-tabs").css({ "background-color" : "transparent" });
		//$(".ui-widget-content").css({ "background-color" : "transparent" });
	}
	
	$.localScroll({ duration: '400' });
	
	
	// add a note about DD being out of office for a week
	/*if ( $("#DDOutOfOffice").length ) {
		$("#DDOutOfOffice").dialog({ show: 'scale' });
	}*/
	
	if ( $("#showRush").length ) {
		$("#showRush").click(function(event){
			event.preventDefault();
			if ( $("#rushProduction").dialog( "option", "bgiframe" ) ) {
				$("#rushProduction").dialog( "destroy" );
			}
			$("#rushProduction").dialog({ bgiframe: true });
			return false;
		});
	}
	
	if ( $("#cakeTabs").length ) {
		$("#cakeTabs").tabs();
		$(document).ready(function(){
			$(".ui-tabs a").css({ "padding" : "0.5em 0.7em" });
		});
	}
	if ( $("#viewcakeFavorBoxInstructions").length ) {
		$("#viewcakeFavorBoxInstructions").click(function(event){
			event.preventDefault();
			//if ( !$("#cakeFavorBoxInstructions").dialog( "option", "height" ) ) {
			if ( !dialogCreated( $("#cakeFavorBoxInstructions") ) ) {
				$("#cakeFavorBoxInstructions").dialog({
					bgiframe: true,
					height: 405,
					width: 430,
					modal: true
				}).load( $("#viewcakeFavorBoxInstructions").attr("href") );
			} else {
				$("#cakeFavorBoxInstructions").dialog( "open" );
			}
			
			return false;
		});
	}
	
	/* if ka tags, hide the monogram letter entry unless necessary */
	if ( $("#selectKATagsShape").length ) {
		$("input#Letter").parent().parent().hide();
		$("#selectDesign").change(function(){
			$("#selectDesign option:selected").each(function(){
				if ( $(this).text() == "Monogram" ) {
					if ( $("input#Letter").parent().parent().css("display") == "none" ) {
						$("input#Letter").parent().parent().show( "blind", "fast" );
						var options = {};
						$("input#Letter").parent().parent().effect( "highlight", options, 1500 );
					}
				} else {
					if ( $("input#Letter").parent().parent().css("display") != "none" ) {
						$("input#Letter").parent().parent().hide( "blind", "fast" );
					}
				}
			});
		});
	}
	
	//$("body").append("<br>1");
	if ( $("#glassDesigns").length ) {
		//$("body").append("<br>2");
		$("#glassDesigns").tabs();
		//$("body").append("<br>3");
		$(".attributeImages").css({ "height" : "125px", "width" : "125px" });
		//$("body").append("<br>4");
	}
	//$("body").append("<br>5");
	
	if ( $(".KAPBoxes").length ) {
		$('.KAPBoxes').load( '/includes/attributes/KA/personality-boxes.php?prodCode=' + prodID );
		$(".showPersonalityBoxes").live( "click",function(event){
			$("body").append("<br>click detected");
			event.preventDefault();
			// images/kate-aspen/personality-favors-v2/CODE/swatches-small/elizabeth-ivory-damask.jpg
			var imgSource = $(this).children("img").attr("src");
			code = imgSource.split( "/" );
			var prodCode = code[4];
			//if ( $("#enlargedPBImage").dialog( "option", "height" ) ) {
			if ( dialogCreated( $("#enlargedPBImage") ) ) {
				$('#enlargedPBImage').dialog( 'destroy' );
			}
			$('#enlargedPBImage').load('/includes/attributes/KA/personality-boxes/popups/ALL.php?prodCode=' + prodCode + '&image=' + escape( $(this).text() ) )
			.attr({ title: $(this).text() })
			.dialog({ width: 450, height: 450 });
		});
	}
	
	if ( $(".tooltip").length ) {
		$(".tooltip").tooltip({
			showURL: false,
			showBody: ":",
			extraClass: "pretty"
		});	
	}
	
	
	if ( $.getQueryString({id:"gclid", defaultvalue:""}) != "" ) {
		var WRInitTime=(new Date()).getTime();
		$("body").append("<div id=\"ClickTaleDiv\" style=\"display: none;\"></div>");
		if ( currentProtocol != "https:" ) {
			$("body").append(unescape("%3Cscript src='http://s.clicktale.net/WRb.js' type='text/javascript'%3E%3C/script%3E"));
			window.callCT;
			$(document).ready(function(){
				callCT = setInterval(
					function(){
						if(typeof ClickTale=='function') {
							ClickTale(11564,1,"www02");
							callCT = clearInterval(callCT);
						}
					}, 100 );
			});
		}
	}
	
	if ( $("#chocolateShippingNotes").length ) {
		var csnDate = new Date();
		if ( csnDate.getMonth() > 2 && csnDate.getMonth() < 10 ) { // between march and october
			var selectedTab = 0;
		} else {
			var selectedTab = 1;
		}
		$("#chocolateShippingNotes").tabs({ selected: selectedTab });
	}
	
	
	/*** begin 2009 redesign ****/
	if ( $("#pImages").length ) {
		$("#pImages").tabs();
		//$("#pImages").removeClass("ui-corner-all").removeClass("ui-widget-content");
	}
	
	if ( $(".prodImages").length ) {
		$(".prodImages").live( "click",function(event){
			event.preventDefault();
			/* someone has clicked one of the additional images:
			* a) enlarged prod image
			* b) cust image
			* c) additional image
			* we must:
			* 1) test if this has been done yet
			*    -- if NOT, create a new window
			*    -- left side of window gets thumbnail of main image, cust images & additionals
			*    -- right side of window gets the clicked image, enlarged
			*    -- ELSE
			*    -- right side of window gets  the clicked image, enlarged
			*/
			if ( !$("#prodImages").length ) {
				try { _gaq.push(['_trackEvent', 'Prod Images', 'Additional Prod Images Viewed', prodID ]); } catch (error) {}
				$("body").append("<div id=\"prodImages\" class=\"hideMe\" title=\"Product Images\"><div id=\"prodImagesThumbs\"></div><div id=\"prodImagesImage\"></div></div>");
				if ( $("#prodImage").length ) {
					prodThumb = window.prodThumb[0] == "/" ? window.prodThumb : "/mm5/" + window.prodThumb;
					$("#prodImagesThumbs").html( $("#prodImagesThumbs").html() + "<p class=\"nomarg\">Main Image</p><a class=\"prodImages\" href=\"" + $("#prodImage").attr("href") + "\"><img src=\"" + prodThumb + "\" height=\"100\" width=\"100\"></a>");
				}
				if ( $("#altImages").length ) {
					$("#prodImagesThumbs").html( $("#prodImagesThumbs").html() + "<p class=\"nomarg\">Alternate Images</p>" + $("#altImages").html() );
				}
				if ( $("#custImages").length ) {
					$("#prodImagesThumbs").html( $("#prodImagesThumbs").html() + "<p class=\"nomarg\">Customer Images</p>" + $("#custImages").html() );
				}
				$("#prodImagesThumbs a").removeClass( "prodImages" ).click(function(event){
					event.preventDefault();
					// it could be a link to an image or a link to a script that returns html
					// figure it out and handle it
					showProdImage( $(this).attr("href"), $(this).attr("title") );
					return false;
				});
				showProdImage( $(this).attr("href"), $(this).attr("title") );
				$("#prodImages").dialog({
					bgiframe: true,
					height: 580,
					width: "85%",
					modal: true
				});
				/* method below adds a transfer animation back to the box for
				* additional cust images etc
				* but if that doesn't exist, it breaks
				* could transfer back to the main prod image but it probably
				* won't look as good */
				/*$("#prodImages").dialog({
					bgiframe: true,
					height: 660,
					width: "85%",
					modal: true,
					beforeclose: function(event,ui){
						var transferOptions = new Array();
						transferOptions["className"] = "ui-effects-transfer";
						transferOptions["to"] = "#custImages";
						$("#prodImages").effect( "transfer", transferOptions, 250 );
					}
				});*/
			} else {
				showProdImage( $(this).attr("href"), $(this).attr("title") );
				$("#prodImages").dialog("open");
			}
			return false;
		});
	}
	

	
	//personalized tags - FC
	if ( $("#addTags").length ) {
		// there are personalized tags from FC, or there are matching tags by KA
		// show tag details
		
		rolloverLink( $("#addTags a img"), "/images/misc/prod/shopping/tag-button-not-check.png", "/images/misc/prod/shopping/tag-button-not-check-mouse-over.png", "/images/misc/prod/shopping/tag-button-not-check-mouse-down.png" );
		var tagType = "dyo"; // or "default"
		
		if ( tagType == "default" ) {
			
			$("#basketAdd").submit( function() {
				//alert("checking tag data");
				var result = checkTags();
				//alert("done checking tag data, result = " + result);
				return result;
			});
			
			//rolloverLink( $("#addTags a img"), "/images/misc/prod/shopping/optional-tag-button.png", "/images/misc/prod/shopping/optional-tag-button-mouseon.png", "/images/misc/prod/shopping/optional-tag-button-click.png" );
			
			$("#addTags a").click(function(event){
				event.preventDefault();
				
				// adjustments when attribute is set up for PE tags and DYO tags
				$("#persTagsBox .attributeLine:hidden").show();
				
				clearTags();
				$("#persTagsBox").toggle( "blind" );
				//alert("unbinding");
				$("#addTags a img").unbind("mouseenter").unbind("mouseleave").unbind("mouseup").unbind("mousedown");
				//alert("done unbinding");
				//alert("click detected, src = \r\n" + $("#addTags a img").attr("src") + "\r\npart 1 = " + ($("#addTags a img").attr("src").indexOf( "tag-button-check.png" ) != -1) + "\r\npart 2 = " + ($("#addTags a img").attr("src").indexOf( "tag-button-check-mouse-over.png" ) != -1) + "\r\npart 3 = " + ($("#addTags a img").attr("src").indexOf( "tag-button-check-mouse-down.png" ) != -1));
				
				if ( $("#addTags a img").attr("src").indexOf( "tag-button-check.png" ) != -1 || $("#addTags a img").attr("src").indexOf( "tag-button-check-mouse-over.png" ) != -1 || $("#addTags a img").attr("src").indexOf( "tag-button-check-mouse-down.png" ) != -1 ) {
					//$("#addTags a img").attr("src", "/images/misc/prod/shopping/optional-tag-button.png");
					//alert("setting image to not-checked");
					$("#addTags a img").attr("src", "/images/misc/prod/shopping/tag-button-not-check.png");
					//alert("setting rollover link to non-x");
					//rolloverLink( $("#addTags a img"), "/images/misc/prod/shopping/optional-tag-button.png", "/images/misc/prod/shopping/optional-tag-button-mouseon.png", "/images/misc/prod/shopping/optional-tag-button-click.png" );
					rolloverLink( $("#addTags a img"), "/images/misc/prod/shopping/tag-button-not-check.png", "/images/misc/prod/shopping/tag-button-not-check-mouse-over.png", "/images/misc/prod/shopping/tag-button-not-check-mouse-down.png" );
					//alert("DONE setting rollover link to non-x");
				} else {
					//$("#addTags a img").attr("src", "/images/misc/prod/shopping/optional-tag-buttonX.png");
					$("#addTags a img").attr("src", "/images/misc/prod/shopping/tag-button-check.png");
					//alert("setting rollover link to x");
					//rolloverLink( $("#addTags a img"), "/images/misc/prod/shopping/optional-tag-buttonX.png", "/images/misc/prod/shopping/optional-tag-buttonXmouseon.png", "/images/misc/prod/shopping/optional-tag-buttonX.png" );
					rolloverLink( $("#addTags a img"), "/images/misc/prod/shopping/tag-button-check.png", "/images/misc/prod/shopping/tag-button-check-mouse-over.png", "/images/misc/prod/shopping/tag-button-check-mouse-down.png" );
					//alert("DONE setting rollover link to x");
				}
				return false;
				//try { _gaq.push(['_trackEvent', 'Products', 'Tag Details Viewed', prodID ]); } catch (error) {}
			});
			$("#persTagsBox .closeTags").click(function(event){
				event.preventDefault();
				$("#addTags a").click();
				return false;
			});
			
			// hide dropdowns that are filled by interface
			$("#selectPersTags").parent().hide().prev().hide().next().next().next().next().hide().parent().prev();
			$("#selectShapeColor").parent().parent().parent().hide();
			
			// adjustments when attribute is set up for PE tags and DYO tags
			$("#Line1,#Line2,#selecttextLines23Color,#selecttextLine1Color,#selectfontStyle,#selectdesign,#selectpatternColor,#selectPattern,#selectborderColor,#selectbackgroundColor,#selectLayout").parents(".attributeLine").hide();
		} else {
			$("#Line1,#Line2,#selecttextLines23Color,#selecttextLine1Color,#selectfontStyle,#selectdesign,#selectpatternColor,#selectPattern,#selectborderColor,#selectbackgroundColor,#selectLayout").parents(".attributeLine").hide();
			$("#selectLayout").parents(".attributeLine").children(".aNumber").children("img").attr({"src":"/images/misc/prod/numbers/1.png", "alt": "1"});
			
			$("#addTags a").data({
				"optionsVisible" : "0",
				"tagType" : tagType
			});
			
			$("#addTags a").click(function(event){
				event.preventDefault();
				clearTags();
				//jqToggleLayer( "persTagsBox", null, 0 );
				//jqSlideLayer( "persTagsBox", "slow", 0 );
				// unhide each option
				if ( $("#addTags a").data("optionsVisible") == "0" ) {
					$("#selectLayout").parents(".attributeLine").show("blind", 200);
					$("#Line1,#Line2,#selecttextLines23Color,#selecttextLine1Color,#selectfontStyle,#selectdesign,#selectpatternColor,#selectPattern,#selectborderColor,#selectbackgroundColor,#selectLayout").addClass("required");
					$("#addTags a").data("optionsVisible","1");
				} else {
					$("#selectLayout").parents(".attributeLine").hide("blind", 200);
					$("#Line1,#Line2,#selecttextLines23Color,#selecttextLine1Color,#selectfontStyle,#selectdesign,#selectpatternColor,#selectPattern,#selectborderColor,#selectbackgroundColor,#selectLayout").removeClass("required");
					$("#addTags a").data("optionsVisible","0");
				}
				try { _gaq.push(['_trackEvent', 'Products', 'Tag Details Viewed', prodID ]); } catch (error) {}
				return false;
			});
			
			
			
			$("#addTags a img").unbind("mouseenter").unbind("mouseleave").unbind("mouseup").unbind("mousedown");
			if ( $("#addTags a img").attr("src").indexOf( "tag-button-check.png" ) != -1 || $("#addTags a img").attr("src").indexOf( "tag-button-check-mouse-over.png" ) != -1 || $("#addTags a img").attr("src").indexOf( "tag-button-check-mouse-down.png" ) != -1 ) {
				$("#addTags a img").attr("src", "/images/misc/prod/shopping/tag-button-not-check.png");
				rolloverLink( $("#addTags a img"), "/images/misc/prod/shopping/tag-button-not-check.png", "/images/misc/prod/shopping/tag-button-not-check-mouse-over.png", "/images/misc/prod/shopping/tag-button-not-check-mouse-down.png" );
			} else {
				$("#addTags a img").attr("src", "/images/misc/prod/shopping/tag-button-check.png");
				rolloverLink( $("#addTags a img"), "/images/misc/prod/shopping/tag-button-check.png", "/images/misc/prod/shopping/tag-button-check-mouse-over.png", "/images/misc/prod/shopping/tag-button-check-mouse-down.png" );
			}
		}
		
	} // if ( $("#addTags").length ) {
	
	if ( $(".textBox").length ) {
		$(".textBox").keyup(function(event){
			var length = $(this).val().length ? $(this).val().length : $(this).html().length;
			$("#cCount" + $(this).attr("id")).html( length );
			if ( length >= $(this).attr("maxlength") ) {
				$("#cCount" + $(this).attr("id")).removeClass("green").addClass("red");
			} else {
				$("#cCount" + $(this).attr("id")).removeClass("red").addClass("green");
			}
		});
	}
	$("#pInfo").tabs({
		fx: { opacity: 'toggle', duration : 75 },
		show: function(event,ui){
			var selected = $("#pInfo").tabs('option', 'selected');
			//alert(selected);
			switch( selected ){
			case 0:
				selected = "Description";
				break;
			case 1:
				selected = "Shipping/Production";
				break;
			case 2:
				selected = "Reviews";
				break;
			}
			try { _gaq.push(['_trackEvent', 'Tab Selected', selected + ' Tab Viewed', prodID ]); } catch (error) {}
		}
	});
	
	// personalization designs JQUI - VERSION 2
	if ( $(".showDesignsJQUIv2").length ) {
		$(".showDesignsJQUIv2").click(function(event) {
			event.preventDefault();
			/*new version, differences are:
			* popup Div will never be present by default, it must be added
			* data is always loaded from href of clicked link
			* this enables multiple links to share the same dialog container,
			* as opposed to one unique container for each link
			*/
			if ( $("#JQUIDialogv2").length ) {
				// if it has been created, we just load the new data and show it
				$("#ui-dialog-title-JQUIDialogv2").text( $(this).attr("title") );
				$("#JQUIDialogv2").attr({ title: $(this).attr("title") }).dialog("open");
				if ( $("#JQUIDialogv2").data( "currentURL" ) != $(this).attr("href") ) {
					$("#JQUIDialogv2").load( $(this).attr("href"), function( responseText, textStatus, XMLHttpRequest){
						uniformSizes( $(".attributeImages") );
					}).data( "currentURL", $(this).attr("href") );
				}				
			} else {
				$("body").append("<div id=\"JQUIDialogv2\"></div>");
				$("#JQUIDialogv2").attr({ title: $(this).attr("title") }).dialog({
					bgiframe: true,
					width: 800,
					height: 600,
					modal: true
				}).load( $(this).attr("href"), function( responseText, textStatus, XMLHttpRequest){
					uniformSizes( $(".attributeImages") );
				}).data( "currentURL", $(this).attr("href") );
			}
		});
	} // if ( $("#showDesignsJQUI").length ) {
	

	/* ScrollTo annoyance:
	* if link is something like /page/FF/PROD/#asdf
	* scrollto takes about 4 to 6 milliseconds before beginning the animation
	* it seems to be confused by links with a path that are pointing to this page
	* we need the path because we use base href, without the path the links are
	* interpreted as favorfavor.com/#asdf which is annoying and doesn't work
	* in browsers with javascript disabled */
	/* also be careful with offset, in IE6 & 7 it combines with the localscroll plugin
	* localscroll scrolls to the correct area, then scrollto does the offset,
	* creating a bounce effect */
	if ( $(".pRating").length ) {
		$(".pRating a").click(function(event){
			event.preventDefault();
			$("#pInfo").tabs( "select", "prodInfoReviews" );
			//$.scrollTo("#pInfo", "400",{axis:"y",offset:-150});
			$.scrollTo("#pInfo", "400",{axis:"y"});
			return false;
		});
	}
	
	if ( $("#pRight a[href*='" + prodID + "#prodInfoShipping']").length ) {
		$("#pRight a[href*='" + prodID + "#prodInfoShipping']").click(function(event){
			event.preventDefault();
			/* we can scroll to the tab and select it, or we
			* can pop up the data in a dialog box
			* lets pop it up
			* the easiest way to pop it up is to trigger a click
			* event for the UPS Transit Map link, which does the same thing */
			
			$(".upsTransitMap").click();
			
			// autoscroll method is below
			//$("#pInfo").tabs( "select", "prodInfoShipping" );
			//$.scrollTo("#pInfo", "400" );
			
			return false;
		});
	}
	
	/* recently viewed items
	* this is present on PROD and CTGY */
	if ( $("#toggleSuggestedItemHistory").length ) {
		$("#toggleSuggestedItemHistory").click(function(event){
			event.preventDefault(); // this isn't a link so there should be no default action but whatever
			$("#suggestedItemHistory").toggle();
			try { _gaq.push(['_trackEvent', 'History', 'History Menu Toggled', prodID ]); } catch (error) {}
			return false;
		});
	}



	if ( $("#prodCreateAccount").length ) {
		$("#prodCreateAccount").click(function(event){
			event.preventDefault();
			$.getScript( "/js/acad.js" );
			
			if ( !$("#createAccountDialog").length ) {
				$("body").append("<div id=\"createAccountDialog\" class=\"hideMe\" title=\"Create Account to Save Your Basket &amp; Recall Later\"></div>");
				$("#createAccountDialog").load( "/includes/ajax/acad.php", function(){
					$(document).ready(function(){
						try { _gaq.push(['_trackEvent', 'Products', 'Save Basket: Info Viewed', prodID ]); } catch (error) {}
						$("#accountCreate").validate({
							errorClass: "ui-state-error",
							rules: {
								Customer_Login: "required",
								Customer_PasswordEmail: {
									required: true,
									email: true
								},
								Customer_Password: "required",
								Customer_VerifyPassword: "required",
								Customer_ShipFirstName: {
									required: {
										depends: function(element) {
											return $("#addressInfo:checked").length;
										}
									}
								},
								Customer_BillLastName: {
									required: {
										depends: function(element) {
											return $("#addressInfo:checked").length;
										}
									}
								},
								Customer_BillEmail: {
									required: {
										depends: function(element) {
											return $("#addressInfo:checked").length;
										}
									}
								},
								Customer_BillPhone: {
									required: {
										depends: function(element) {
											return $("#addressInfo:checked").length;
										}
									},
									minlength: 7,
									digits: true
								},
								Customer_BillAddress: {
									required: {
										depends: function(element) {
											return $("#addressInfo:checked").length;
										}
									}
								},
								Customer_BillCity: {
									required: {
										depends: function(element) {
											return $("#addressInfo:checked").length;
										}
									}
								},
								Customer_BillStateSelect: {
									required: {
										depends: function(element) {
											return $("#addressInfo:checked").length;
										}
									}
								},
								Customer_BillZip: {
									required: {
										depends: function(element) {
											return $("#addressInfo:checked").length;
										}
									},
									minlength: 5,
									digits: true
								},
								Customer_BillCountry: {
									required: {
										depends: function(element) {
											return $("#addressInfo:checked").length;
										}
									}
								},
								Customer_ShipFirstName: {
									required: {
										depends: function(element) {
											return $("#differentShipping:checked").length;
										}
									}
								},
								Customer_ShipLastName: {
									required: {
										depends: function(element) {
											return $("#differentShipping:checked").length;
										}
									}
								},
								Customer_ShipEmail: {
									required: {
										depends: function(element) {
											return $("#differentShipping:checked").length;
										}
									},
									email: true
								},
								Customer_ShipPhone: {
									required: {
										depends: function(element) {
											return $("#differentShipping:checked").length;
										}
									},
									minlength: 7,
									digits: true
								},
								Customer_ShipAddress: {
									required: {
										depends: function(element) {
											return $("#differentShipping:checked").length;
										}
									}
								},
								Customer_ShipCity: {
									required: {
										depends: function(element) {
											return $("#differentShipping:checked").length;
										}
									}
								},
								Customer_ShipStateSelect: {
									required: {
										depends: function(element) {
											return $("#differentShipping:checked").length;
										}
									}
								},
								Customer_ShipZip: {
									required: {
										depends: function(element) {
											return $("#differentShipping:checked").length;
										}
									},
									minlength: 5,
									digits: true
								},
								Customer_ShipCountry: {
									required: {
										depends: function(element) {
											return $("#differentShipping:checked").length;
										}
									}
								}
							
							}
						});
						$("#createAccount").click(function(event){
							event.preventDefault();
							if ( $("#accountCreate").valid() ) {
								try { _gaq.push(['_trackEvent', 'Products', 'Save Basket: Account Created, Item Added', prodID ]); } catch (error) {}
								createAccount( sessionID, "prod" );
							}
							return false;
						});
						
						$("#accountLoginForm").validate({
							rules: {
								accountLoginCustomer_Login: "required",
								accountLoginCustomer_Password: "required"
							}
						});
						$("#loginAccount").click(function(event){
							event.preventDefault();
							if ( $("#accountLoginForm").valid() ) {
								//alert("login detected, tracking");
								try { _gaq.push(['_trackEvent', 'Products', 'Save Basket: Logged In, Item Added', prodID ]); } catch (error) {}
								//alert("logging in");
								loginAccount( sessionID, "prod" );
							}
							return false;
						});
						
						$("#whatIsThis").click(function(event){
							event.preventDefault();
							$("#whatIsThisInfo").load( "/includes/ajax/whatIsThisProd.php", function(){
								$(document).ready(function(){
									//if ( !$("#whatIsThisInfo").dialog( "option", "height" ) ) {
									if ( !dialogCreated( $("#whatIsThisInfo") ) ) {
										$("#whatIsThisInfo").dialog({
											bgiframe: true,
											height: 250,
											width: 350
										});
									} else {
										$("#whatIsThisInfo").dialog( "open" );
									}
								});
							});
							return false;
						});
						
					});															
				}).dialog({
					bgiframe: true,
					height: 490,
					width: 700,
					modal: true
				});
			} else {
				$("#createAccountDialog").dialog( "open" );
			}
			return false;
	   });
	} // if ( $("#prodCreateAccount").length ) {

	if ( $("#prodAddWishList").length ) {
		$.getScript( '/js/acad.js' );
		$("#prodAddWishList").click(function(event){
			event.preventDefault();
			//alert("click detected, tracking");
			try { _gaq.push(['_trackEvent', 'Products', 'Save Basket: Item Added', prodID ]); } catch (error) {}
			//alert("saving basket");
			saveBasket( '', sessionID, "prod", "loggedIn" );
			return false;
		});
		
	}

	// hide additional input elements (mainly for JDS items)
	if ( $("#Item2Line1").length ) {
		//$("body").append("<br>making accordion");
		// there are additional item inputs, lets make it into an accordian
		// first we have to surround each attribute with a blank div
		// and add an h3 header
		// then we can accorion it
		var attributeCount = $("input[id*=Line1]").length;
		//$("body").append("<br>attribute count: " + attributeCount );
		
		//alert(prodMin);
		//$(".attributeLine").before("<h3><a href=\"#\">Item</a></h3>");
		//$("#pAttributes").accordion();
		
		//$(".attributeLine:even").before("<h3><a href=\"#\">Item</a></h3><div class=\"blueBG\">");
		//$(".attributeLine:odd").after("</div>");
		//$(".attributeLine:even,.attributeLine:odd").wrapAll("<div class=\"blueBG\"></div>");
		//$("#pAttributes").accordion();
		
		//$('.attributeLine:lt(2)').wrapAll("<div class=\"blueBG\" />");
		//$('.attributeLine:gt(1)').wrapAll("<div class=\"blueBG\" />");
		
		//$('.attributeLine:eq(1),.attributeLine:eq(0)').wrapAll('<div class="blueBG" />');
		//$('.attributeLine:eq(2),.attributeLine:eq(1)').wrapAll('<div class="blueBG" />');
		
		var totalAttributes = $("input[name=Product_Attribute_Count]").val();
		var grouping = Math.floor( totalAttributes / attributeCount );
		var remaining = totalAttributes % grouping;
		/*$("body").append("<br>total attributes = " + totalAttributes);
		$("body").append("<br>attribute count = " + attributeCount);
		$("body").append("<br>grouping = " + grouping);
		$("body").append("<br>remaining = " + remaining);
		$("body").append( "<br>length = " + $("img[src*='/images/misc/prod/numbers']").length );*/
		/*if ( totalAttributes % 2 ) {
			if ( totalAttributes % 3 ) {
				var grouping = 1;
			} else {
				var grouping = 3;
			}
		} else {
			// totalAttributes remainder was 0 (it divided evenly)
			var grouping = 2;
		}*/
		//$("body").append("<br>grouping = " + grouping);
		switch( grouping ) {
			case 1:
				//$("body").append("<br>grouping as 1");
				for( i = 0; i <= attributeCount*grouping; i++ ) {
					if ( $(".attributeLine:eq("+i+")").length ) {
						var oneUp = i+1;
						$(".attributeLine:eq("+i+")").before("<h3><a href=\"#\">Personalization " + oneUp + "</a></h3>");
						$(".attributeLine:eq("+i+")").wrap("<div class=\"nomarg\" />");
						$(".attributeLine:eq("+i+") img[src*='/images/misc/prod/numbers']").attr("src", "/images/misc/prod/numbers/1.png" );
					}
				}
				break;
			case 2:
				//$("body").append("<br>grouping as 2");
				if ( prodID == "GC309" || prodID == "GC193" || prodID == "GC180" ) {
					// item GC309 has 2 additional attributes so we have to loop one more time
					attributeCount++;
				}
				var startingPoint = 0;
				/* before the loop, we must manually group the remaining attributes
				* regardless of how many there are
				* it is assumed they will be first
				* then we must start the loop right after the last remaining attribute
				*/
				if ( remaining ) {
					//$("body").append("<br>wrapping remainders, total = " + remaining);
					for ( i = 1; i <= remaining; i++ ) {
						var matchThis = i-1;
						$(".attributeLine:eq(" + matchThis + ")").addClass("attrLineW").before("<h3><a href=\"#\">Design</a></h3>");
						//$("body").append("<br>added class");
						
					}
					//$("body").append( "<br>" + $(".attrLineW").text() );
					$(".attrLineW").wrapAll('<div class="nomarg accWrapper" />');
					startingPoint = remaining+1;
				}
				//$("body").append("<br>starting point = " + startingPoint);
				for( i = startingPoint; i <= attributeCount*grouping; i++ ) {
					//$("body").append("<br>i = " + i );
					var oneDown = i-1;
					var twoDown = i-2;
					var threeDown = i-3;
					//$("body").append("<br>" + $(".attributeLine:eq("+oneDown+")").text());
					//$("body").append("<br>" + $(".attributeLine:eq("+i+")").text());
					var okToWrap = startingPoint ? !(i % grouping) : (i % grouping);
					if ( okToWrap && $(".attributeLine:eq("+oneDown+")").length ) {
						//$("body").append("<br>....wrapping");
						$(".attributeLine:eq("+oneDown+")").before("<h3><a href=\"#\">Personalization " + Math.ceil(i/2) + "</a></h3>");
						$(".attributeLine:eq("+oneDown+"),.attributeLine:eq("+i+")").wrapAll("<div class=\"nomarg accWrapper\" />");
						$(".attributeLine:eq("+oneDown+") img[src*='/images/misc/prod/numbers']").attr("src", "/images/misc/prod/numbers/1.png" );
						$(".attributeLine:eq("+i+") img[src*='/images/misc/prod/numbers']").attr("src", "/images/misc/prod/numbers/2.png" );
					}
				}
				var blockAccordion = 0;
				break;
			case 3:
				//$("body").append("<br>grouping as 3");
				for( i = 3; i <= attributeCount*grouping; i++ ) {
					var oneDown = i-1;
					var twoDown = i-2;
					var threeDown = i-3;
					if ( !(i % grouping) && $(".attributeLine:eq("+oneDown+")").length ) {
						/*$("body").append("<br>i = " + i );
						$("body").append( $(".attributeLine:eq("+oneDown+")").text() );
						$("body").append( $(".attributeLine:eq("+twoDown+")").text() );
						$("body").append( $(".attributeLine:eq("+threeDown+")").text() );*/
						$(".attributeLine:eq("+threeDown+")").before("<h3><a href=\"#\">Personalization " + Math.ceil(oneDown/3) + "</a></h3>");
						$(".attributeLine:eq("+oneDown+"),.attributeLine:eq("+twoDown+"),.attributeLine:eq("+threeDown+")").wrapAll("<div class=\"nomarg\" />");
						$(".attributeLine:eq("+threeDown+") img[src*='/images/misc/numbers']").attr("src", "/images/misc/prod/numbers/1.png" );
						$(".attributeLine:eq("+twoDown+") img[src*='/images/misc/prod/numbers']").attr("src", "/images/misc/prod/numbers/2.png" );
						$(".attributeLine:eq("+oneDown+") img[src*='/images/misc/prod/numbers']").attr("src", "/images/misc/prod/numbers/3.png" );
					}
				}
				break;
		}
		$("#pOrder").after( $("#pAttributes") );
		if ( !blockAccordion ) { $("#pAttributes").accordion({autoHeight:false}); }
		$(".ui-accordion-content,.ui-accordion").css({ "margin-bottom":"0px","padding-bottom":"0px"});
	}

	/**** button rollovers *****/
	//rolloverLink( el, off, over, clicked );
	rolloverLink( $("#addToBasket"), "/images/misc/prod/shopping/add-to-cart.png", "/images/misc/prod/shopping/add-to-cart-on.png", "/images/misc/prod/shopping/add-to-cart-click.png" );
	rolloverLink( $("#psShare img"), "/images/misc/prod/share-reg.png", "/images/misc/prod/share-mouse-on.png", "/images/misc/prod/share-mouse-click.png" );
	rolloverLink( $("#psPrint img"), "/images/misc/prod/print-reg.png", "/images/misc/prod/print-mouse-over.png", "/images/misc/prod/print-mouse-click.png" );
	rolloverLink( $("#psBookmark img"), "/images/misc/prod/bookmark-reg.png", "/images/misc/prod/bookmark-mouse-over.png", "/images/misc/prod/bookmark-mouse-click.png" );
	rolloverLink( $("#orderSample img"), "/images/misc/prod/shopping/order1sample-button2.png", "/images/misc/prod/shopping/order1sample-button-mouse-over2.png", "/images/misc/prod/shopping/order1sample-button-mouse-click.png" );
	var wishListEl = $("#prodCreateAccount").length ? $("#prodCreateAccount img") : $("#prodAddWishList img");
	rolloverLink( wishListEl, "/images/misc/prod/shopping/wish-list-button.png", "/images/misc/prod/shopping/wish-list-button-mouse-over.png", "/images/misc/prod/shopping/wish-list-button-mouse-click.png" );

	if ( offerSeparateOptions ) {
		//$("body").append("<br>offering separate options");
		$("#pAttributes").attr("title","Choose Options").before("<div style=\"display: none;\"><p style=\"margin-left: 5px;\">Enter your quantity below and then Click 'Add to Cart' to begin personalizing each item. <a href=\"javascript:void(0);\" id=\"chooseSeparateOptions\" style=\"display:none;\">choose options</a></p></div>").hide();
		
		rolloverRemove( $("#addToBasket") );
		$("#addToBasket").attr("src", "/images/misc/prod/shopping/personalize.png");
		rolloverLink( $("#addToBasket"), "/images/misc/prod/shopping/personalize.png", "/images/misc/prod/shopping/personalize-on.png", "/images/misc/prod/shopping/personalize-click.png" )
		
		$("#addToBasket").click(function(event){
			event.preventDefault();
			$("#chooseSeparateOptions").click();
			return false;
		});
		$("#chooseSeparateOptions").button().click(function(event){
			event.preventDefault();
			if( !dialogCreated( $("#pAttributes") ) ) {
				$("#pAttributes").dialog({
					height: 560,
					width: 600,
					bgiframe: true,
					modal: true
				}).prepend("<div class=\"chooseSeparateOptionsDsc\"><label class=\"hideMe\">Quantity: <input class='ui-corner-all ui-widget-content valid' type='text' name='chooseSeparateOptionsQty' value='1' size='4' id='chooseSeparateOptionsQty' style='text-align: center;'><br></label><label><input type='radio' name='chooseSeparateOptionsType' id='chooseSeparateOptions-separateOptions' value='chooseSeparateOptions-separateOptions'>Choose options for item <b class='optionCountCurrent'>1</b> of <b class='optionCountMax'>1</b></label><br><label><input type='radio' name='chooseSeparateOptionsType' id='chooseSeparateOptions-sameForAll' value='chooseSeparateOptions-sameForAll'>Use the same options for <b class=\"optionCountRemaining\"></b> item(s)</label></div>").parent().appendTo("#basketAdd").addClass("posRel");			
				
				$("#chooseSeparateOptionsQty").keyup(function(event){
					$("#Quantity").val($(this).val());
					$(".optionCountMax").text($(this).val());
					$(".optionCountRemaining").text($(this).val());
				}).val( $("#Quantity").val() );
				$(".attributeLine").wrapAll("<div id=\"chooseSeparateOptionsContainer\"></div>");
				$("#chooseSeparateOptionsContainer").after("<div class=\"fRight\"><p class=\"nomarg\">&nbsp;<span id=\"nowPersonalizing\">Now personalizing item <b class='optionCountCurrent'>1</b> of <b class='optionCountMax'>1</b></span></p><p class=\"nomarg fLeft\"><img src=\"/images/misc/loadingAnimation.gif\" height=\"13\" width=\"208\" id=\"chooseSeparateOptionsLoad\" class=\"hideMe\"><img src=\"/images/misc/greencheck.gif\" height=\"18\" width=\"18\" alt=\"success\" class=\"hideMe\" id=\"chooseSeparateOptionsGreencheck\" style=\"margin-top: 6px;\"></p><p class=\"nomarg fRight\"><a href=\"javascript:void(0);\" id=\"useSeparateOptions\">Use these options for <span id=\"useForItemCount\">item <span class=\"optionCountCurrent\">1</span><span id=\"useSepOptionsCont\" class=\"hideMe\">and continue</span></span><span class=\"hideMe\" id=\"useForFinal\">final item and continue</span><span class=\"hideMe\" id=\"useForAll\">all items and continue</span></a></p></div>");
				$(".optionCountMax").text( $("#Quantity").val() );
				$(".optionCountRemaining").text( $("#Quantity").val() );
				var chooseSeparateOptionsCoverPosition = $("#chooseSeparateOptionsContainer").position();
				$("<div id=\"chooseSeparateOptionsCover\" class=\"ui-widget-overlay\" style=\"background-color: #999 !important;\">").appendTo($("#chooseSeparateOptionsContainer").parent()).css({
					top: chooseSeparateOptionsCoverPosition.top,
					left: chooseSeparateOptionsCoverPosition.left
				});
				$("input[name='chooseSeparateOptionsType']").change(function(event){
					if ( $("#chooseSeparateOptionsCover").is(":visible") ) {
						$("#chooseSeparateOptionsCover").hide( "slide", "fast" );
					}
					if ( $(this).val() == "chooseSeparateOptions-sameForAll" ) {
						$("#useForAll").show();
						$("#useForItemCount,#nowPersonalizing").hide();
					} else {
						$("#useForAll").hide();
						$("#useForItemCount,#nowPersonalizing").show();
					}
				});
				$("#useSeparateOptions").button().click(function(event){
					event.preventDefault();
					//alert( $("#basketAdd").valid() );
					//alert($("input[name='chooseSeparateOptionsType']:checked").val());
					if ( $("#basketAdd").valid() ) {
						$("#useSeparateOptions").hide( );
						if ( $("input[name='chooseSeparateOptionsType']:checked").val() == "chooseSeparateOptions-separateOptions" ) {
							$("#Quantity").val(1);
						} else {
							//$("#Quantity").val($("#chooseSeparateOptionsQty").val());
							$("#Quantity").val($(".optionCountRemaining").text());
						}
						$("#chooseSeparateOptionsGreencheck").hide();
						$("#chooseSeparateOptionsLoad").show( "slide", "fast" );
						
						enableFormElements( $("#basketAdd") );
						var formData = $("#basketAdd").serialize();
						//$("body").append("<br>fd = " + formData);
						disableFormElements( $("#basketAdd") );
						
						var postTo = $("#basketAdd").attr("action");
						//$("body").append("<br>posting to: " + postTo);
						//$("body").append("<br>adding to basket <br>---<br>" + formData);
						$.post( postTo, formData, function( data, status, jqXHR ) {
							$("#chooseSeparateOptionsLoad").hide();
							//$("body").append("<br>status = " + status );
							//$("body").append("<br><br><br>----<br><br><br>" + data );
							//alert(data);
							if ( status == "success" ) {
								$("#chooseSeparateOptionsGreencheck").show( "slide", "fast" );
								$("#useSeparateOptions").show( "slide", "fast" );
								if ( $("input[name='chooseSeparateOptionsType']:checked").val() == "chooseSeparateOptions-separateOptions" ) {
									if ( Number($(".optionCountCurrent:first").text()) == Number($("#chooseSeparateOptionsQty").val()) ) {
										//alert("done, should redirect now");
										window.location = $("#cartLinkSID").attr("href");
									} else {
										$(".optionCountCurrent").text( Number($(".optionCountCurrent:first").text()) + 1 );
										$(".optionCountRemaining").text( Number($(".optionCountRemaining:first").text()) - 1 );
										
										// reset options
										$("#chooseSeparateOptionsContainer input:visible[type='text']").val("");
										$("#chooseSeparateOptionsContainer select:visible").val("");
										$("#chooseSeparateOptionsContainer .greenCheck:visible").hide();
										
										// if we are now on the last item, update the button text
										if ( Number($(".optionCountCurrent:first").text()) == Number($("#chooseSeparateOptionsQty").val()) ) {
											$("#useForFinal").show();
											$("#useForItemCount").hide();
										}
									}
								} else {
									// simply redirect, this is for all items
									window.location = $("#cartLinkSID").attr("href");
								}
							}
							//alert( $('<div/>').text(data).html() );
							//$("body").append( $('<div/>').text(data).html() );
							//alert(data);
						}, "html");
					} else {
						//alert("not valid form");
					}
					return false;
				});
			} else {
				$("#pAttributes").dialog("open");
				$("#chooseSeparateOptionsQty").val( $("#Quantity").val() );
				$(".optionCountMax").text($("#Quantity").val());
				$(".optionCountRemaining").text($("#Quantity").val());
			}
			return false;
		});
	} else { // if ( offerSeparateOptions ) {
		//$("body").append("<br>NOT offering separate options");
	} // if ( offerSeparateOptions ) {

	if ( $(".upsTransitMap").length ) {
		$(".upsTransitMap").click(function(event){
			event.preventDefault();
			if ( !$("#upsTransitMap").length ) {
				$("body").append("<div id=\"upsTransitMap\" title=\"UPS Transit Map\" style=\"font-size: .8em;\"></div>");
				$("#upsTransitMap").html( $("#prodInfoShipping").html() );
				$("#upsTransitMap").dialog({
					bgiframe: true,
					height: 500,
					width: 600,
					modal: true
				});
			} else {
				$("#upsTransitMap").dialog( "open" );
			}
			return false;
		});
	}

	if ( $(".prodStats").length && $(".pRating").length ) {
		$(".prodStats .pRating span.blue").removeClass("blue").addClass("darkBlue");
	}
	
	if ( $("#shipsOnOrAbout").length ) {
		$("#shipsOnOrAbout").parent().parent().parent().hide();
	}
	
	if ( isGlassware ) {
		if ( $("#shipsOnOrAbout").length  && !outOfStock ) {
			/* note: this CAN handle items that are out of stock, the code is available below.
			* but we don't want it enabled for them right now, because maybe they will ship sooner than
			* the usual production time, hence the "&& !outOfStock" above
			*/
			
			if ( 1 ) {
				// pull shipping date from Fashioncraft
				var futureURL = "http://www.fashioncraft.com/utilities/glassShipDate.php?a=1&jsoncallback=?";
				$.getJSON(futureURL, function(data){
					var date = String(data["shipDate"]).split( /\-/g );
					var year = date[0];
					var month = date[1];
					var day = date[2];
					switch( date[1] ) {
					case "01":
						month = "January";
						break;
					case "02":
						month = "February";
						break;
					case "03":
						month = "March";
						break;
					case "04":
						month = "April";
						break;
					case "05":
						month = "May";
						break;
					case "06":
						month = "June";
						break;
					case "07":
						month = "July";
						break;
					case "08":
						month = "August";
						break;
					case "09":
						month = "September";
						break;
					case "10":
						month = "October";
						break;
					case "11":
						month = "November";
						break;
					case "12":
						month = "December";
						break;
					}
					var newShipDate = month + " " + day + ", " + year;
					$("#shipsOnOrAbout").val( newShipDate );
					$(".prodAvailability").html("Ships<a title=\"This refers to the date the item will leave our warehouse. For a transit time estimate, click on the 'more shipping info' link to the right.\" class=\"shippingOnOrAboutDescription\" style=\"color: #00f\" href=\"javascript:void(0);\">*</a> on or about " + newShipDate);
					$(".shippingOnOrAboutDescription").tooltip({
						showURL: false,
						showBody: ":",
						extraClass: "pretty"
					}).click(function(event){
						event.preventDefault();
						return false;
					});
				});
			} else { // if ( 1 ) {
				// use our own script
				var advanceDays = 14;
				var advanceWeeks = 0;
				var futureURL = "/pscripts/misc/futureDate.php?days=" + advanceDays + "&weeks=" + advanceWeeks;
				if ( outOfStock ) {
					futureURL += "&return=" + escape($(".prodAvailability").text().split(":")[0].split(" ")[1]);
				}
				$.get(futureURL, function(data){
					$("#shipsOnOrAbout").val(data);
					$(".prodAvailability").html("Ships<a title=\"This refers to the date the item will leave our warehouse. For a transit time estimate, click on the 'more shipping info' link to the right.\" class=\"shippingOnOrAboutDescription\" style=\"color: #00f\" href=\"javascript:void(0);\">*</a> on or about " + data);
					$(".shippingOnOrAboutDescription").tooltip({
						showURL: false,
						showBody: ":",
						extraClass: "pretty"
					}).click(function(event){
						event.preventDefault();
						return false;
					});
				});
			} // if ( 1 ) {
		} // if ( $("#shipsOnOrAbout").length  && !outOfStock ) {
		
		if ( $(".fashioncraftGlasswareLink").length ) {
			// hide glassware attributes
			$("#pAttributes .attributeLine").each(function(index){
				if ( $(this).has( $(".fashioncraftGlasswareLink") ).length ) {
					$("select",this).hide();
				} else {
					$(this).hide();
				}
			});
		}
		
		if ( $(".fashioncraftGlasswareLink").length ) {
			// add fashioncraft's glassware info to product descriptions
			//$("body").append("<br>working");
			$.get("/includes/ajax/glass/bullets.htm", function(data){
				//$("body").append("<br>working 2");
				data = data.split("|");
				$("#prodInfoDescription ul").append(data[0]);
				$("#prodInfoDescription").append(data[1]);
		
				if ( $("#custArtLink").length ) {
					$("#custArtLink").click(function(event){
						event.preventDefault();
						if ( !dialogCreated( $("#custArtPop") ) ) {
							$("body").append("<div id=\"custArtPop\" class=\"hideMe\" title=\"Custom Artwork\" style=\"font-size: .8em;\">");
							$("#custArtPop").load( $(this).attr("href"), function(){
								$("#custArtPop").dialog({
									bgiframe: true,
									height: 260,
									width: 500,
									modal: true
								});
							});
						} else {
							$("#custArtPop").dialog( "open" );
						}
						return false;
					});
				} // if ( $("#custArtLink").length ) {
			});
		}
	} // if ( isGlassware ) {

	if ( $("#DDAssembly").length ) {
		$("#DDAssembly").click(function(event){
			event.preventDefault();
			if ( !dialogCreated( $("#DDAssemblyExpl") ) ) {
				$("body").append("<div id=\"DDAssemblyExpl\" class=\"hideMe\" title=\"Assembly Options\" style=\"font-size: .8em;\">");
				$("#DDAssemblyExpl").load( $(this).attr("href"), function(){
					$("#DDAssemblyExpl").dialog({
						bgiframe: true,
						height: 200,
						width: 400,
						modal: true
					});
				});
			} else {
				$("#DDAssemblyExpl").dialog( "open" );
			}			   
			return false;
		});
	} // if ( $("#DDAssembly").length ) {

	/* design testing */
	/*$("#pInfo").draggable().resizable().css("background-color","fff");
	$("#customersShopped").draggable().resizable().css("background-color","fff");
	$("#customersAlsoShopped").draggable().resizable().css("background-color","fff");
	$("#suggestedItems").draggable().resizable().css("background-color","fff");*/
	

	/*********** PRODUCT SPECIFIC ************/
	switch( prodID ) {
	case "heartmatch":
		$("#selectColor option[value=Silver]").remove();
		$("#selectColor option[value=Gold]").remove();
		break;
	case "Match":
		$("#selectColor").change(function(event){
			if ( $(this).val() == "Silver" || $(this).val() == "Gold" ) {
				// automatically choose the same color for imprinting, and disable the menu
				$("#selectPrtCol").val( $(this).val() ).prop( "disabled", true );
			} else {
				$("#selectPrtCol").prop( "disabled", false );
			}
		});
		break;
	case "EB2138":
		// remove latte and ivory options
		$(".attributeImages img[src*=classic-aqua-blue.jpg]").parent().parent().remove();
		$(".attributeImages img[src*=classic-burgundy.jpg]").parent().parent().remove();
		$(".attributeImages img[src*=classic-chocolate-blue.jpg]").parent().parent().remove();
		$(".attributeImages img[src*=classic-chocolate-green.jpg]").parent().parent().remove();
		$(".attributeImages img[src*=classic-chocolate-pink.jpg]").parent().parent().remove();
		$(".attributeImages img[src*=classic-grey.jpg]").parent().parent().remove();
		$(".attributeImages img[src*=classic-ivory.jpg]").parent().parent().remove();
		$(".attributeImages img[src*=classic-ivory-chocolate.jpg]").parent().parent().remove();
		$(".attributeImages img[src*=classic-latte.jpg]").parent().parent().remove();
		$(".attributeImages img[src*=classic-lemon.jpg]").parent().parent().remove();
		$(".attributeImages img[src*=classic-strawberry-chocolate.jpg]").parent().parent().remove();
		$(".attributeImages img[src*=classic-white.jpg]").parent().parent().remove();
		
		$("#selectcolor option[value=AquaBlue]").remove();
		$("#selectcolor option[value=Burgundy]").remove();
		$("#selectcolor option[value=ChocolateBlue]").remove();
		$("#selectcolor option[value=ChocolateGreen]").remove();
		$("#selectcolor option[value=ChocolatePink]").remove();
		$("#selectcolor option[value=Grey]").remove();
		$("#selectcolor option[value=Ivory]").remove();
		$("#selectcolor option[value=IvoryChocolate]").remove();
		$("#selectcolor option[value=Latte]").remove();
		$("#selectcolor option[value=Lemon]").remove();
		$("#selectcolor option[value=StrawberryChocolate]").remove();
		$("#selectcolor option[value=White]").remove();
		break;
	case "EB2136":
	case "EB2210G":
		// hide text input unless 'grad year' design is chosen
		$("#Text1").parent().parent().parent().hide();
		$("#Text2").parent().parent().parent().hide();
		$("#GradYear").parent().parent().parent().hide();
		$(".attributeLine:last .aNumber img").attr("src", "/images/misc/prod/numbers/3.png");
		$("#selectdesign").change(function(event){
			if ( $(this).val() == "classof" && $(this).data("classof") != "1" ) {
				$(this).data("classof","1");
				$("#Text1").addClass("required").parent().parent().parent().show("blind");
				$("#Text2").addClass("required").parent().parent().parent().show("blind");
				$("#GradYear").addClass("required").parent().parent().parent().show("blind");
				$(".attributeLine:last .aNumber img").attr("src", "/images/misc/prod/numbers/6.png");
			} else if ( $(this).val() != "classof" && $(this).data("classof") == "1" ) {
				$(this).data("classof","0");
				$("#Text1").removeClass("required").parent().parent().parent().hide();
				$("#Text2").removeClass("required").parent().parent().parent().hide();
				$("#GradYear").removeClass("required").parent().parent().parent().hide();
				$(".attributeLine:last .aNumber img").attr("src", "/images/misc/prod/numbers/3.png");
			}
		});
		//break deliberately omitted
	case "EB2210Y":
		// hide birthday text input unless 'grad year' design is chosen
		$("#Birthday").parent().parent().parent().hide();
		$(".attributeLine:last .aNumber img").attr("src", "/images/misc/prod/numbers/5.png");
		$("#selectdesign").change(function(event){
			if ( $(this).val() == "MilestoneBirthday" && $(this).data("MilestoneBirthday") != "1" ) {
				$(this).data("MilestoneBirthday","1");
				$("#Birthday").addClass("required").parent().parent().parent().show("blind");
				$(".attributeLine:last .aNumber img").attr("src", "/images/misc/prod/numbers/6.png");
			} else if ( $(this).val() != "MilestoneBirthday" && $(this).data("MilestoneBirthday") == "1" ) {
				$(this).data("MilestoneBirthday","0");
				$("#Birthday").removeClass("required").parent().parent().parent().hide();
				$(".attributeLine:last .aNumber img").attr("src", "/images/misc/prod/numbers/5.png");
			}
		});
		//break deliberately omitted
	case "EB2138":
		$(".attributeImages img[src*='/ivory.jpg']").parent().parent().remove();
		$(".attributeImages img[src*='/latte.jpg']").parent().parent().remove();
		$("#selectColor option[value='Ivory']").remove();
		$("#selectColor option[value='Latte']").remove();
		if ( prodID == "EB2138" ) {
			// http://dev.favorfavor.com/images/attributes/eventBlossom/tagsStickers/EB2138/ivory-chocolate.jpg
			$(".attributeImages img[src*='/white.jpg']").parent().parent().remove();
			$(".attributeImages img[src*='/ivory-chocolate.jpg']").parent().parent().remove();
			$(".attributeImages img[src*='/chocolate-pink.jpg']").parent().parent().remove();
			$(".attributeImages img[src*='/strawberry-chocolate.jpg']").parent().parent().remove();
			$(".attributeImages img[src*='/burgundy.jpg']").parent().parent().remove();
			$(".attributeImages img[src*='/grey.jpg']").parent().parent().remove();
			$(".attributeImages img[src*='/chocolate-blue.jpg']").parent().parent().remove();
			$(".attributeImages img[src*='/chocolate-green.jpg']").parent().parent().remove();
			$(".attributeImages img[src*='/aqua-blue.jpg']").parent().parent().remove();
			$(".attributeImages img[src*='/lemon.jpg']").parent().parent().remove();
			$("#selectColor option[value='White']").remove();
			$("#selectColor option[value='IvoryChocolate']").remove();
			$("#selectColor option[value='StrawberryChocolate']").remove();
			$("#selectColor option[value='Burgundy']").remove();
			$("#selectColor option[value='Grey']").remove();
			$("#selectColor option[value='ChocolateBlue']").remove();
			$("#selectColor option[value='ChocolateGreen']").remove();
			$("#selectColor option[value='AquaBlue']").remove();
			$("#selectColor option[value='Lemon']").remove();
		}
		break;
	case "4748":
	case "4747":
		// hide sticker option on certain items
		$("#selectTagType option").each(function(){
			if ( $(this).text() == "Stickers" ) {
				$(this).remove();
			}
		});
		break;
	case "Petals":
		$(".attributeLine input[type='text']").parents(".attributeLine").hide();
		$("#selectPrintColor").change(function(event){
			if ( $(this).val() != "" ) {
				if ( $(".attributeLine input[type='text']").parents(".attributeLine:hidden").length ) {
					$(".attributeLine input[type='text']").addClass("required").parents(".attributeLine").show("normal");
				}
			} else {
				if ( $(".attributeLine input[type='text']").parents(".attributeLine:visible").length ) {
					$(".attributeLine input[type='text']").removeClass("required").val("").parents(".attributeLine").hide();
				}
			}
		});
		break;
	case "amwed115":
		$("#Text2").parents(".attributeLine").hide();
		$("#selectWidth").change(function(event){
			if ( $(this).val() == "Wide5-8" ) {
				if ( $("#Text2").parents(".attributeLine:hidden").length ) {
					$("#Text2").addClass("required").parents(".attributeLine").show("normal");
				}
			} else {
				if ( $("#Text2").parents(".attributeLine:visible").length ) {
					$("#Text2").removeClass("required").val("").parents(".attributeLine").hide();
				}
			}
		});
		break;
	case "1519CC":
	case "1776CC":
	case "2070CC":
	case "B9161SCC":
	case "1188CC":
	case "3025CC":
		if ( prodID == "1519CC" || prodID == "B9161SCC" ) {
			$(".aNumber img[src='/images/misc/prod/numbers/3.png']").attr("src", "/images/misc/prod/numbers/2.png");
		} else if ( prodID == "1188CC" || prodID == "3025CC" ) {
			$(".aNumber img[src='/images/misc/prod/numbers/5.png']").attr("src", "/images/misc/prod/numbers/4.png");
		} else {
			$(".aNumber img[src='/images/misc/prod/numbers/4.png']").attr("src", "/images/misc/prod/numbers/3.png");
		}
		$("#Text").parent().parent().parent().hide();
		$("#Text1").parent().parent().parent().hide();
		$("#selectengravingType,#selectPersonalizationStyle").change(function(){
			if ( !$(this).data("textVisible") ) {
				$(this).data("textVisible","1");
				var effect = "blind";
			} else {
				var effect = "";
			}
			if ( $(this).val() == "Name" ) {
				$("#Text").val("").removeClass("required").parent().parent().parent().hide();
				$("#Text1").addClass("required").parent().parent().parent().show(effect);
			} else if ( $(this).val() != "" ) {
				$("#Text1").val("").removeClass("required").parent().parent().parent().hide();
				$("#Text").addClass("required").parent().parent().parent().show(effect);
			} else {
				$(this).data("textVisible","");
				$("#Text:visible").val("").removeClass("required").parent().parent().parent().hide("blind");
				$("#Text1:visible").val("").removeClass("required").parent().parent().parent().hide("blind");
			}
		});
		break;
		
		//break;
	case "1015LCC":
		$("#selectColor").prop( "disabled", true );
		break;
	/*case "":
		break;*/
	} // switch( prodID ) {
	/*********** END PRODUCT SPECIFIC ************/
	
	
	if ( $.getQueryString({id:"ela"}) == "1" || 1 ) {
		// equal length attributes
		// first get the longest one
		var longest = 0;
		$(".attributeLine input,.attributeLine select").not(":hidden").each( function(){
			if ( $(this).width() > longest ) {
				longest = $(this).width();
			}
		});
		$(".attributeLine input[type='text'],.attributeLine select").not(":hidden").width( longest );
	}
	
	
	/***************** mobile adjustments ************************/
	if ( typeof( window.mobileSite ) != "undefined" ) {
		// remove the write review link and the show all reviews link
		$("table.rHeading").remove();
		$("#viewAllReviews").remove();
		
	}
});














