// 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
	// large images
	if ( $("#prodImage").length ) {
		// there is an enlarged image available
		$("#prodImage").click(function(event){
			event.preventDefault();
			try { _gaq.push(['_trackEvent', 'Products', 'Large Image Viewed', prodID ]); } catch (error) {}
			
			if ( dialogCreated( $("#largeImage") ) ) {
				$("#largeImage").dialog( "destroy" );
			}
			$("#largeImage").attr( "title", "Enlarged Image" ).dialog({
				bgiframe: true,
				height: 545,
				width: 675,
				modal: true
			}).load( $(this).attr("href") );
			
			return false;
		});
	}
	
	// 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 ) {
		// 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 ( 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 ( !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 ( !dialogCreated( $("#MapPop") ) ) {
				$("#MapPop").dialog({
					bgiframe: true,
					height: 500,
					width: 600,
					modal: true
				}).load( $(this).attr("href") );
			} else {
				$("#MapPop").dialog( "open" );
			}
			
			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 ( !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 ) {
		//$("body").append("<br><br><br><br><br><br>link spotted");
		$("#showDesignsJQUI,.showDesignsJQUI").click(function(event) {
			event.preventDefault();
			//$("body").append("<br><br><br><br><br><br>click detected");
			if ( !dialogCreated( $("#JQUIDialog") ) ) {
				//var HW = getHW( $(this).attr("href") );
				//alert("making dialog");
				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 - VERSION 2
	if ( $(".showDesignsJQUIv2").length ) {
		$(".showDesignsJQUIv2").click(function(event) {
			event.preventDefault();
			//$("body").append("<br><br><br><br><br><br><br><br>working");
			/*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: 650,
					height: 500,
					modal: true
				}).load( $(this).attr("href"), function( responseText, textStatus, XMLHttpRequest){
					uniformSizes( $(".attributeImages") );
				}).data( "currentURL", $(this).attr("href") );
				//$("body").append("<br><br><br><br><br><br><br><br>done");
			}
		});
	} // if ( $("#showDesignsJQUI").length ) {

	// personalization designs JQUI
	if ( $("#showDesignsJQUI2").length || $(".showDesignsJQUI2").length ) {
		$("#showDesignsJQUI2,.showDesignsJQUI2").click(function(event) {
			event.preventDefault();
			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 ) {


	// 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);
		});
	}
	
	//personalized tags - FC
	if ( $("#AddPersTags").length ) {
		// there are personalized tags from FC, or there are matching tags by KA
		
		/*$("#basketAdd").submit( function() {
			//alert("checking tag data");
			var result = checkTagsJQ();
			//result = false;
			//alert("done checking tag data, result = " + result);
			return result;
		});*/
		
		var tagVersion = 2;
		if ( tagVersion == 1 ) {
			/* this is the old version where tag options are surrounded by a div */
			// show tag details
			$("#AddPersTags").click(function(event){
				clearTags();
				jqToggleLayer( "persTagsBox", null, 0 );
				//jqSlideLayer( "persTagsBox", "slow", 0 );
				try { _gaq.push(['_trackEvent', 'Products', 'Tag Details Viewed', prodID ]); } catch (error) {}
			});
		} else {
			/* new version, tag options are not surrounded by a div */
			
			$("#selectPersTags,#selectShapeColor,#selectTagType,#Names,#Date").parents(".attributeLine").hide();
			$("#selecttextLines23Color,#selecttextLine1Color,#selectfontStyle,#selectdesign,#selectpatternColor,#selectPattern,#selectborderColor,#selectbackgroundColor,#selectLayout").parents(".attributeLine").hide();
			
			//var tagType = $.getQueryString({id:"dyoTags", defaultvalue:""}) != "" ? "dyo" : "default";
			var tagType = "dyo";
			
			if ( tagType == "dyo" ) {
				$(".fashioncraftLabelsLink").next(".attrC").remove();
			}
			
			$("#AddPersTags").data({
				"optionsVisible" : "0",
				"tagType" : tagType
			});
			
			
			
			$("#AddPersTags").click(function(event){
				clearTags();
				//jqToggleLayer( "persTagsBox", null, 0 );
				//jqSlideLayer( "persTagsBox", "slow", 0 );
				// unhide each option
				if ( $("#AddPersTags").data("optionsVisible") == "0" ) {
					if ( $("#AddPersTags").data("tagType") == "default" ) {
						$("#selectPersTags,#selectShapeColor,#selectTagType,#Names,#Date").addClass("required").parents(".attributeLine").show("blind", 200);
					} else {
						$("#selectLayout").parents(".attributeLine").show("blind", 200);
						$("#selecttextLines23Color,#selecttextLine1Color,#selectfontStyle,#selectdesign,#selectpatternColor,#selectPattern,#selectborderColor,#selectbackgroundColor,#selectLayout").addClass("required");
					}
					$("#AddPersTags").data("optionsVisible","1");
					
					$("#Quantity").rules("add", {
						/*negativeRange: [1,prodMin],*/
						min : prodMin,
						messages: {
							min: "Tags may only be ordered with this item if you are purchasing " + prodMin + " or more. You are ordering " + $("#Quantity").val()
						}
					});
					
				} else {
					if ( $("#AddPersTags").data("tagType") == "default" ) {
						$("#selectPersTags,#selectShapeColor,#selectTagType,#Names,#Date").removeClass("required").parents(".attributeLine").hide("blind", 200);
					} else {
						$("#selectLayout").parents(".attributeLine").hide("blind", 200);
						$("#selecttextLines23Color,#selecttextLine1Color,#selectfontStyle,#selectdesign,#selectpatternColor,#selectPattern,#selectborderColor,#selectbackgroundColor,#selectLayout").removeClass("required");
					}
					$("#AddPersTags").data("optionsVisible","0");
					
					$("#Quantity").rules("remove", "min" );
				}
				
				try { _gaq.push(['_trackEvent', 'Products', 'Tag Details Viewed', prodID ]); } catch (error) {}
			});
			
			
		}
	} // if ( $("#AddPersTags").length ) {
	
	if ( $("#ReviewBoxPop").length ) {
		// a review has been submitted
		$("#reviewReceived").click(function(event){
			jqToggleLayer( "ReviewBoxPop", null, 0 );
		});
	}
	
	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){
			$(".moreReviews").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>" );
			}
		});
	}
	
	// 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 ( !dialogCreated( $("#ReviewBoxPop") ) ) {
			$("#ReviewBoxPop").dialog({
				bgiframe: true,
				height: 125,
				width: 220
			});
		} else {
			$("#ReviewBoxPop").dialog( "open" );
		}	
	} // if ( $("#ReviewBoxPop").length ) {

	// validate quantity
	if ( $("#Quantity").length) {
		$("#basketAdd").validate({ errorClass: "alert", errorElement: "p" });
		
		if ( window.prodMin && ( window.enforceMin || window.blockSamples ) ) {
			$("#Quantity").rules("add", { negativeRange: [1,prodMin] });
		}
		
		if ( !window.blockSamples ) {
			
			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%");
				//$("input[src='/mm5/graphics/en-US/new/add-to-basket.png']").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>");
			}
			rolloverLink( $("#orderSample img"), "/images/buttons/orderSample-off.png", "/images/buttons/orderSample-over.png", "/images/buttons/orderSample-down.png" );
			$("#orderSample").click(function(event){
				event.preventDefault();
				if ( !dialogCreated( $("#sampleConfirm") ) ) {
					$("body").append("<div title=\"Order a Sample\" id=\"sampleConfirm\" class=\"hideMe\"><p class=\"nomarg\">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 {
			$("#Quantity").rules("add", { min: prodMin });
			//$("#orderSample").hide(); // this shouldn't exist, miva hides it
		}
		
		
		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 ) { $("body").append("<br>prodMin = true" ); } else { $("body").append("<br>prodMin = false" ); }
			//if ( $("#Quantity").val() == "1" ) { $("body").append("<br>Quantity = true" ); } else {  $("body").append("<br>Quantity = false" ); }
			//$("body").append("<br>blockSamples = " + !blockSamples );
			//if ( Number($("#prodAttributes p.hideMe input[name='Product_Attribute_Count']").val()) >= 1 ) { $("body").append("<br>pAttributes = true" ); } else { $("body").append("<br>pAttributes = false" ); }
			
			if ( prodMin > 1 && $("#Quantity").val() == "1" && !blockSamples && $("#prodAttributes 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 ( $("#Quantity").length) {

	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 ( !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 ( 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 ( $(".tooltipImage").length ) {
		$(".tooltipImage").tooltip({
			delay: 0,
			showURL: false,
			bodyHandler: function(){
				//alert( this.src );
				//alert( "width: " + this.width + "\r\nheight: " + this.height + "\r\nsrc:" + this.src + "\r\nclass: " + this.class + "\r\ntitle: " + this.title + "\r\nid: " + this.id);
				//alert( this.title );
				//var src = this.src.replace( /\-th/, "" );
				//alert( $(this).attr("title") );
				//alert( src );
				return $("<img/>").attr("src",this.id);
				//return "hi";
			}
		});	
	}
	
	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 });
	}

	// glassware artwork
	if ( $("#showCustArt").length ) {
		// there is an enlarged image available
		$("#showCustArt").click(function(event){
			event.preventDefault();
			try { _gaq.push(['_trackEvent', 'Products', 'Glassware Custom Art Info Viewed', prodID ]); } catch (error) {}
			if ( dialogCreated( $("#custArtPop") ) ) {
				$("#custArtPop").dialog( "open" );
			} else {
				$("#custArtPop").dialog({
					bgiframe: true,
					height: 300,
					width: 400
				});
			}
			
			return false;
		});
	}

	if ( $("#shipsOnOrAbout").length ) {
		$("#shipsOnOrAbout").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 ) {
			
				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 ) {
			// 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("|");
				if ( $("#prodInfoDescription ul").length ) {
					//$("body").append("<br>... appending");
					$("#prodInfoDescription ul").append(data[0]);
				} else {
					//$("body").append("<br>... prepending");
					$("#prodInfoDescription").prepend("<ul>" + data[0] + "</ul>");
				}
				$("#prodInfoDescription").append(data[1]);
		
				if ( $("#custArtLink").length ) {
					$("#custArtLink").click(function(event){
						event.preventDefault();
						try { _gaq.push(['_trackEvent', 'Products', 'Glassware Custom Art Info Viewed', prodID ]); } catch (error) {}
						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 ( $("#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 ) {
	
	// prod page
	if ( $("#basketAdd a img").parent().next("b:contains(:)").length ) {
		$("#basketAdd a img").parent().next("b:contains(:)").hide();
	}
	if ( $("#basketAdd img").next("b:contains(:)").length ) {
		$("#basketAdd img").next("b:contains(:)").hide();
	}
	if ( $.trim($("#basketAdd .ui-icon").parent().parent().next().html()) == ":" ) {
		$("#basketAdd .ui-icon").parent().parent().next().hide();
	}
	// patr page
	if ( $("#missingProdAttributes").length ) {
		if ( $("#missingProdAttributes a img").parent().next().html() == ":" ) {
			$("#missingProdAttributes a img").parent().next().hide();
		}
	}
	
	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 above 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();
		
		$("input[src='/mm5/graphics/en-US/new/add-to-basket.png']").attr("src", "/images/buttons/personalize.png");
		
		$("input[src='/images/buttons/personalize.png']").click(function(event){
			event.preventDefault();
			//$("body").append("<br>click detected");
			$("#chooseSeparateOptions").click();
			return false;
		});
		$("#chooseSeparateOptions").button().click(function(event){
			event.preventDefault();
			//$("body").append("<br>click detected");
			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;'></label><br><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().addClass("posRel");
				
				
				/* for some reason on NPF the dialog is moved much lower than it should be
				* it seems to have something to do with appendTo("#basketAdd")
				* let's figure out where it should be and reset the 'top' property
				*/
				//$("body").append("<br><br><br><br><br><br><br><br><br>working");
				//$("#pAttributes").parent().css("top",newTop + "px");
				/*var dialogHeight = $("#pAttributes").parent().height();
				var windowHeight = $(window).height();
				var availableSpace = windowHeight - dialogHeight;
				newTop = availableSpace > 0 ? availableSpace / 2 : 0;
				$("body").append("<br>dialogHeight = " + dialogHeight);
				$("body").append("<br>windowHeight = " + windowHeight);
				$("body").append("<br>availableSpace = " + availableSpace);
				$("body").append("<br>newTop = " + newTop);
				newTop += $(document).scrollTop();
				$("body").append("<br>newTop = " + newTop);*/
				
				var correctPosition = $("#pAttributes").parent().position();
				//$("body").append("<br>correctPosition = " + correctPosition.top);
				correctPosition.top -= 380;
				$("#pAttributes").parent().appendTo("#basketAdd").css("top",correctPosition.top + "px");
				$(".attributeLine:not(:first) td").css("border-top","2px solid rgb( 217,214,196 )");
				//$("body").append("<br>working");
				
				
				
				$("#chooseSeparateOptionsQty").keyup(function(event){
					$("#Quantity").val($(this).val());
					$(".optionCountMax").text($(this).val());
					$(".optionCountRemaining").text($(this).val());
				}).val( $("#Quantity").val() );
				$(".attributeLine").wrapAll("<div id=\"chooseSeparateOptionsContainer\"><table></table></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+20,
					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();
						disableFormElements( $("#basketAdd") );
						
						var postTo = $("#basketAdd").attr("action");
						//alert("adding to basket \r\n" + formData);
						$.post( postTo, formData, function( data, status, jqXHR ) {
							$("#chooseSeparateOptionsLoad").hide();
							//alert(status);
							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 );
									}
								} 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");
			}
			return false;
		});
	} else { // if ( offerSeparateOptions ) {
		//$("body").append("<br>NOT offering separate options");
	} // if ( offerSeparateOptions ) {
	
	// orderSample handling
	
	$("#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")));
				}
			});
		}
	});
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	/*********** 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 "EB2136":
	case "EB2210G":
		// remove latte and ivory options
		//$("body").append("<br><br><br><br><br>found eb2136");
		$(".attributeImages img[src*='classic-latte.jpg']").parent().parent().remove();
		$(".attributeImages img[src*='classic-ivory.jpg']").parent().parent().remove();
		$("#selectcolor option[value='Latte']").remove();
		$("#selectcolor option[value='Ivory']").remove();
		// hide text input unless 'grad year' design is chosen
		$("#Text1").parent().parent().hide();
		$("#Text2").parent().parent().hide();
		$("#GradYear").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().show("blind");
				$("#Text2").addClass("required").parent().parent().show("blind");
				$("#GradYear").addClass("required").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().hide();
				$("#Text2").removeClass("required").parent().parent().hide();
				$("#GradYear").removeClass("required").parent().parent().hide();
				//$(".attributeLine:last .aNumber img").attr("src", "/images/misc/prod/numbers/3.png");
			}
		});
		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 "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().hide();
		$("#Text1").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().hide();
				$("#Text1").addClass("required").parent().parent().show(effect);
			} else if ( $(this).val() != "" ) {
				$("#Text1").val("").removeClass("required").parent().parent().hide();
				$("#Text").addClass("required").parent().parent().show(effect);
			} else {
				$(this).data("textVisible","");
				$("#Text:visible").val("").removeClass("required").parent().parent().hide("blind");
				$("#Text1:visible").val("").removeClass("required").parent().parent().hide("blind");
			}
		});
		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 );
	}
	
});
