// 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 {
		pageTracker._trackEvent('Products', 'Product Viewed', prodID );
	} catch (error) { /* do nothing */ }
	
	// test item 5364
	// large images
	if ( $("#prodImage").length ) {
		// there is an enlarged image available
		$("#prodImage").click(function(event){
			event.preventDefault();
			pageTracker._trackEvent('Products', 'Large Image Viewed', prodID );
			
			if ( $("#largeImage").dialog( "option", "height" ) ) {
				$("#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 a flash image available
		$("#flash360").click(function(event){
			event.preventDefault();
			pageTracker._trackEvent('Products', '360 Flash Viewed', prodID );
			
			if ( $("#largeImage").dialog( "option", "height" ) ) {
				$("#largeImage").dialog( "destroy" );
			}
			$("#largeImage").attr( "title", "360 Degree View" ).dialog({
				bgiframe: true,
				height: 545,
				width: 675,
				modal: true
			}).load( $(this).attr("href") );
			
			return false;
		});
	}

	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();
			pageTracker._trackEvent('Products', 'Review Image Viewed', prodID );
			if ( $("#reviewImages").dialog( "option", "height" ) ) {
				$("#reviewImages").dialog( "destroy" );
			}
			$("#reviewImages").dialog({
				bgiframe: true,
				height: 500,
				width: 600,
				modal: true
			}).load( $(this).attr("href") );
			return false;
		});
	}

	if ( $("#viewAllReviews").length ) {
		$("#viewAllReviews").click(function(event){
			event.preventDefault();
			pageTracker._trackEvent('Products', 'All Reviews Viewed', prodID );
			if ( !$("#allReviewsDialog").dialog( "option", "height" ) ) {
				$("#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;
		});
	}
	
	
	
	// 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.js" );
	}
	
	// additional images (using greybox)
	if ( $(".greybox").length ) {
		// there are extra images available
		$("head").append("<link rel=\"stylesheet\" href=\"/includes/greybox/greybox.css\" type=\"text/css\">");
		var GB_ROOT_DIR = "/includes/greybox/";
		
		$.getScript( "/includes/greybox/AJS.js" );
		$.getScript( "/includes/greybox/greybox.js" );
		
		
		/*var GB_ANIMATION = true;
		$(document).ready(function(){
			$("a.greybox").click(function(){
				event.preventDefault();
				var t = this.title;
				if ( !t ) { t = this.href; }
				GB_show(t,this.href,470,600);
				return false;
			});
		});*/
	}
	
	//transit time
	if ( $("#transitTimeShow").length ) {
		// there is a transit time calculator available
		$("#transitTimeShow").click(function(event){
			event.preventDefault();
			jqSlideLayer( "transitTimePop", "fast", 0 );
			pageTracker._trackEvent('Products', 'Transit Estimator Form Viewed', prodID );
		});
		
		$("#transitTimePopClose").click(function(event){
			jqSlideLayer( "transitTimePop", "fast", 0 );
		});
		
		$("#to").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 );
			//pageTracker._trackEvent('Prod Page', 'Transit Time Calculator Used' );
			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 isGlasswareVal = $.getQueryString({id:"isGlassware",theURL: theIncURL});
			var weightVal = $.getQueryString({id:"weight",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 + "//www.favorfavorbaby.com/pscripts/UPS/timeInTransit.php";
			$.post( thePostURL, {
				   to: theShipZip,
				   from: theFromZip,
				   availability: theAvailability,
				   tags: pTags,
				   isGlassware: isGlasswareVal,
				   weight: weightVal,
				   jQSubmit: "1"
				   },
				   function(returnData){
						$("#transitTimeResults").html( returnData );
						jqToggleLayer( "transitTimeLoading", "fast", 0 );
				   });
			pageTracker._trackEvent('Products', 'Transit Estimator Used', prodID );
			/*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();
			pageTracker._trackEvent('Products', 'UPS Map Viewed', prodID );
			
			if ( !$("#MapPop").dialog( "option", "height" ) ) {
				$("#MapPop").dialog({
					bgiframe: true,
					height: 500,
					width: 575,
					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 ( !$("#wishListDescription").dialog( "option", "height" ) ) {
						$("#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) {
			if ( !$("#JQUIDialog").dialog( "option", "height" ) ) {
				//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" );
			}
		});
	} // if ( $("#showDesignsJQUI").length ) {
		
	/* FC Personalized Tags */
	if ( $(".popLink").length ) {
		// bind the links in coffee-favors with their behaviors below
		$(".popLink").click( function(event) {
			event.preventDefault();
			if ( !$("#attInfo").dialog( "option", "height" ) ) {
				$("#attInfo").load( $(this).attr("href"), function(){
					$("#attInfo").dialog({
						bgiframe: true,
						width: 525,
						height: 440,
						modal: true
					});
				});
			} else {
				$("#attInfo").load( $(this).attr("href"), function(){
					$("#attInfo").dialog( "open" );
				});
			}
		});
	} // if ( $(".popLink").length ) {

	// 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
				$("#JQUIDialogv2").attr({ title: $(this).attr("title") }).dialog("open").load( $(this).attr("href") );
			} else {
				$("body").append("<div id=\"JQUIDialogv2\"></div>");
				$("#JQUIDialogv2").attr({ title: $(this).attr("title") }).dialog({
					bgiframe: true,
					width: 620,
					height: 500,
					modal: true
				}).load( $(this).attr("href") );
			}
		});
	} // if ( $("#showDesignsJQUI").length ) {

	// personalization designs JQUI
	if ( $("#showDesignsJQUI2").length ) {
		$("#showDesignsJQUI2").click(function(event) {
			if ( !$("#JQUIDialog2").dialog( "option", "height" ) ) {
				//var HW = getHW( $(this).attr("href") );
				$("#JQUIDialog2").dialog({
					bgiframe: true,
					width: 600,
					height: 500,
					modal: true
				});
			} else {
				$("#JQUIDialog2").dialog( "open" );
			}
		});
	} // 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);
		});
	}
	
	//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() {
			return checkTags();
		});
		// show tag details
		$("#AddPersTags").click(function(event){
			clearTags();
			jqToggleLayer( "persTagsBox", null, 0 );
			//jqSlideLayer( "persTagsBox", "slow", 0 );
			pageTracker._trackEvent('Products', 'Tag Details Viewed', prodID);
		});
	}
	
	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>" ) {
				pageTracker._trackEvent('Products', 'More Reviews Viewed', prodID);
				$("#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();
			if ( !$("#waitListPop").dialog( "option", "height" ) ) {
				//var HW = getHW( $(this).attr("href") );
				$("#waitListPop").dialog({
					bgiframe: true,
					width: 450,
					height: 250,
					modal: true
				});
			} else {
				$("#waitListPop").dialog( "open" );
			}
			pageTracker._trackEvent('Products', 'Wait List Signup Viewed', prodID);
		});
		$("#Your_Email").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
				$("#waitListSubmit").click();
				event.preventDefault();
				return false;
			} else {
				return true;
			}
		});
		$("#waitListSubmit").click(function(event){
			event.preventDefault();
			$(".loading").slideToggle("fast");
			var theURL = "http://www.favorfavorbaby.com/pscripts/waitlist.php";
			/*theURL += "Your_Email=" + escape( $("#Your_Email").val() );
			theURL += "&Product_Code=" + escape( $("#Product_Code").val() );
			theURL += "&Screen=PROD";
			theURL += "&SubScreen=CTWLSEND";
			theURL += "&Store_Code=FFB";*/
			// we have to append a random # to the URL to prevent caching
			$.get( theURL, {
			   email: $("#Your_Email").val(),
			   code: $("#Product_Code").val(),
			   rand: Math.floor(Math.random()*99999999999)
			   },
			   function(returnData){
					$(".loading").slideToggle("fast");
					if ( returnData == "1" ) {
						$("#waitListResults").addClass("success").removeClass("alert").html("<br>Thank you, we will be glad to notify you as soon as this item is back in stock.");
						pageTracker._trackEvent('Products', 'Wait List Signup Success', prodID);
					} else {
						$("#waitListResults").addClass("alert").removeClass("success").html("<br>There was an error submitting your request. Please <a href=\"http://www.favorfavorbaby.com/c-contact-us.htm\">contact us</a> to be added to the signup list.");
						pageTracker._trackEvent('Products', 'Wait List Signup Failure', prodID);
					}
				   //$("#waitListResults").html(returnData);
				   $("#waitListResults").show("fast");
				   //alert( returnData );
			   });
		});

	} // wait list signup
	

	$("#basketAdd").submit(function(){
		if ( $("#Quantity").val() == "1" && prodMin > 1 ) {
			$("#basketAdd input:text").each(function(i){
				if ( $(this).val() && isNaN($(this).val()) ) {
					$(this).val("SAMPLE");
				}
			});
		}
	});

	// validate quantity
	if ( $("#Quantity").length) {
		$("#basketAdd").validate({
			errorClass: "alert",
			errorElement: "p"/*,
			submitHandler: function(form){
				if ( $("#Quantity").val() == "1" ) {
					$("input").each( function( index, item ) {
						if ( $(this).attr("type") == "text" && $(this).val() && $(this).attr("id") != "Quantity" ) {
							$(this).val("sample");
						}
					});
				}
				$("#basketAdd").submit();
			}*/
		});
		$("#Quantity").rules("add", { negativeRange: [1,prodMin] });
	}
	
	/* this works but is not in use. see http://www.favorfavorbaby.com/test/jq/9401.htm */
	if ( $(".pub").length) {
		$(".pub").click(function(event){
			event.preventDefault();
			var theContentURL = $(this).attr("href");
			var whatToRequest = jqMakePUBURL( currentProtocol, theContentURL );
			var theAnchor = $(this);
			$.get( whatToRequest, function(data){
				// use the query string to get the ID of the layer we're going to load
				// we'll also make that id visible
				//alert(data);
				//alert( theAnchor.attr("href") );
				theAnchor.after( data );
				jqSlideLayer( "largeImage", "slow", 0 );
			});
		});
	} // if ( $(".pub").length) {
	
	
	

	
	// exit surveys
	/*if ( prodID == "test" ) {
		var exit = true;
		$("a").bind("click", function(){ exit = false; });
		$("form").bind("submit", function(){ exit = false; });
		$(window).bind("unload", function(){
							if ( exit ) {
								var surveyURL = "http://www.favorfavorbaby.com/includes/surveys/supplies.php";
								var height = "550";
								var width = "450";
								var windowName = "FavorFavorExitSurvey";
								var settings = "toolbar=0,directories=0,menubar=0,scrollbars=1,resizable=1,width="+width+",height="+height;
								window.open( surveyURL, windowName, settings );
							}
		});
	}*/
	


	if ( $("#prodCreateAccount").length ) {
		$("#prodCreateAccount").click(function(event){
			event.preventDefault();
			$.getScript( '/jscripts/acad.js' );
			if ( !$("#createAccountDialog").dialog( "option", "height" ) ) {
				$("#createAccountDialog").load( "/includes/ajax/acad.php", function(){
					$(document).ready(function(){
						pageTracker._trackEvent('Products', 'Save Basket: Info Viewed', prodID );
						$("#accountCreate").validate({
							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_ShipLastName: {
									required: {
										depends: function(element) {
											return $("#addressInfo:checked").length;
										}
									}
								},
								Customer_ShipEmail: {
									required: {
										depends: function(element) {
											return $("#addressInfo:checked").length;
										}
									}
								},
								Customer_ShipPhone: {
									required: {
										depends: function(element) {
											return $("#addressInfo:checked").length;
										}
									},
       								minlength: 7,
      								digits: true
								},
								Customer_ShipAddress: {
									required: {
										depends: function(element) {
											return $("#addressInfo:checked").length;
										}
									}
								},
								Customer_ShipCity: {
									required: {
										depends: function(element) {
											return $("#addressInfo:checked").length;
										}
									}
								},
								Customer_ShipStateSelect: {
									required: {
										depends: function(element) {
											return $("#addressInfo:checked").length;
										}
									}
								},
								Customer_ShipZip: {
									required: {
										depends: function(element) {
											return $("#addressInfo:checked").length;
										}
									},
       								minlength: 5,
      								digits: true
								},
								Customer_ShipCountry: {
									required: {
										depends: function(element) {
											return $("#addressInfo:checked").length;
										}
									}
								},
								Customer_BillFirstName: {
									required: {
										depends: function(element) {
											return $("#differentBilling:checked").length;
										}
									}
								},
								Customer_BillLastName: {
									required: {
										depends: function(element) {
											return $("#differentBilling:checked").length;
										}
									}
								},
								Customer_BillEmail: {
									required: {
										depends: function(element) {
											return $("#differentBilling:checked").length;
										}
									},
									email: true
								},
								Customer_BillPhone: {
									required: {
										depends: function(element) {
											return $("#differentBilling:checked").length;
										}
									},
       								minlength: 7,
      								digits: true
								},
								Customer_BillAddress: {
									required: {
										depends: function(element) {
											return $("#differentBilling:checked").length;
										}
									}
								},
								Customer_BillCity: {
									required: {
										depends: function(element) {
											return $("#differentBilling:checked").length;
										}
									}
								},
								Customer_BillStateSelect: {
									required: {
										depends: function(element) {
											return $("#differentBilling:checked").length;
										}
									}
								},
								Customer_BillZip: {
									required: {
										depends: function(element) {
											return $("#differentBilling:checked").length;
										}
									},
       								minlength: 5,
      								digits: true
								},
								Customer_BillCountry: {
									required: {
										depends: function(element) {
											return $("#differentBilling:checked").length;
										}
									}
								}
							
							}
						});
						$("#createAccount").click(function(event){
							event.preventDefault();
							if ( $("#accountCreate").valid() ) {
								pageTracker._trackEvent('Products', 'Save Basket: Account Created, Item Added', prodID );
								createAccount( sessionID, "prod" );
							}
							return false;
						});
						
						$("#accountLogin").validate({
							rules: {
								accountLoginCustomer_Login: "required",
								accountLoginCustomer_Password: "required"
							}
						});
						$("#loginAccount").click(function(event){
							event.preventDefault();
							if ( $("#accountLogin").valid() ) {
								pageTracker._trackEvent('Products', 'Save Basket: Logged In, Item Added', prodID );
								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" ) ) {
										$("#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( '/jscripts/acad.js' );
		$("#prodAddWishList").click(function(event){
			event.preventDefault();
			pageTracker._trackEvent('Products', 'Save Basket: Item Added', prodID );
			saveBasket( '', sessionID, "prod", "loggedIn" );
			return false;
		});
		
	}
	
	// show review submitted confirmation
	if ( $("#ReviewBoxPop").length ) {
		pageTracker._trackEvent('Products', 'Product Review Submitted', '&mvt:global:product_code;' );
		if ( !$("#ReviewBoxPop").dialog( "option", "height" ) ) {
			$("#ReviewBoxPop").dialog({
				bgiframe: true,
				height: 200,
				width: 200
			});
		} else {
			$("#ReviewBoxPop").dialog( "open" );
		}	
	} // if ( $("#ReviewBoxPop").length ) {

	// glassware artwork
	if ( $("#showGlassCustomArt").length ) {
		// there is an enlarged image available
		$("#showGlassCustomArt").click(function(event){
			event.preventDefault();
			pageTracker._trackEvent('Products', 'Glassware Custom Art Info Viewed', prodID );
			
			if ( $("#glassCustomArt").dialog( "option", "height" ) ) {
				$("#glassCustomArt").dialog( "open" );
			} else {
				$("#glassCustomArt").dialog({
					bgiframe: true,
					height: 300,
					width: 400
				});
			}
			
			return false;
		});
	}

	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' });
	}*/
	
	// hide sticker option on certain items
	if ( prodID == "4748" || prodID == "4747" ) {
		$("#selectTagType option").each(function(){
			if ( $(this).text() == "Stickers (+0.28)" ) {
				$(this).remove();
			}
		});
	}
	
	if ( $("#chocolateShippingNotes").length ) {
		if ( Date().getMonth > 2 && Date().getMonth < 10 ) { // between march and october
			var selectedTab = 0;
		} else {
			var selectedTab = 1;
		}
		$("#chocolateShippingNotes").tabs({ selected: selectedTab });
	}

	if ( $("#selectletterCount").length && $("#babyName").length ) {
		// this is a kara nessian diaper cake with option for wooden letters showing baby name
		// rather than make visitors count the letters and choose from menu, lets
		// count the letters and fill out the menu for them.
		$("#selectletterCount").parent().parent().parent().parent().hide();
		$("#babyName").keyup(function(){
			$("#selectletterCount").val( $(this).val().length );
			//$("body").append("<br>I set the value to '" + $(this).val().length + "'");
		});
	}




});