/*
	version note [1.1] - PJR - 18/02/2010 - CaseID:10-12230 - Basket in top right of page not showing second part if order ends in two zeros
	version note [1.2] 24/05/2010  SHN  CR-2010-02-5584 Desc: Removal of Site folder and ULR changes for SEO /product/ will become /p/ and /category/ will become /c/ with .html in end
	version note [1.3] 01/03/2011  TJB  Opp [#31737] Extra "Buy me" button at the top of product page.	
*/	
		
		<!-- [2.31] Start - adding jQuery.ready()  --><!-- [2.40] Start -->
				jQuery(document).ready(function() {
					// ---- INI ---- //
						 // PNG FIX - using jQuery plugin to display PNG images in IE6
						 jQuery("#corner-animation-top").pngFix();
						 jQuery("#test").pngFix();

						 // get the default value from the sign up box
						var sSignUpDefault = jQuery("#newsletter-signup input#up_gi_email_address").attr("value")

						// Top Right Animation
						// check for cookie - if we hit the page for the 1st time (cookie is null) - change the container to flash and set the cookie
						// otherwise use just normal image
						// also test if we are on secure pages (https), if so, dont load the flash animation
						var pageURL = (window.location.href);
						var r = new RegExp('^https:', 'i');
						if (!jQuery.cookie("HasVisitedTheSite") && !(r.test(pageURL))){
							var sAnimationFilename = jQuery("input#corner-animation-top-filename").attr("value");
							jQuery('div#corner-animation-top[class=flash]').flash({
							    swf: '/public/cm/' + sAnimationFilename,
							    width: 196,
							    height: 133,
							    params: {
									 wmode: 'transparent'
								}
							});
							jQuery('div#corner-animation-top[class=flash]').css({zIndex:150});
							jQuery.cookie("HasVisitedTheSite", 'true', {path: '/'})
						} else {
							jQuery("#corner-image-top-filename").show();
						}

						// Category hero image - change it to flash if available
						jQuery('div#hero-img[class=flash]').flash({
						    swf: jQuery(this).find("input[name=filename]").attr("value"),
						    width: 914,
						    height: 185,
						    params: {
								 wmode: 'opaque'
							}
						});
						jQuery('div#hero-img[class=flash]').css({zIndex:0});

						 // overlay FIX - moving overlay windows to the front in DOM
						jQuery("#divCalendarContainer").each(function(){
							jQuery(this).prependTo("#page-container")
						});
						jQuery("#_oDropShadow").each(function(){
							jQuery(this).prependTo("body")
						});



					// ---- EVENTS ---- //
						// *** GWO links catching section :: START :: ***
							<!-- category - Sort ASC -->
							jQuery("#itemListHeader #sort-switch a.priceAsc").click(function() {
								pageTracker._trackPageview("/pages/category/SortByPrice-ascending");
							});
							<!-- category - Sort DESC -->
							jQuery("#itemListHeader #sort-switch a.priceDesc").click(function() {
								pageTracker._trackPageview("/pages/category/SortByPrice-descending");
							});
							<!-- category - show ALL records -->
							jQuery("#itemListHeader .pagination-box a[href$='viewall=true']").click(function() {
								pageTracker._trackPageview("/pages/category/viewAllProducts");
							});
						// *** GWO links catching section :: END :: ***


						 // click on the header basket icon redirects to basket page
						jQuery("#header-minibasket").click(function(){
							window.location.replace(jQuery(this).find("a").attr('href'));
						});


						// *** Newsletter Signup - START
						// ------------------------------

						 // clear the sign up box upon click
						jQuery("#newsletter-signup input#up_gi_email_address").click(function(){
							if(jQuery(this).attr("value")==sSignUpDefault){
								jQuery(this).attr("value","");
							}
						});

				         // bind the form with the plugin
//				        jQuery("#frmSubscribe").ajaxForm()

						 // catch the link for registered users - send the form
						jQuery("a#frmSubscribe_link").click(function(){
					        jQuery("#frmSubscribe").submit();
					        return false;
						});

						 // modify submit event to ajax
						jQuery("#frmSubscribe").submit(function(){
							 // if the email address exist and is valid
							if(jQuery(this).children("#up_gi_email_address").length > 0 && isValidEmailAddress(jQuery(this).children("#up_gi_email_address").attr('value'))) {
						        jQuery(this).ajaxSubmit({
						        	success: function(){
						        		// fade out the form
						        		jQuery("#frmSubscribe").fadeOut(100,function(){
						        			// fade in the confirmation box
						        			jQuery("#newsletter-signup-confirmation").fadeIn(1000);
						        		});
					        		}
					        	});
							} else {
								alert('Please provide a valid email address');
							}
				        	return false;
						});

			        	 // check email address for valid format
						function isValidEmailAddress(sEmail) {
							var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
							if (!filter.test(sEmail)) {
								return false;
							}
							return true;
						}

						// *** Newsletter Signup - END
						// ------------------------------



						<!-- catch the link for hiding Gift-confirmation overlay window -->
						jQuery("#oGiftConfirmColourMessage a.actionButton").click(function() {
							jQuery('#oGiftConfirmColourMessage').hide();
							return false;
						});

						 // catch the PRODUCT AddToBasket submit form and AJAX it instead
					    //jQuery(".addToBasketBox a[href][id^=form_]").click(function() {
					    jQuery("#productActionButtons .addToBasket_enabled a").click(function() {
					    	var prodID = jQuery(this).attr('rel');
					    	var sFormName = 'form_' + prodID;
					    	 // get the form object (use form NAME instead of ID which doesnt have to be present.. :(
					    	var jqForm = jQuery("form[name="+sFormName+"]")
					    	 // GWO tracking
					    	pageTracker._trackPageview("/addtobasket/product/" +prodID+ "/main");
					    	 // AJAX-submit the product form
					    	addToBasketAjax(jqForm);

					      	return false;
					    });
							//*** [1.3] Start:
					    jQuery("#productActionButtonsTop .addToBasket_enabled a").click(function() {
					    	var prodID = jQuery(this).attr('rel');
					    	var sFormName = 'form_' + prodID;
					    	 // get the form object (use form NAME instead of ID which doesnt have to be present.. :(
					    	var jqForm = jQuery("form[name="+sFormName+"]")
					    	 // GWO tracking
					    	pageTracker._trackPageview("/addtobasket/product/" +prodID+ "/main");
					    	 // AJAX-submit the product form
					    	addToBasketAjax(jqForm);
				      	return false;
					    });					   
						 	//*** Catch the product AddToBasket when NO Stock
					    jQuery("#productActionButtonsTop .addToBasket_disabled a").click(function() {
					      	return false;
					    });					     
					    //*** [1.3] End.
						 // catch the CATEGORY AddToBasket submit form and AJAX it instead
					    jQuery(".addToBasketBox a[href][id^=form_]").click(function() {
					    	 // get the form name from A link (rel attribute)
					    	var prodID = jQuery(this).attr('rel');
					    	var sFormName = 'form_' + prodID;
					    	 // get the form object (use form NAME instead of ID which doesnt have to be present.. :(
					    	var jqForm = jQuery("form[name="+sFormName+"]")
					    	 // GWO tracking
					    	pageTracker._trackPageview("/addtobasket/product/" +prodID+ "/subcategory");
					    	 // AJAX-submit the product form
					    	addToBasketAjax(jqForm);

					      	return false;
					    });

						 // catch the product AddToBasket when NO Stock
					    jQuery("#productActionButtons .addToBasket_disabled a").click(function() {
					      	return false;
					    });

						<!-- catch the Continue Shopping and Close window links - just hide the overlay window -->
						jQuery("#inBasketConfirmBox .actionButtons .continue a, #inBasketConfirmBox .x a").click(function() {
							jQuery('#inBasketConfirmBox').slideUp('slow')
							return false;
						});


					// ---- TOP PAGE NAVIGATION
					    // hovering the menu
					   jQuery("ul.topnav li:has(ul)").hover(
					      function () {
					        jQuery(this).find("ul.subnav:hidden").show();
					      },
					      function () {
					        jQuery(this).find("ul.subnav").slideUp('fast');
					      }
					    );
					     // last item's subitems fix - make the width of last item's subitems the same as the item itself
//					    jQuery("ul.topnav > li:last ul.subnav").each(function(){
//					    	var newWidth = jQuery("ul.topnav > li:last").width()
//					    	jQuery(this).css('width',newWidth);
//					    	jQuery(this).children().css('width',newWidth);
//					    	jQuery(this).find("a").css('width',newWidth);
//					    });

					     // background separator fix - for selected item hide the bg separator image from preceeding menu element
					    jQuery("ul.topnav li.selected").each(function(){
					    	jQuery(this).prev().find("a").css("backgroundImage", "none");
					    });

				});


				jQuery(window).load(function () {

 						 // category boxes height FIX
						jQuery("#itemList").each(function(){
							var currentTallest = 0;
							jQuery(this).children(".categoryItemBox").each(function(i){
								if (jQuery(this).height() > currentTallest) {
									currentTallest = jQuery(this).height();
								}
							});
							jQuery(this).children(".categoryItemBox").css({'height': currentTallest});
						});
				});


				// ---- OTHER functions

					 // ADD TO BASKET - AJAX - get the product form, AJAX it, display Ovelay window
				    function addToBasketAjax(jqForm) {
						 // extract server baseurl from the form action attribute
//						var regexp = 'https?:\/\/[_+a-zA-Z0-9.-]+'
//						jqForm.attr("action").match(searchvalue);
						var sUrl = '';
						sUrl += "/pages/basket/AJAX_AddToBasket.asp";
						 // and change it to point to a simplified AJAX addtobasket page
						jqForm.attr("action",sUrl);
						 // supress inner page redirection
						jqForm.children("input[name=redirect_on_ok]").attr("value","");
						 // remove serial field from Form if exists - so that I can send the form repeatedly
						jqForm.children("input[name=serial]").remove();
			        	jqForm.ajaxSubmit({
				        	success: function(data){
				        		if(data == "addedToBasket"){
					        		 // on callback - fetch the inBasketConfirmBox with product details
					        		jQuery("#inBasketConfirmBox .productInfo .name").text(jqForm.children("input[name=prodname]").attr("value"));
					        		jQuery("#inBasketConfirmBox .productInfo img").attr('src',('/public/pictures/products/basket/' + jqForm.children("input[name=image_filename]").attr("value")));

								if (jqForm.children("input[name=item_corporate_product]").length > 0)
								{
									jQuery("#inBasketConfirmBox #confirm_qty").text(jqForm.children("input[name=qty]").attr("value"));
									jQuery("#inBasketConfirmBox #confirm_totalcost").text(jqForm.children("input[name=item_corp_total_cost]").attr("value"));
								}

					        		// update the minibasket (in both Header-minibasket and inBasketConfirmBox)
//			        					alert( 'baskettotal==' + jQuery.cookie("baskettotal") + " || totalitemcount==" + jQuery.cookie("totalitemcount") );
					        		jQuery(".minibasket-content .totalitemcount").text(jQuery.cookie("totalitemcount"))
					        		 // get the currency symbol from the Total's parent (link's rel attribute)
					        		var currSymbol = jQuery(".minibasket-content span.baskettotal").parent("a").attr("rel")
					        		// [1.1] - parse the baskettotal to 2 decimal places
					        		jQuery(".minibasket-content .baskettotal").text(currSymbol + parseFloat(jQuery.cookie("baskettotal")).toFixed(2))

			   				    	 // show/hide inBasketConfirmBox
			   				    	jQuery('#inBasketConfirmBox').css('top', (jQuery(window).scrollTop()+40) + 'px');
							    	jQuery('#inBasketConfirmBox').hide().slideDown(500,function (){
							    		// disappear automaticaly after 10 sec
							      		var timer = self.setTimeout(function() {jQuery('#inBasketConfirmBox').slideUp('slow')}, 10000);
									});
				        		}
			        		}
			        	});
				    }

					 // move Ovelay window to be the 1st element in the page container, so that proper z-index can be applied
				    function displayInFront(sDiv, iLeft, iTop) {
						var jqDiv = jQuery("#"+sDiv);
							jqDiv.prependTo("#page-container").hide();
							jqDiv.css({'left':iLeft,'top':iTop});
							jqDiv.css({'opacity':'1','filter':'alpha(opacity=100)'}).fadeIn('slow');
				    }

				    // make all dropdowns on the page invisible - IE6 bug fix
				    function hideDropdowns(){
				    	jQuery("select").css('visibility','hidden');
				    }
				    // make all dropdowns on the page visible - IE6 bug fix
				    function showDropdowns(){
				    	jQuery("select").css('visibility','hidden');
				    }
		
			<!-- [2.31] End --><!-- [2.40] End -->
