// JavaScript Document

$(document).ready(function(){
	var currentProtocol = (("https:" == document.location.protocol) ? "https:" : "http:");
	pageTracker._trackEvent('Products', 'Product Viewed', prodID );
	
	// 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 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 );
			pageTracker._trackEvent('Products', '360 Flash Viewed', prodID );
		});
	}

	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 ( $(".reviewImage").length ) {

	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;
		});
	} //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 );
			pageTracker._trackEvent('Products', 'Extra Image Viewed', prodID );
		});*/
	}
	
	//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 );
			//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 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();
			pageTracker._trackEvent('Products', 'UPS Map Viewed', prodID );
			
			if ( !$("#MapPop").dialog( "option", "height" ) ) {
				$("#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 ( !$("#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) {
			event.preventDefault();
			if ( !$("#JQUIDialog").dialog( "option", "height" ) ) {
				//var HW = getHW( $(this).attr("href") );
				$("#JQUIDialog").dialog({
					bgiframe: true,
					width: 620,
					height: 500,
					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();
			/*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: 650,
					height: 500,
					modal: true
				}).load( $(this).attr("href") );
			}
		});
	} // if ( $("#showDesignsJQUI").length ) {
	
	// personalization designs JQUI
	if ( $("#showDesignsJQUI2").length || $(".showDesignsJQUI2").length ) {
		$("#showDesignsJQUI2,.showDesignsJQUI2").click(function(event) {
			event.preventDefault();
			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" );
			}
			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 = checkTags();
			//alert("done checking tag data, result = " + result);
			return result;
		});
		// 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();
			$("#waitListPop").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>" );
			}*/
		});
	}
	
	// show review submitted confirmation
	if ( $("#ReviewBoxPop").length ) {
		pageTracker._trackEvent('Products', 'Product Review Submitted', prodID );
		if ( !$("#ReviewBoxPop").dialog( "option", "height" ) ) {
			$("#ReviewBoxPop").dialog({
				bgiframe: true,
				height: 200,
				width: 200
			});
		} else {
			$("#ReviewBoxPop").dialog( "open" );
		}	
	} // if ( $("#ReviewBoxPop").length ) {
	
	$("#basketAdd").submit(function(){
		if ( $("#Quantity").val() == "1" && prodMin > 1 ) {
			$("#basketAdd input:text").each(function(i){
				if ( $(this).val() && isNaN($(this).val()) ) {
					$(this).val("SAMPLE");
				}
			});
		}
	});
	
	if ( $("#addToBasket").length ) {
		$("#addToBasket").click(function(event){						 
			try {
				//pageTracker._trackPageview("/mm5/merchant.mvc?Screen=BASKFromProd");
				pageTracker._trackPageview("/mm5/merchant.mvc?Screen=BASK");
			} catch(err) {
			}
		});
	}

	// validate quantity
	if ( $("#Quantity").length) {
		$("#basketAdd").validate({ errorClass: "alert", errorElement: "p" });
		$("#Quantity").rules("add", { negativeRange: [1,prodMin] });
		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;
					}
				}
			});
		}
	}

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