		function recSelectColour(a, colour_ID) { 
			if (a.style.width=="25px") {					
				a.style.width = "23px";
				a.style.height = "23px";
				a.style.border = "2px solid #fff";
				a.style.background = "url('includes/z-dhtml/color/currency_white_arrow.gif') no-repeat 8px 18px";
				$("colours").value += "|" + colour_ID + "|";
			} else {
				a.style.width = "25px";
				a.style.height = "25px";
				a.style.border = "1px solid #fff";
				a.style.background = "";
				$("colours").value = $("colours").value.replace("|" + colour_ID + "|", "");
			}						
		}
		function getColoursWidth() {
			//return ( ( (parseInt($("rec_Colours_Total").value)*(27+2)+0) / 3 ) + 2 );
			return 158;
		}
		function getColoursHeight() {
			return parseInt(Math.ceil($("rec_Colours_Total").value / 5) * (27+2)) - 2;
		}
		function toggleColours() {
			if (parseInt($("recBG").style.height) > 27) {
			//if (parseInt($("recBG").style.width) > 158) {
				contractColours();				
			} else {
				expandColours();
			}
		}
		function expandColours() {
			//if (getColoursWidth()<=158) { return false; } // Dont bother
			window.clearTimeout(colorsTimeout);
			$("recControlImg").src = "includes/z-dhtml/color/lp_arrow_up.gif";
			$("recControlImg").alt = "Hide All Colours";
			var myAnim1 = new YAHOO.util.Anim('recBG', { width: { to: getColoursWidth() }, height: { to: getColoursHeight() }, opacity: { to: 0.75 } }, 0.5, YAHOO.util.Easing.easeOut);
			var myAnim2 = new YAHOO.util.Anim('recBlocks', { width: { to: getColoursWidth() }, height: { to: getColoursHeight() } }, 0.5, YAHOO.util.Easing.easeOut);
			//var myAnim3 = new YAHOO.util.Anim('recControl', { left: { to: (getColoursWidth()+2) } }, 0.5, YAHOO.util.Easing.easeOut);
			myAnim1.animate(); myAnim2.animate(); //myAnim3.animate(); 
		}
		function contractColours() {
			window.clearTimeout(colorsTimeout);
			//swatchHide();
			$("recControlImg").src = "includes/z-dhtml/color/lp_arrow_down.gif";
			$("recControlImg").alt = "Show All Colours";
			var myAnim1 = new YAHOO.util.Anim('recBG', { width: { to: 158 }, height: { to: 27 }, opacity: { to: 0.2 } }, 0.5, YAHOO.util.Easing.easeOut);
			var myAnim2 = new YAHOO.util.Anim('recBlocks', { width: { to: 158 }, height: { to: 27 } }, 0.5, YAHOO.util.Easing.easeOut);
			//var myAnim3 = new YAHOO.util.Anim('recControl', { left: { to: 156 } }, 0.5, YAHOO.util.Easing.easeOut);
			myAnim1.animate(); myAnim2.animate(); //myAnim3.animate(); 
		}
		var colorsTimeout = null;
		function startColoursTimer() {
			window.clearTimeout(colorsTimeout);
			//if (parseInt($("recBG").style.width) != 158) { 
			if (parseInt($("recBG").style.height) != 27) { 
				colorsTimeout = window.setTimeout("contractColours();", 1000);
			}
		}
		
		function swatchShow(strSwatch) {
			$("swatch-preview").style.visibility = "visible";
			if ($("hp_flash")) { $("hp_flash").style.visibility = "hidden"; }
			window.clearTimeout(swatchTimeout);
			swatchLoad(strSwatch);
			var myAnim1 = new YAHOO.util.Anim('swatch-preview', { opacity: { to: 1 } }, 0.5, YAHOO.util.Easing.easeOut);	
			myAnim1.animate(); 					
		}
		function swatchHide() {				
			window.clearTimeout(swatchTimeout);
			var myAnim1 =new YAHOO.util.Anim('swatch-preview', { opacity: { to: 0 } }, 0.5, YAHOO.util.Easing.easeOut);	
			var hideSwatch = function() { 
				$("swatch-preview").style.visibility = "hidden"; 
				if ($("hp_flash")) { $("hp_flash").style.visibility = "visible"; }
			};
			myAnim1.onComplete.subscribe(hideSwatch)
			myAnim1.animate(); 	
		}
		function swatchLoad(strSwatch) {
			//$("swatch").innerHTML = "";
			$("swatch").style.backgroundImage = "none";
			$("swatch-loading").style.visibility = "visible";
			var oSwatch = new Image;
			oSwatch.onload = function() {
				$("swatch-loading").style.visibility = "hidden";
				//$("swatch").innerHTML = "<img src='" + strSwatch + "' />";
				$("swatch").style.backgroundImage = "url('" + strSwatch + "')";
			}
			oSwatch.src = strSwatch;
		}
		var swatchTimeout = null;
		function startSwatchTimer() {
			window.clearTimeout(swatchTimeout);
			swatchTimeout = window.setTimeout("swatchHide();", 300);
		}

		function countdown_clock(year, month, day, hour, minute, format)
		{
			Today = new Date();
			Todays_Year = Today.getFullYear() - 2000;
			Todays_Month = Today.getMonth() + 1;
			
						
			// Computes the time difference between the client computer and the server.
			Server_Date = (new Date(8, 4, 16,
			                     14, 16, 10)).getTime();
			Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(),
			                     Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();
			
			countdown(year, month, day, hour, minute, (Todays_Date - Server_Date), format);              
		}
	
		function countdown(year, month, day, hour, minute, time_difference, format)
		{
			
			
			Today = new Date();
			Todays_Year = Today.getFullYear() - 2000;
			Todays_Month = Today.getMonth() + 1;
			                         
			// Convert today's date and the target date into miliseconds.
			Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(),
			             Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();
			Target_Date = (new Date(year, month, day, hour, minute, 00)).getTime();
			
			// Find their difference, and convert that into seconds.
			// Taking into account the time differential between the client computer and the server.
			Time_Left = Math.round((Target_Date - Todays_Date + time_difference) / 1000);
			
			if(Time_Left < 0)
			Time_Left = 0;
			
			switch(format)
			{
				case 0:
					// The simplest way to display the time left.
					document.getElementById("countdown").innerHTML = Time_Left + ' seconds';
					break;
				case 1:
					// More datailed.
					days = Math.floor(Time_Left / (60 * 60 * 24));
					Time_Left %= (60 * 60 * 24);
					hours = Math.floor(Time_Left / (60 * 60));
					Time_Left %= (60 * 60);
					minutes = Math.floor(Time_Left / 60);
					Time_Left %= 60;
					seconds = Time_Left;
					
					dps = 's'; hps = 's'; mps = 's'; sps = 's';
					// ps is short for plural suffix.
					if(days == 1) dps ='';
					if(hours == 1) hps ='';
					if(minutes == 1) mps ='';
					if(seconds == 1) sps ='';
					
					document.getElementById("countdown").innerHTML = 'Count down to CHRISTMAS: ';
					document.getElementById("countdown").innerHTML += '<strong>' + days + ' day' + dps + '</strong> ';
					document.getElementById("countdown").innerHTML += '<strong>' + hours + ' hour' + hps + '</strong> ';
					document.getElementById("countdown").innerHTML += '<strong>' + minutes + ' minute' + mps + '</strong> and ';
					document.getElementById("countdown").innerHTML += '<strong>' + seconds + ' second' + sps + '</strong> ';				
					break;
				default: 
					document.getElementById("countdown").innerHTML = Time_Left + ' seconds';
			}

			// Recursive call, keeps the clock ticking.
			setTimeout('countdown(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + time_difference + ', ' + format + ');', 1000);
		}












	var productArray = new Array('643','644','645','646','647','648','649');
	var productPriceArray = new Array('&pound;9.99','&pound;9.99','&pound;9.99','&pound;9.99','&pound;9.99','&pound;9.99','&pound;9.99');
	var productRRPArray = new Array('&pound;19.99','&pound;19.99','&pound;19.99','&pound;19.99','&pound;19.99','&pound;19.99','&pound;19.99');
	var productSavingArray = new Array('&pound;10.00','&pound;10.00','&pound;10.00','&pound;10.00','&pound;10.00','&pound;10.00','&pound;10.00');
		
	//var objProducts = { '643' : { 'colour_ID' : '1', 'size_ID' : '1', 'stock_Available' : 358 }, '644' : { 'colour_ID' : '3', 'size_ID' : '1', 'stock_Available' : 113 }, '645' : { 'colour_ID' : '9', 'size_ID' : '1', 'stock_Available' : 127 }, '646' : { 'colour_ID' : '11', 'size_ID' : '1', 'stock_Available' : 114 }, '647' : { 'colour_ID' : '14', 'size_ID' : '1', 'stock_Available' : 243 }, '648' : { 'colour_ID' : '16', 'size_ID' : '1', 'stock_Available' : 185 }, '649' : { 'colour_ID' : '19', 'size_ID' : '1', 'stock_Available' : 307 } };
	var objColours = { '1' : { 'colour_Name' : '#1 jet black', 'colour_Filename' : 'color_1.jpg', 'colour_Enabled' : true }, '2' : { 'colour_Name' : '#1B natural black', 'colour_Filename' : 'color_1B.jpg', 'colour_Enabled' : true }, '5' : { 'colour_Name' : '#6 medium brown', 'colour_Filename' : 'color_6.jpg', 'colour_Enabled' : true }, '3' : { 'colour_Name' : '#2 darkest brown', 'colour_Filename' : 'color_2.jpg', 'colour_Enabled' : true }, '4' : { 'colour_Name' : '#4 chocolate brown', 'colour_Filename' : 'color_4.jpg', 'colour_Enabled' : true }, '6' : { 'colour_Name' : '#8 light brown', 'colour_Filename' : 'color_8.jpg', 'colour_Enabled' : true }, '7' : { 'colour_Name' : '#10 medium ash brown', 'colour_Filename' : 'color_10.jpg', 'colour_Enabled' : true }, '8' : { 'colour_Name' : '#12 light golden brown', 'colour_Filename' : 'color_12.jpg', 'colour_Enabled' : true }, '9' : { 'colour_Name' : '#14 light ash brown', 'colour_Filename' : 'color_14.jpg', 'colour_Enabled' : true }, '10' : { 'colour_Name' : '#16 sahara blonde', 'colour_Filename' : 'color_16.jpg', 'colour_Enabled' : true }, '11' : { 'colour_Name' : '#18 ash blonde', 'colour_Filename' : 'color_18.jpg', 'colour_Enabled' : true }, '12' : { 'colour_Name' : '#20 dark blonde', 'colour_Filename' : 'color_20.jpg', 'colour_Enabled' : true }, '13' : { 'colour_Name' : '#22 medium blonde', 'colour_Filename' : 'color_22.jpg', 'colour_Enabled' : true }, '14' : { 'colour_Name' : '#24 light blonde', 'colour_Filename' : 'color_24.jpg', 'colour_Enabled' : true }, '15' : { 'colour_Name' : '#27 strawberry blonde', 'colour_Filename' : 'color_27.jpg', 'colour_Enabled' : true }, '16' : { 'colour_Name' : '#30 auburn', 'colour_Filename' : 'color_30.jpg', 'colour_Enabled' : true }, '17' : { 'colour_Name' : '#33 rich copper red', 'colour_Filename' : 'color_33.jpg', 'colour_Enabled' : true }, '18' : { 'colour_Name' : '#613 lightest blonde', 'colour_Filename' : 'color_613.jpg', 'colour_Enabled' : true }, '19' : { 'colour_Name' : '#P18/22 ash blonde with blonde highlight', 'colour_Filename' : 'color_P18_22.jpg', 'colour_Enabled' : true }, '20' : { 'colour_Name' : '#P24/27 strawberry blonde with blonde highlight', 'colour_Filename' : 'color_P24_27.jpg', 'colour_Enabled' : true }, '21' : { 'colour_Name' : '#P27/613 strawberry blond with lightest blonde highlight', 'colour_Filename' : 'color_P27_613.jpg', 'colour_Enabled' : true }, '22' : { 'colour_Name' : '#P4/27 dark brown with blonde highlight', 'colour_Filename' : 'color_P4_27.jpg', 'colour_Enabled' : true }, '23' : { 'colour_Name' : '#P6/27 medium brown with blonde highlight', 'colour_Filename' : 'color_P6_27.jpg', 'colour_Enabled' : true }, '24' : { 'colour_Name' : '#P6/613 medium brown with lightest blonde highlight', 'colour_Filename' : 'color_P6_613.jpg', 'colour_Enabled' : true }, '25' : { 'colour_Name' : '#P2/27 darkest brown with blonde highlight', 'colour_Filename' : 'color_P2_27.jpg', 'colour_Enabled' : true }, '26' : { 'colour_Name' : '#green', 'colour_Filename' : 'color_green.jpg', 'colour_Enabled' : true }, '27' : { 'colour_Name' : '#light pink', 'colour_Filename' : 'color_lightpink.jpg', 'colour_Enabled' : true }, '28' : { 'colour_Name' : '#pink', 'colour_Filename' : 'color_pink.jpg', 'colour_Enabled' : true }, '29' : { 'colour_Name' : '#purple', 'colour_Filename' : 'color_purple.jpg', 'colour_Enabled' : true }, '30' : { 'colour_Name' : '#red', 'colour_Filename' : 'color_red.jpg', 'colour_Enabled' : true }, '31' : { 'colour_Name' : '#blue', 'colour_Filename' : 'color_blue.jpg', 'colour_Enabled' : true }, '32' : { 'colour_Name' : '#yellow', 'colour_Filename' : 'color_yellow.gif', 'colour_Enabled' : true }, '33' : { 'colour_Name' : '#Wine Red', 'colour_Filename' : 'color_99J.gif', 'colour_Enabled' : true } };

	function stockAvailable(colour_ID, size_ID) { 
		for (product_ID in objProducts) {
			if (objProducts[product_ID]["colour_ID"] == colour_ID && objProducts[product_ID]["size_ID"] == size_ID) { 
				if (objProducts[product_ID]["stock_Available"]) {
					return objProducts[product_ID]["stock_Available"];
				} else {
					return 0;
				}		
			}	
		}
		return -1;
	}
	function updateStock(colour_ID, size_ID) {
		var intStock = stockAvailable(colour_ID, size_ID);
				if ($("stock-available")) {
						if (intStock>0) { $("stock-available").innerHTML = "In Stock"; return true; }
						if (intStock==0) { $("stock-available").innerHTML = "Out Of Stock"; return true; }
			if (intStock==-1) { $("stock-available").innerHTML = "Product Not Available"; return true; }
		}
			}
	
	/* COLOURS */
	function cSwatchShowPreview(colour_ID) {
		$("color-preview").innerHTML = "<img src='images/colour_chart/" + objColours[colour_ID]["colour_Filename"] + "' />";
		$("color-name").innerHTML = objColours[colour_ID]["colour_Name"];
		updateStock(colour_ID, intSelectedSize);
	}
	
	function cSwatchHidePreview() { 
		if (!intSelectedColour) { return false; }
		$("color-preview").innerHTML = "<img src='images/colour_chart/" + objColours[intSelectedColour]["colour_Filename"] + "' />";
		$("color-name").innerHTML = objColours[intSelectedColour]["colour_Name"];
		updateStock(intSelectedColour, intSelectedSize);
	}
	
	function highlightColour(a) {
		a.style.width = "23px";
		a.style.height = "23px";
		a.style.border = "2px solid #fff";
		a.style.background = "url('includes/z-dhtml/color/currency_white_arrow.gif') no-repeat 8px 18px";
	}
	function lowlightColour(a) {
		a.style.width = "25px";
		a.style.height = "25px";
		a.style.border = "1px solid #fff";
		a.style.background = "";
	}
	
	var intSelectedColour = false;
	function selectColour(selected_Colour_ID) { 
		if (!selected_Colour_ID) { return false; } 
		if (!isColourEnabled(selected_Colour_ID)) { alert("Sorry, this colour is currently unavailable"); return false; }
		if (!stockAvailable(selected_Colour_ID, intSelectedSize)) { alert("Sorry, this colour is currently out of stock"); return false; }
		for (colour_ID in objColours) {	
			if (objColours.hasOwnProperty(colour_ID) && colour_ID != "0") {
				lowlightColour($("col_" + colour_ID));
			}
		}
		highlightColour($("col_" + selected_Colour_ID));
		intSelectedColour = selected_Colour_ID;
		cSwatchShowPreview(intSelectedColour);
		updateProductSelection();
		return true;
	}
	
	function isColourEnabled(colour_ID) { 
		if (objColours[colour_ID]) {
			return objColours[colour_ID]["colour_Enabled"]; 
		} else {
			return false;
		}
	}
	function enableColour(colour_ID) { 
		objColours[colour_ID]["colour_Enabled"] = true;
		$("colp_" + colour_ID).className = ""; 
	}
	function disableColour(colour_ID) { 
		objColours[colour_ID]["colour_Enabled"] = false;
		$("colp_" + colour_ID).className = "op20"; 
	}
	function restrictColours(size_ID) {
		intFirstColour = 0;
		for (colour_ID in objColours) {	
			if (objColours.hasOwnProperty(colour_ID) && colour_ID != "0") {
				disableColour(colour_ID);
				//alert("disable: " + colour_ID);
			}
		}		
		for (product_ID in objProducts) {	
			if (objProducts.hasOwnProperty(product_ID) && product_ID != "0") {
				if (objProducts[product_ID]["size_ID"]==size_ID) { 
					if (!intFirstColour) { intFirstColour = objProducts[product_ID]["colour_ID"]; }
					enableColour(objProducts[product_ID]["colour_ID"]);			
					//alert("enable: " + objProducts[product_ID]["colour_ID"]);
				}
			}
		}
		if (!isColourEnabled(intSelectedColour)) { intSelectedColour = intFirstColour }
		selectColour(intSelectedColour);
	}
	
	/* SIZES */
	
	function sShowPreview(size_ID) {
		$("size-name").innerHTML = objSizes[size_ID]["size_Name"];
		updateStock(intSelectedColour, size_ID);
	}
	function sHidePreview() {
		if (!intSelectedSize) { return false; }
		$("size-name").innerHTML = objSizes[intSelectedSize]["size_Name"];
		updateStock(intSelectedColour, intSelectedSize);
	}
	
	function highlightSize(a) {
		a.style.width = "71px";
		a.style.height = "96px";
		a.style.border = "2px solid #FFF";
		a.style.background = "url('includes/z-dhtml/color/currency_white_arrow.gif') no-repeat 32px 91px";
	}
	function lowlightSize(a) {
		a.style.width = "75px";
		a.style.height = "100px";
		a.style.border = "";
		a.style.background = "";
	}
	
	var intSelectedSize = false;
	function selectSize(selected_Size_ID) {
		if (!selected_Size_ID) { return false; } 
		if (!isSizeEnabled(selected_Size_ID)) { alert("Sorry, this size is currently unavailable"); return false; }
		if (!stockAvailable(intSelectedColour, selected_Size_ID)) { alert("Sorry, this size is currently out of stock"); return false; }
		for (size_ID in objSizes) {	
			if (objSizes.hasOwnProperty(size_ID) && size_ID != "0") {
				lowlightSize($("size_" + size_ID));
			}
		}
		highlightSize($("size_" + selected_Size_ID));
		intSelectedSize = selected_Size_ID;
		sShowPreview(intSelectedSize);
		updateProductSelection();
		return true;
	}
	
	function isSizeEnabled(size_ID) { 
		if (objSizes[size_ID]) {
			return objSizes[size_ID]["size_Enabled"]; 
		} else {
			return false
		}
	}
	function enableSize(size_ID) { 
		objSizes[size_ID]["size_Enabled"] = true;
		$("sizep_" + size_ID).className = ""; 
	}
	function disableSize(size_ID) { 
		objSizes[size_ID]["size_Enabled"] = false;
		$("sizep_" + size_ID).className = "op20"; 
	}
	function restrictSizes(colour_ID) {
		intFirstSize = 0;
		for (size_ID in objSizes) {	
			if (objSizes.hasOwnProperty(size_ID) && size_ID != "0") {
				disableSize(size_ID);
			}
		}		
		for (product_ID in objProducts) {	
			if (objProducts.hasOwnProperty(product_ID) && product_ID != "0") {
				if (objProducts[product_ID]["colour_ID"]==colour_ID) { 
					if (!intFirstSize) { intFirstSize = objProducts[product_ID]["size_ID"]; }
					enableSize(objProducts[product_ID]["size_ID"]);			
				}
			}
		}
		if (!isSizeEnabled(intSelectedSize)) { intSelectedSize = intFirstSize }
		selectSize(intSelectedSize);
	}
	
	/* PRODUCTS */
		
	function selectProduct(product_ID) {
		for(x=0; x<productArray.length; x++) {
			if (productArray[x]==product_ID) { productIndex = x; }
		}
		
		objProduct_ID = $("product_ID");
		objProduct_ID.value = product_ID;
		
		if ($("display_Price")) { $("display_Price").innerHTML = productPriceArray[productIndex];	 } 
		if ($("display_RRP")) { $("display_RRP").innerHTML = productRRPArray[productIndex]; }
		if ($("display_Saving")) { $("display_Saving").innerHTML = productSavingArray[productIndex]; }
		
		updateStock(intSelectedColour, intSelectedSize);
	
		return false;
	}
	
	function updateProductSelection() {
		for (product_ID in objProducts) {	
			if (objProducts.hasOwnProperty(product_ID) && product_ID != "0") {
				if ( objProducts[product_ID]["colour_ID"] == intSelectedColour 
							&& objProducts[product_ID]["size_ID"] == intSelectedSize ) { 
					selectProduct(product_ID);
					break;
				}
			}
		}
	}
	
	function checkProductID() {
		if ($("product_ID").value=="") {
			alert("Please make a selection from the available options above.");
			return false;
		} else {
			return true;
		}
	}
	
	function hoverProductOn(product_ID) {
		objButton = $("b_pID_" + product_ID);
		if (objButton.src.indexOf('stock_available.gif')>-1) {
			objButton.src = "includes/z-dhtml/color/stock_over.gif";
		}
	}
	
	function hoverProductOff(product_ID) {
		objButton = $("b_pID_" + product_ID);
		if (objButton.src.indexOf('stock_over.gif')>-1) {
			objButton.src = "includes/z-dhtml/color/stock_available.gif";
		}
	}
	
		YAHOO.util.Event.onDOMReady(function() {		
		if (objProducts[643]["stock_Available"]) {
			// entry has stock
			intSelectedColour = objProducts[643]["colour_ID"];
			intSelectedSize = objProducts[643]["size_ID"];
		} else {
			// find first with stock
			for (product_ID in objProducts) {	
				if (objProducts.hasOwnProperty(product_ID) && product_ID != "0") {
					if ( objProducts[product_ID]["stock_Available"] ) { 
						intSelectedColour = objProducts[product_ID]["colour_ID"];
						intSelectedSize = objProducts[product_ID]["size_ID"];
						break;
					}
				}
			}
		}
		// Select
		if (intSelectedColour && intSelectedSize) { 
			selectColour(intSelectedColour);
			selectSize(intSelectedSize);		
			restrictSizes(intSelectedColour);
			restrictColours(intSelectedSize);
		} else {
			restrictSizes(null);
			restrictColours(null);
		}
	} ); 

