// Global JavaScript enhancement functions
// www.dulux.co.uk
// Oliver J Bishop
// (c) ICI PLC 2007
YAHOO.namespace('dulux.co.uk');

var startPos;
var flashDir = "/web/flash/";
/* Default Flash version supported, 
Flash Write function can override this if passed a different version as the last argument*/
var ver = 7;

var fPlug=0;
if (fPlug==0 && fDetect) {fDetect();}
if (fPlug>=ver) {hideNoFVer();}

function helperWin(URL,winName,type) {
	if (!type) {type='large';}
	var features = 'top=0,resizable,menubar,scrollbars';
	if (type=='full') {
		features += ',left=0,height=460,width=758,location,status';
	} else {
		features += ',left=100,height=500'
		if (type=='small') {
			features += ',width=350';
		} else if (type=='medium2') {
			features = 'top=0,resizable,scrollbars,left=100,height=460,width=420 status=no';
		} else if (type=='medium') {
			features += ',width=550';
		} else {
			features += ',width=618';
		}
	}
	if (type=='MP') {
		features = 'top=0,resizable,scrollbars,left=100,height=535,width=777';
	}
	if (type=='MPV') {
		features = 'top=0,height=526,width=760,resizable=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no';
	}
	eval(winName+'pop = window.open(URL,winName,features)');
	eval(winName+'pop.opener = self');
	eval(winName+'pop.focus()');
}

function fDetect() {
	/* detect which version of Flash installed, either  */
	fPlug= (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
	if (fPlug) {
		fPlug = parseInt(fPlug.description.substring(fPlug.description.indexOf(".")-2));
	}
	else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && navigator.userAgent.indexOf("Windows")>=0 ) {
	document.write('<script language=VBScript>\n');
	document.write('Dim hasPlayer, version\n');
	document.write('hasPlayer = false\n');
	document.write('version = 10\n');
	document.write('Do While version > 0\n');
	document.write('On Error Resume Next\n');
	document.write('hasPlayer = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & version)))\n');
	document.write('If hasPlayer = true Then Exit Do\n');
	document.write('version = version - 1\n');
	document.write('Loop\n');
	document.write('is_FlashVersion = version\n');
	document.write('is_Flash = hasPlayer\n');
	document.write('<\/script>\n');		
	if (version>0) {fPlug=version;}
	}
}

function hideNoFVer() {
	document.write('<style type="text/css"><!--');
	document.write('.noFlash {visibility:hidden;position:absolute;top:0;left:-1600;z-index:1;}');
	document.write('--><\/style>');
}

function fWrite(movie, w, h, fVars, minVer) {
	if ((minVer&&fPlug>=minVer)||fPlug>=ver) {
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+ver+',0,0,0" ');
		document.write('width="'+w+'" height="'+h+'" id="visualiser">');
		document.write('<param name="movie" value="'+flashDir+movie+'.swf?' + fVars + '">');
		document.write('<param name="allowScriptAccess" value="sameDomain" />');
		document.write('<param name="wmode" value="transparent">');
		document.write('<embed src="'+flashDir+movie+'.swf?' + fVars + '" name="visualiser" width="'+w+'" height="'+h+'" ');
		document.write('wmode="transparent" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">');
		document.write('<\/object>');
	}
}	

function lhsFlash(num) {   
	if (fWrite) { 
		fWrite('i_hue_select_leftnav', 87, 200, 'initMenu=' + num + '&inlink1=/inspiration/colour_inspiration/red_inspiration.jsp&inlink2=/inspiration/colour_inspiration/orange_inspiration.jsp&inlink3=/inspiration/colour_inspiration/gold_inspiration.jsp&inlink4=/inspiration/colour_inspiration/yellow_inspiration.jsp&inlink5=/inspiration/colour_inspiration/green_inspiration.jsp&inlink6=/inspiration/colour_inspiration/blue_inspiration.jsp&inlink7=/inspiration/colour_inspiration/violet_inspiration.jsp&inlink8=/inspiration/colour_inspiration/neutral_inspiration.jsp'); 
	} 
}

// ******************************************************************************************
// Global functions for www.dulux.co.uk
// ******************************************************************************************

function roll(obj) { // Roll images

	var img, img2;

	if (typeof obj === "object") {
		if (document.getElementsByTagName) {
			img = obj.getElementsByTagName("IMG")[0];
			img.src = (img.src.indexOf("_0.")>0)?img.src.replace("_0.", "_1."):img.src.replace("_1.", "_0.");
			
			// to allow global colour menu to rollover (ie to allow two image tags within the roll(this) object
			img2 = obj.getElementsByTagName("IMG")[1];
			if (img2!=null) {
				img2.src = (img2.src.indexOf("_0.")>0)?img2.src.replace("_0.", "_1."):img2.src.replace("_1.", "_0.");
			}
		}
	}
}

function rollBtn(btn) { // Roll buttons
  if (!btn.state) { btn.state = 0; }
  var newState = (btn.state===0)?1:0;
  btn.src = btn.src.replace("_" + btn.state + ".gif", "_" + newState + ".gif");
  btn.state = newState;
  return true;
}

YAHOO.dulux.co.uk.getScrollXY = function() { // Get scroll position of page
		var scrOfX = 0, scrOfY = 0;
		if( typeof( window.pageYOffset ) === 'number' ) {
			//Netscape compliant
			scrOfY = window.pageYOffset;
			scrOfX = window.pageXOffset;
		} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
			//DOM compliant
			scrOfY = document.body.scrollTop;
			scrOfX = document.body.scrollLeft;
		} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
			//IE6 standards compliant mode
			scrOfY = document.documentElement.scrollTop;
			scrOfX = document.documentElement.scrollLeft;
		}
		return [scrOfX,scrOfY];
	}
YAHOO.dulux.co.uk.fnMoveScrapbookVertical = function (e) { // Move scrapbook based on scroll position
	var animScrapbook;
	if (YAHOO.dulux.co.uk.getScrollXY()[1] < 100) {
		animScrapbook = new YAHOO.util.Anim('scrapbook', {   
			top : { to: 100 }  
		    }, 0.5, YAHOO.util.Easing.backOut).animate();   
		} else {
		animScrapbook = new YAHOO.util.Anim('scrapbook', {
			top : { to: YAHOO.dulux.co.uk.getScrollXY()[1]+12 }
			}, 0.5, YAHOO.util.Easing.backOut).animate();   
	}
}
YAHOO.dulux.co.uk.fnMoveScrapbookHorizontal = function (e) { // Move scrapbook based on scroll position

	//try not moving it at all
	return;

	var animScrapbook;
	if (YAHOO.util.Dom.getViewportWidth() < 900 ) {
		if (YAHOO.util.Dom.getViewportWidth() > 773) {
			animScrapbook = new YAHOO.util.Anim('scrapbook', {   
				left : { to: YAHOO.util.Dom.getViewportWidth() - 188 }  
			    }, 0.5, YAHOO.util.Easing.backOut).animate();   
		} else {
			animScrapbook = new YAHOO.util.Anim('scrapbook', {   
				left : { to: 587 }  
			    }, 0.5, YAHOO.util.Easing.backOut).animate();   
		}
	} else {
			animScrapbook = new YAHOO.util.Anim('scrapbook', {
				left : { to: 750}
				}, 0.5, YAHOO.util.Easing.backOut).animate();   
	}
}
YAHOO.dulux.co.uk.initRollovers = function() { // Configure dynamic colour chip rollovers
	var enhanceChips = function () {
	var dom = YAHOO.util.Dom;
	var thisChip, el, colourName, colourCode, picURL;
	var newHeader, newFooter;
	var tempDrag;
	// create colour chip rollovers
	var elements = dom.getElementsByClassName('chip');
	dom.generateId(elements,'chip_');
	for (var i = 0; i < elements.length; i++) {
		// Added to prevent infection of new Rollover script
		if (elements[i].className.indexOf("collect ") === -1) {
			thisChip = dom.get(elements[i]);			
			try { 
				// get the colour name from the image's alt tag
				el = thisChip.getElementsByTagName('img')[0];
				colourName = el.getAttribute("alt");
				colourCode = colourName.replace(/ /g,"_").toLowerCase();
				picURL = el.getAttribute("src");
				el.id="rollimg_"+i;
			} catch (err) { // handle case of no alt tag on chip
				colourName = "No colour";
				picURL = "/files/noimage.jpg";
			}
			if (YAHOO.util.Dom.hasClass ( thisChip , "expand")) {
				newHeader = document.createElement("div");
				newFooter = document.createElement("div");
				dom.addClass(newHeader, "header");
				dom.addClass(newFooter, "footer");
				// insert header div before the a tag
				if (thisChip.getElementsByTagName('a').length >0) { 
					elements[i].insertBefore(newHeader,thisChip.getElementsByTagName('a')[0]);
				} else {
					elements[i].insertBefore(newHeader,thisChip.getElementsByTagName('img')[0]);
				}
				//append the footer to the end of the div
				newFooter.appendChild(document.createTextNode(colourName));

				if (YAHOO.util.Dom.hasClass ( thisChip , "basket") || YAHOO.util.Dom.hasClass ( thisChip , "scrapbook")) {
					newDeleteDiv = document.createElement("div");
					newDeleteLink = document.createElement("a");
					newBR = document.createElement("br");
					newInput = document.createElement("input");
					newInput.type = "image";
					newInput.src = "/web/images/furniture/btn_delete.gif";
					newInput.alt = "Delete "+colourName;
					newInput.value = "Delete";
					newInput.name = "delete."+(i+1);
					newInput.onclick=function(){YAHOO.dulux.co.uk.doAjaxDelete(this); return false;};
					newDeleteDiv.appendChild(newInput); 
					dom.addClass(newDeleteDiv, "delete");
					newFooter.appendChild(newDeleteDiv);
				}		
				elements[i].appendChild(newFooter);
			}

			if (YAHOO.util.Dom.hasClass ( thisChip , "roll")) {
				// add listener for mouseover on the chip only (el) to show the rollover
				YAHOO.util.Event.addListener(el, "mouseover", fnShowrollover);  
				YAHOO.util.Event.addListener(el, "focus", fnShowrollover);
			} else {
				// make original image draggable
				if (YAHOO.util.Dom.hasClass ( thisChip , "nodrag") === false ) {
					tempDrag = new YAHOO.dulux.co.uk.DDCollectColour(el,"colours", { dragElId: "dragColour", centerFrame: true, resizeFrame: false });	
				}
			}
		}
	}

	// create image rollovers
	elements = dom.getElementsByClassName('pic');
	for (var j = 0; j < elements.length; j++) {
		// Added to prevent infection of new Rollover script
		if (elements[j].className.indexOf("collect ") === -1) { 
			thisPic = dom.get(elements[j]);
			thisPic.id = "pic_"+j;
			YAHOO.util.Event.addListener(thisPic, "mouseover", fnShowPicrollover);
			YAHOO.util.Event.addListener(thisPic, "focus", fnShowPicrollover);

			if (dom.hasClass ( thisPic , "scrapbook")) {
				var picURL = thisPic.getAttribute("src");
				var leftStr = picURL.search("/web/images/collect/");
				var rightStr = picURL.search(".jpg");
				var picCode = picURL.substring(leftStr+20,rightStr);
				picCode = picCode.replace('_72','');
				picCode = picCode.replace('_154','');
				picCode = picCode.replace('_236','');
				thisPic.id = picCode;
			}
		}
	}

	function fnShowrollover(e) { // Show chip rollover
		document.getElementById("rollovers").style.display = 'block';

		var colourName, colourCode;
		var dom = YAHOO.util.Dom;

		colourName = this.getAttribute("alt");
		colourCode = colourCode = colourName.replace(/ /g,"_").replace("/","").toLowerCase().replace("é","e").replace("ó","o").replace("í","i").replace("è","e");
;
		picURL = this.getAttribute("src");

		var chipDiv = this.parentNode;
		var rollOverDiv = dom.get("rollovers");

if (dom.hasClass ( chipDiv , "wood")) {

			rollOverDiv.innerHTML="<div class=\"rollover\"><div class=\"header\"></div><img id=\"dragcol\" src=\""+picURL+"\" alt=\""+colourName+"\" title=\""+colourName+"\" class=\"chipro\"/><div class=\"footer\">"+colourName+"<br/><br/></div></div>"		

		} else if (dom.hasClass ( chipDiv.parentNode , "product")) {

			var prodName = YAHOO.util.Dom.getElementsByClassName('prodPName','img','PageBorder')[0].id;

			//do the product special case

			rollOverDiv.innerHTML="<div class=\"rollover\"><div class=\"header\"></div><img id=\"dragcol\" src=\"/web/images/swatch/"+colourCode+".jpg\" alt=\""+colourName+"\" title=\""+colourName+"\" class=\"chipro\"/><div class=\"footer\">"+colourName+"<a onmouseover=\"roll(this);\" onmouseout=\"roll(this);\" href=\"/servlet/ColourSchemeHandler?name="+colourCode+"\">See colour schemes <img width=\"7\" height=\"7\" src=\"/web/images/shared/arrow_0.gif\" alt=\"\"/></a><a onmouseover=\"roll(this);\" onmouseout=\"roll(this);\" href=\"/servlet/ShoppingListHandler?listaction=add&colour="+colourCode+"&product="+prodName+"&successURL=/projects/my_shopping_list/refresh.jsp\">Add to shopping list <img width=\"7\" height=\"7\" src=\"/web/images/shared/arrow_0.gif\" alt=\"\"/></a><br/></div></div>"

		} else {

			if (dom.hasClass ( chipDiv.parentNode , "exterior")) {

				//rollOverDiv.innerHTML="<div class=\"rollover\"><div class=\"header\"></div><img id=\"dragcol\" src=\"/web/images/swatch/"+colourCode+".jpg\" alt=\""+colourName+"\" title=\""+colourName+"\" class=\"chipro\"/><div class=\"footer\">"+colourName+"&nbsp;<br/><br/></div></div>"

				rollOverDiv.innerHTML="<div class=\"rollover\"><div class=\"header\"></div><img id=\"dragcol\" src=\"/web/images/swatch/"+colourCode+".jpg\" alt=\""+colourName+"\" title=\""+colourName+"\" class=\"chipro\"/><div class=\"footer\">"+colourName+"<a onmouseover=\"roll(this);\" onmouseout=\"roll(this);\" href=\"/servlet/ColourAvailabilityHandler?name="+colourCode+"\">See products available in this colour <img width=\"7\" height=\"7\" src=\"/web/images/shared/arrow_0.gif\" alt=\"\"/></a><br/></div></div>"

			} else {

				rollOverDiv.innerHTML="<div class=\"rollover\"><div class=\"header\"></div><img id=\"dragcol\" src=\"/web/images/swatch/"+colourCode+".jpg\" alt=\""+colourName+"\" title=\""+colourName+"\" class=\"chipro\"/><div class=\"footer\">"+colourName+"<a onmouseover=\"roll(this);\" onmouseout=\"roll(this);\" href=\"/servlet/ColourAvailabilityHandler?name="+colourCode+"\">See co-ordinating colours and products available in this colour <img width=\"7\" height=\"7\" src=\"/web/images/shared/arrow_0.gif\" alt=\"\"/></a><br/></div></div>"

			}

	}



		if (!dom.hasClass ( chipDiv , "nodrag")) {
			tempDrag = new YAHOO.dulux.co.uk.DDCollectColour("dragcol", "colours", { dragElId: "dragColour", centerFrame: true, resizeFrame: false });	
		}

		var coord = dom.getXY(this);
		var rolloverLayer = rollOverDiv;
		var thisChip;

		dom.setX(rolloverLayer, coord[0]-9);
		dom.setY(rolloverLayer, coord[1]-10);

		// add listener for mouseout on the whole rollover (newRollover) 
		YAHOO.util.Event.addListener(document.getElementById("rollovers"), "mouseout", fnHiderollover);
	} 

	function fnShowPicrollover(e) { // Show picture rollover
		var dom = YAHOO.util.Dom;		
		var coord = dom.getXY(this);
		document.getElementById("rollovers").style.display = 'block';	
		var picURL = this.getAttribute("src");

		var leftStr = picURL.search("/web/images/collect/");
		var rightStr = picURL.search(".jpg");
		var picCode = picURL.substring(leftStr+20,rightStr);
		picCode = picCode.replace('_72','');
		picCode = picCode.replace('_154','');
		picCode = picCode.replace('_236','');
		picCode = picCode.replace('_400','');

		var picSize = this.getAttribute("width");
		var rollOverDiv = dom.get("rollovers");
		if (dom.hasClass ( this , "scrapbook")) {
			rollOverDiv.innerHTML = "<div style=\"width: "+picSize+"px;\" class=\"picrollover "+picSize+"\" id=\"picrollover_0\"><img onclick=\"YAHOO.dulux.co.uk.doZoom(this);return false;\" id=\"dragpic\" src=\""+picURL+"\"/><div class=\"picrolloverfooter\"><div><a href=\"#\" onmouseover=\"roll(this);\" onclick=\"YAHOO.dulux.co.uk.doScrapbookDeleteImage('"+picCode+"',this);return false;\" onmouseout=\"roll(this);\">Delete <img width=\"7\" height=\"7\" src=\"/web/images/shared/arrow_0.gif\" alt=\"\"/></a></div></div></div>";
		} else {
			rollOverDiv.innerHTML = "<div style=\"width: "+picSize+"px;\" class=\"picrollover "+picSize+"\" id=\"picrollover_0\"><img onclick=\"YAHOO.dulux.co.uk.doZoom(this);return false;\" id=\"dragpic\" src=\""+picURL+"\"/><div class=\"picrolloverfooter\" style=\"margin-top: 0;\"><div></div></div></div>";
			//rollOverDiv.innerHTML = "<div style=\"width: "+picSize+"px;height: "+picSize+"px;\" class=\"picrollover "+picSize+"\" id=\"picrollover_0\"><img onclick=\"YAHOO.dulux.co.uk.doZoom(this);return false;\" id=\"dragpic\" src=\""+picURL+"\"/><div class=\"picrolloverfooter\"><div><a href=\"#\" onmouseover=\"roll(this);\" onclick=\"YAHOO.dulux.co.uk.doScrapbookAddImage('"+picCode+"',this);return false;\" onmouseout=\"roll(this);\">Add to my scrapbook <img width=\"7\" height=\"7\" src=\"/web/images/shared/arrow_0.gif\" alt=\"\"/></a></div></div></div>";

			
		}

		if (picSize != null && picSize < 236 ) {
			YAHOO.util.Dom.addClass("dragpic", "zoom");
		} 

		dom.setX(rollOverDiv, coord[0]-11);
		dom.setY(rollOverDiv, coord[1]-10);

		tempDrag = new YAHOO.dulux.co.uk.DDCollectImage("dragpic","pictures", { dragElId: "dragPicture", centerFrame: true, resizeFrame: false });

		// add listener for mouseout on the whole rollover (newRollover) 
		YAHOO.util.Event.addListener(document.getElementById("rollovers"), "mouseout", fnHiderollover);
	} 
	 
	function fnHiderollover(e) { // Hide colour chip rollover
		// Prevent double zoom problem
		YAHOO.dulux.co.uk.doZoomFlag = false;
		var tg = (window.event) ? e.srcElement : e.target;
		if (tg.nodeName !== 'DIV') { return; }
		
		var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
		
		if (reltg) {
			while (reltg && reltg !== tg && reltg.nodeName !== 'BODY') {
				reltg= reltg.parentNode;
			}
		}
		if (reltg === tg) {return;}
		// Mouseout took place when mouse actually left layer
		// Handle event
		document.getElementById("rollovers").style.display = 'none';
		}
	};
	
	enhanceChips();
};

YAHOO.dulux.co.uk.initScrapbook = function() { // Configure scrolling scrapbook

	var setScrapbook = function(e) {
	
		// add listener for scrolling
		YAHOO.util.Event.addListener(window, "scroll", YAHOO.dulux.co.uk.fnMoveScrapbookVertical);  
		YAHOO.util.Event.addListener(window, "resize", YAHOO.dulux.co.uk.fnMoveScrapbookHorizontal);  
		
		YAHOO.dulux.co.uk.fnMoveScrapbookVertical(); 
		YAHOO.dulux.co.uk.fnMoveScrapbookHorizontal(); 
	};

setScrapbook();

};

YAHOO.dulux.co.uk.doZoomFlag = false;

YAHOO.dulux.co.uk.DDCollectImage = function(id, sGroup, config) {
    if (id) {
        this.init(id, sGroup, config);				
    }
};

YAHOO.dulux.co.uk.DDCollectImage.prototype = new YAHOO.util.DDProxy();

YAHOO.dulux.co.uk.DDCollectImage.prototype.clickValidator = function(e) {
	var el = this.getEl(); 
	var picURL = el.getAttribute("src");
	// Remove the _x used for non-square zoom image
	picURL = picURL.replace('_x','');
	picURL = picURL.replace('_400','_31');
	picURL = picURL.replace('_236','_31');
	picURL = picURL.replace('_154','_31');
	picURL = picURL.replace('_72','_31');
	// If images are not a square size
	picURL = (picURL.indexOf("_31") == -1) ? picURL.replace(".jpg", "_31.jpg") : picURL;
	var root = YAHOO.util.Dom.get("dragPicture");
  	
	this.startPos = YAHOO.util.Dom.getXY(el);
	YAHOO.util.Dom.setStyle(root, 'background-image', 'url('+picURL+')'); 	
		
	return true;
};



YAHOO.dulux.co.uk.DDCollectColour = function(id, sGroup, config) {
    if (id) {
        this.init(id, sGroup, config);				
    }
};

YAHOO.dulux.co.uk.DDCollectColour.prototype = new YAHOO.util.DDProxy();

YAHOO.dulux.co.uk.DDCollectColour.prototype.clickValidator = function(e) {
	var el = this.getEl(); 
	var picURL = el.getAttribute("src");
	var root = YAHOO.util.Dom.get("dragColour");
  	
	this.startPos = YAHOO.util.Dom.getXY(el);
	YAHOO.util.Dom.setStyle(root, 'background-image', 'url('+picURL+')'); 	
		
	return true;
};


YAHOO.dulux.co.uk.DDCollectImage.prototype.onInvalidDrop = function(e) {  
		
	//Close any open chips/images
	document.getElementById("rollovers").style.display = 'none';
			
};

YAHOO.dulux.co.uk.DDCollectImage.prototype.onDragDrop = function(e, id) {  

var imageName, leftStr, rightStr, colourId, addingelement, resultelement, url, animProgress;

	if (id === 'scrapbook') { 
	
		imageName= YAHOO.util.Dom.getStyle('dragPicture', 'background-image');
		leftStr = imageName.search("/web/images/collect/");
		rightStr = imageName.search("_31.jpg");
		imageId = imageName.substring(leftStr+20,rightStr);
		resultelement = document.getElementById("message");
		addingelement = document.getElementById("adding");

		//Close any open chips/images
		document.getElementById("rollovers").style.display = 'none';

		YAHOO.util.Dom.setStyle('indicator', 'visibility', '');
		resultelement.textContent = "";
		resultelement.innerText = ""; 
		addingelement.textContent = "Adding...";
		addingelement.innerText = "Adding...";
		YAHOO.dulux.co.uk.doScrapbookAddDraggedImage(imageId);		
	}
};




YAHOO.dulux.co.uk.DDCollectColour.prototype.onDragDrop = function(e, id) {  

var colourStyle, leftStr, rightStr, colourId, addingelement, resultelement, url, animProgress;

	if (id === 'scrapbook') { 
	
		colourStyle= YAHOO.util.Dom.getStyle('dragColour', 'background-image');
	
		leftStr = colourStyle.search("/swatch/");
		rightStr = colourStyle.search(".jpg");
		colourId = colourStyle.substring(leftStr+8,rightStr);
		resultelement = document.getElementById("message");
		addingelement = document.getElementById("adding");

		//Close any open chips/images
		document.getElementById("rollovers").style.display = 'none';

		YAHOO.util.Dom.setStyle('indicator', 'visibility', '');
		resultelement.textContent = "";
		resultelement.innerText = ""; 
		addingelement.textContent = "Adding...";
		addingelement.innerText = "Adding..."; 
		YAHOO.dulux.co.uk.doScrapbookAddColour(colourId);		
	}
};

YAHOO.dulux.co.uk.DDCollectColour.prototype.onInvalidDrop = function(e) {  
	//Close any open chips/images
	document.getElementById("rollovers").style.display = 'none';
};

YAHOO.dulux.co.uk.doZoom = function(el) {
	var picRollover, picSize, picImg, picZoom, picZoomPic, picShift;			

	picRollover = el.parentNode.id;
	picShift = 0;
	picSizeWidth = parseInt(el.width); // Changed from picRollover to el
	picSizeHeight = parseInt(el.height); // Changed from picRollover to el
	picImg = el.parentNode.childNodes[0];

	YAHOO.util.Dom.removeClass(picImg, "zoom");

	if (!YAHOO.dulux.co.uk.doZoomFlag &&
	picSizeWidth < 400 && 
	(picSizeWidth !== 358 && picSizeHeight !== 355) &&
	(picSizeWidth == picSizeWidth && 
	picSizeWidth !== 72 &&
	picSizeWidth !== 154 &&
	picSizeWidth !== 236)) { 	
		YAHOO.dulux.co.uk.doZoomFlag = true;
		var sizeY = picSizeHeight + 82;
		var scale = sizeY / picSizeHeight;
		var sizeX = Math.round(picSizeWidth * scale);

		switch(picSizeWidth) {
			case 72:  picShift = 72; break;
			case 154: picShift = 36; break;
			default: picShift = (sizeX - picSizeWidth) / 2;
		}

		var myAnim = new YAHOO.util.Anim(picRollover, {   
			width: { to: sizeX }   		 
			}, .2, YAHOO.util.Easing.easeOut).animate();   

		var myAnim2 = new YAHOO.util.Anim(picImg, {   
			width: { to: sizeX },    
			height: { to: sizeY }  
			}, .2, YAHOO.util.Easing.easeOut).animate();   

		var myAnim4 = new YAHOO.util.Anim(document.getElementById("rollovers"), {   
			left : { by: -picShift },
			top : { by: -picShift }
			}, .2, YAHOO.util.Easing.easeOut);

		var replacePicture = function() {
			picImg.src = picImg.src.replace(".jpg", "_x.jpg");
		};

		myAnim4.onComplete.subscribe(replacePicture);
		myAnim4.animate();
		return;
	} 

	if (picSizeWidth < 236 && picSizeHeight < 236 && !YAHOO.dulux.co.uk.doZoomFlag) { 
		YAHOO.dulux.co.uk.doZoomFlag = true;

		switch(picSizeWidth) {
			case 72:  picShift = 72; break;
			case 154: picShift = 36; break;
		}

		var myAnim = new YAHOO.util.Anim(picRollover, {   
			width: { to: 236 }   		 
			}, .2, YAHOO.util.Easing.easeOut).animate();   

		var myAnim2 = new YAHOO.util.Anim(picImg, {   
			width: { to: 236 },    
			height: { to: 236 }  
			}, .2, YAHOO.util.Easing.easeOut).animate();   

		var myAnim4 = new YAHOO.util.Anim(document.getElementById("rollovers"), {   
			left : { by: -picShift },
			top : { by: -picShift }
			}, .2, YAHOO.util.Easing.easeOut);

		var replacePicture = function() {
			picImg.src=picImg.src.replace("_72","_236");
			picImg.src=picImg.src.replace("_154","_236");
		};

		myAnim4.onComplete.subscribe(replacePicture);
		myAnim4.animate();
	}
};
	
YAHOO.dulux.co.uk.doAjaxDelete = function(el) {

	var colourToDelete = el.parentNode.parentNode.parentNode.childNodes[1].alt.replace(/ /g,"_").toLowerCase();

	var totalColours = YAHOO.util.Dom.getElementsByClassName("chip","div");
		
	if (!YAHOO.util.Dom.hasClass ( el.parentNode.parentNode.parentNode , "scrapbook")) {
	
			if (totalColours.length <= 16) {
				document.getElementById("change").innerHTML = "<input name=\"checkout\" type=\"submit\" value=\"Order\" />";
			}
			
			if (totalColours.length === 1) {
				document.getElementById("hereare").innerHTML = "";
				document.getElementById("change").innerHTML = "<div class=\"tReg\"><p>You currently don't have any items in your order.</p><p> As you browse the site you can select colours to order by moving your mouse pointer over a colour  and you'll see the option to order a colour swatch.</p>	  <a href=\"/colours/index.jsp\" class=\"menuLnk scta\" onMouseOver=\"roll(this)\" onMouseOut=\"roll(this)\">See our colours <img src=\"/web/images/shared/arrow_0.gif\" width=\"7\" height=\"7\" border=\"0\" alt=\"\" /></a>	</div>";
			}
		
	}

	//change the delete button into an Ajax progress indicator
	el.src = "/web/images/furniture/scrapbook/indicator_white.gif";
	YAHOO.util.Dom.setStyle(el.parentNode, 'left', "54px"); 	
	YAHOO.util.Dom.setStyle(el, 'left', "54px"); 	
	YAHOO.util.Dom.setStyle(el, 'outline', "none"); 	
	YAHOO.util.Dom.setStyle(el, 'width', "16px"); 	
	YAHOO.util.Dom.setStyle(el, 'height', "16px"); 	

	var delCallback =
		{
		  success: function(o) {
			// Delete the colour chip passed as o.argument from the array of chips
			var elements = YAHOO.util.Dom.getElementsByClassName('chip');
			for (var i = 0; i < elements.length; i++) {
				if (elements[i].childNodes[1].src.indexOf(o.argument[0]) > 0) {
					while(elements[i].hasChildNodes()){
						elements[i].removeChild(elements[i].childNodes[0])
					}
					elements[i].parentNode.removeChild(elements[i]);
				}
			}	
		},
		
		  failure: function(o) {alert("Could not delete this colour.");},
		  argument: [colourToDelete]
		}
	
	var sUrl="";
	var sArgs="";
	if (YAHOO.util.Dom.hasClass ( el.parentNode.parentNode.parentNode , "scrapbook")) {
		sUrl="/servlet/ScrapbookHandler";
		sArgs="scrapaction=delete&successURL=/ajax/response.jsp&failURL=/ajax/response.jsp&ItemType=colour&ItemId="+colourToDelete;
	} else {
		sUrl="/servlet/ShoppingBasketHandler";
		sArgs="action=delete&successURL=/ajax/response.jsp&failURL=/ajax/response.jsp&ItemType=colour&ItemID="+colourToDelete;
	}
	
	var transaction = YAHOO.util.Connect.asyncRequest('POST', sUrl, delCallback, sArgs);  
}

YAHOO.dulux.co.uk.doScrapbookAddFolder = function (folderToAdd, el) {

	//Add an ID to the clicked element
	YAHOO.util.Dom.generateId(el,"add_");
	
	var addIcon, addText;
		
	addIcon = YAHOO.util.Dom.getElementsByClassName('AddIcon','div',el)[0].childNodes[0];		
	addText = YAHOO.util.Dom.getElementsByClassName('AddText','div',el)[0];

	addText.innerHTML="Adding...";
	
	//Remove links now clicked
	el.onclick="";
	el.onmouseover="";
	el.onmouseout="";
	YAHOO.util.Dom.setStyle(el, 'cursor', "default"); 	
		
	//change the icon into an Ajax progress indicator
	addIcon.src = "/web/images/furniture/scrapbook/indicator_white.gif";
	YAHOO.util.Dom.setStyle(addIcon, 'left', "54px"); 	
	YAHOO.util.Dom.setStyle(addIcon, 'margin-left', "3px");
	YAHOO.util.Dom.setStyle(addIcon, 'outline', "none"); 	
	YAHOO.util.Dom.setStyle(addIcon, 'width', "16px"); 	
	YAHOO.util.Dom.setStyle(addIcon, 'height', "16px"); 	

	var addCallback =
		{
		  success: function(o) {
			var response, resultelement,addingelement, addIcon, addText;
			var addedDiv = document.getElementById(o.argument);

			addIcon = YAHOO.util.Dom.getElementsByClassName('AddIcon','div',el)[0];		
			addText = YAHOO.util.Dom.getElementsByClassName('AddText','div',el)[0];

			if (!o.responseText.indexOf("unhandled exception") >= 0){
				addText.innerHTML="Folder added";
				addIcon.innerHTML="";
			} else {
				addText.innerHTML="Error";
				addIcon.innerHTML="";
			} 
			
			YAHOO.util.Dom.setStyle('indicator', 'visibility', 'hidden');
			response = o.responseText;
			if (response.indexOf("unhandled exception") >= 0 ) { response = "Sorry, you need to enable cookies to use the scrapbook.";}
			resultelement = document.getElementById("message");
			addingelement = document.getElementById("adding");
			resultelement.textContent = response;
  			resultelement.innerText = response;  
			addingelement.textContent = "";
			addingelement.innerText = "";
						
		},
		
		  failure: function(o) {
				var addingelement;
		    	YAHOO.util.Dom.setStyle('indicator', 'visibility', 'hidden');
	    		addingelement = document.getElementById("adding");
				addingelement.textContent = "";
				addingelement.innerText = "";
		  		alert("Could not add this folder.");
				
		},
		  argument: [el.id]
		}
	
	var sUrl="";
	var sArgs="";
	sUrl="/servlet/ScrapbookHandler";
	sArgs="scrapaction=add&successURL=/ajax/response.jsp&failURL=/ajax/response.jsp&ItemType=folder&ItemId="+folderToAdd;
	
	var transaction = YAHOO.util.Connect.asyncRequest('POST', sUrl, addCallback, sArgs);
		
}

YAHOO.dulux.co.uk.doScrapbookAddImage = function (imgToAdd, el) {

	addDiv = el.parentNode;
	
	addDiv.innerHTML="<img width=\"10\" height=\"10\" src=\"/web/images/furniture/scrapbook/indicator_white.gif\" /> Adding...";
	
	//Add an ID to the clicked element
	YAHOO.util.Dom.generateId(addDiv,"addimg_");
	
	var addCallback =
		{
		  success: function(o) {
	//		var response, resultelement,addingelement, addIcon, addText;

			try {
				var addedDiv = document.getElementById(o.argument);
				if (!o.responseText.indexOf("unhandled exception") >= 0) {
					addedDiv.innerHTML="Added.";
				} else {
					addedDiv.innerHTML="Error.";
				}
			} catch (e) {
				// Rollover has been removed in the meantime
			}
			
			YAHOO.util.Dom.setStyle('indicator', 'visibility', 'hidden');
			response = o.responseText;
			if (response.indexOf("unhandled exception") >= 0 ) { response = "Sorry, you need to enable cookies to use the scrapbook.";}
			resultelement = document.getElementById("message");
			addingelement = document.getElementById("adding");
			resultelement.textContent = response;
   			resultelement.innerText = response;  
			addingelement.textContent = "";
			addingelement.innerText = "";
						
		},
		
		  failure: function(o) {
				var addingelement;
		    	YAHOO.util.Dom.setStyle('indicator', 'visibility', 'hidden');
	    		addingelement = document.getElementById("adding");
				addingelement.textContent = "";
				addingelement.innerText = "";
		  		alert("Could not add this picture.");
				
		},
		  argument: [addDiv.id]
		}
	
	var sUrl="";
	var sArgs="";
	sUrl="/servlet/ScrapbookHandler";
	sArgs="scrapaction=add&successURL=/ajax/response.jsp&failURL=/ajax/response.jsp&ItemType=image&ItemId="+imgToAdd;
	
	var transaction = YAHOO.util.Connect.asyncRequest('POST', sUrl, addCallback, sArgs);
		
}

YAHOO.dulux.co.uk.doScrapbookDeleteImage = function (imgToDelete, el) {

	
	delDiv = el.parentNode;
	
	delDiv.innerHTML="<img width=\"10\" height=\"10\" src=\"/web/images/furniture/scrapbook/indicator_white.gif\" /> Deleting...";
	
	//Add an ID to the clicked element
	YAHOO.util.Dom.generateId(delDiv,"delimg_");
	
	var delCallback =
		{
		  success: function(o) {
	
			//Close any open chips/images
			document.getElementById("rollovers").style.display = 'none';
			//in effect, hide the pic until the page is refreshed
			var picImg = document.getElementById(o.argument)
			YAHOO.util.Dom.removeClass ( picImg , "pad" );
			YAHOO.util.Dom.removeClass ( picImg , "scrapbook" );
			YAHOO.util.Dom.removeClass ( picImg , "pic" );
			picImg.src="";
			picImg.height="0";
			picImg.width="0";
						
		},
		
		  failure: function(o) {
				var addingelement;
		    	YAHOO.util.Dom.setStyle('indicator', 'visibility', 'hidden');
	    		addingelement = document.getElementById("adding");
				addingelement.textContent = "";
				addingelement.innerText = "";
		  		alert("Could not delete this picture.");
				
		},
		  argument: [imgToDelete]
		}
	
	var sUrl="";
	var sArgs="";
	sUrl="/servlet/ScrapbookHandler";
	sArgs="scrapaction=delete&successURL=/ajax/response.jsp&failURL=/ajax/response.jsp&ItemType=image&ItemId="+imgToDelete;
	
	var transaction = YAHOO.util.Connect.asyncRequest('POST', sUrl, delCallback, sArgs);
		
}


YAHOO.dulux.co.uk.doScrapbookAddDraggedImage = function (imgToAdd) {

	var addCallback =
		{
		  success: function(o) {
			
			YAHOO.util.Dom.setStyle('indicator', 'visibility', 'hidden');
			response = o.responseText;
			if (response.indexOf("unhandled exception") >= 0 ) { response = "Sorry, you need to enable cookies to use the scrapbook.";}
			resultelement = document.getElementById("message");
			addingelement = document.getElementById("adding");
			resultelement.textContent = response;
   			resultelement.innerText = response;  
			addingelement.textContent = "";
			addingelement.innerText = "";
						
		},
		
		  failure: function(o) {
				var addingelement;
		    	YAHOO.util.Dom.setStyle('indicator', 'visibility', 'hidden');
	    		addingelement = document.getElementById("adding");
				addingelement.textContent = "";
				addingelement.innerText = "";
		  		alert("Could not add this picture.");
				
		}
		}
	
	var sUrl="";
	var sArgs="";
	sUrl="/servlet/ScrapbookHandler";
	sArgs="scrapaction=add&successURL=/ajax/response.jsp&failURL=/ajax/response.jsp&ItemType=image&ItemId="+imgToAdd;
	
	var transaction = YAHOO.util.Connect.asyncRequest('POST', sUrl, addCallback, sArgs);
		
}



YAHOO.dulux.co.uk.doScrapbookAddColour = function (colourToAdd) {
	
	var addCallback =
		{
		  success: function(o) {
			var response, resultelement,addingelement;
			YAHOO.util.Dom.setStyle('indicator', 'visibility', 'hidden');
			response = o.responseText;
			if (response.indexOf("unhandled exception") >= 0 ) { response = "Sorry, you need to enable cookies to use the scrapbook.";}
			resultelement = document.getElementById("message");
			addingelement = document.getElementById("adding");
			resultelement.textContent = response;
  			resultelement.innerText = response;  
			addingelement.textContent = "";
			addingelement.innerText = "";
						
		},
		
		  failure: function(o) {
		  	
			var addingelement;
		    YAHOO.util.Dom.setStyle('indicator', 'visibility', 'hidden');
	    	addingelement = document.getElementById("adding");
			addingelement.textContent = "";
			addingelement.innerText = "";
		  	alert("Could not add this colour.");
			
			},
		  argument: [colourToAdd]
		}
	
	var sUrl="";
	var sArgs="";
	sUrl="/servlet/ScrapbookHandler";
	sArgs="scrapaction=add&successURL=/ajax/response.jsp&failURL=/ajax/response.jsp&ItemType=colour&ItemId="+colourToAdd;
	
	var transaction = YAHOO.util.Connect.asyncRequest('POST', sUrl, addCallback, sArgs);  
}

	

YAHOO.dulux.co.uk.toggleSection = function(section) {

	var divToToggle = document.getElementById("productSection"+section);

	//Close any open chips/images
	document.getElementById("rollovers").style.display = 'none';

	if (YAHOO.util.Dom.getStyle(divToToggle, 'display')==="none") {
		YAHOO.util.Dom.setStyle(divToToggle, 'display', 'block');
	} else {
		YAHOO.util.Dom.setStyle(divToToggle, 'display', 'none');
	}
	//Roll the arrow
	roll(document.getElementById("rolloverLink"+section));

	}
	
YAHOO.dulux.co.uk.startList = function() {

		var navRoot, node, i, breadCrumb, newTabBackground;	
		var sectionName = "";
		var tabToChange = "";

		if (document.all&&document.getElementById) {
			navRoot = document.getElementById("nav");
			if (navRoot) {
				for (i=0; i<navRoot.childNodes.length; i++) {
					node = navRoot.childNodes[i];
					if (node.nodeName==="LI") {
						node.onmouseover=function() {
							this.className+=" over";
						};
						node.onmouseout=function() {
							this.className=this.className.replace(" over", "");
						};
						
					}
				}
			}
		}

		breadCrumb = document.getElementById("breadCrumb");
		
		if (breadCrumb !== null && breadCrumb.hasChildNodes()) {
			if (breadCrumb.childNodes[1] && breadCrumb.childNodes[1].hasChildNodes()) {
				sectionName = breadCrumb.childNodes[1].childNodes[0];
			} else {
				if (breadCrumb.hasChildNodes()) {
					sectionName = breadCrumb.childNodes[1];
				}
			}
			if (sectionName !== "" && typeof sectionName !== "undefined") {
				sectionName = sectionName.nodeValue.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
			}
		}
		
		if (sectionName !== "" && typeof sectionName !== "undefined") {
			if (sectionName.substring(0,3) === "Ins") {
				tabToChange = document.getElementById("nav1");
			} else if (sectionName.substring(0,3) === "Col") {
				tabToChange = document.getElementById("nav2");
			} else if (sectionName.substring(0,4) === "Prod") {
				tabToChange = document.getElementById("nav3");
			} else if (sectionName.substring(0,4) === "Help") {
				tabToChange = document.getElementById("nav4");
			};
		}
		
		if (tabToChange !== "") {
			YAHOO.util.Dom.addClass(tabToChange.childNodes[0], "navSelected");
			newTabBackground = YAHOO.util.Dom.getStyle(tabToChange, 'background-image').replace("_0","_1");
			YAHOO.util.Dom.setStyle(tabToChange, 'background-image', newTabBackground);
		}		
}
	
YAHOO.dulux.co.uk.deleteFromProjectList = function(id, el) {
	
	var newProgress;
	var divToDelete = el.parentNode.parentNode.parentNode;
	var divDelete = el.parentNode;
	
	//Remove the a href and image from the divDelete
	while(divDelete.hasChildNodes()){
			divDelete.removeChild(divDelete.childNodes[0])
	}

	newProgress = document.createElement("img");
	
	//Create a new Ajax progress indicator
	newProgress.src = "/web/images/furniture/scrapbook/indicator_white.gif"; 	
	YAHOO.util.Dom.setStyle(newProgress, 'left', "54px"); 	
	YAHOO.util.Dom.setStyle(newProgress, 'outline', "none"); 	
	YAHOO.util.Dom.setStyle(newProgress, 'width', "16px"); 	
	YAHOO.util.Dom.setStyle(newProgress, 'height', "16px"); 	
	YAHOO.util.Dom.setStyle(newProgress, 'margin-top', "4px"); 
	
	//Put the indicator in the delete div	
	divDelete.appendChild(newProgress);

	var projDelCallback =
		{
		  success: function(o) {
			// Delete the colour chip passed as o.argument from the array of chips
			var divToDelete = document.getElementById(o.argument);
	
			while(divToDelete.hasChildNodes()){
				divToDelete.removeChild(divToDelete.childNodes[0])
			}
			
			YAHOO.util.Dom.setStyle(divToDelete, 'visibility', 'hidden');
			
		},
		
		  failure: function(o) {alert("Could not delete this project.");},
		  argument: [divToDelete.id]
		}
	
	var sUrl="";
	var sArgs="";
	sUrl="/servlet/SaveSchemeHandler";
	sArgs="action=delete&successURL=/ajax/response.jsp&failURL=/ajax/response.jsp&SchemeID="+id;
	
	var transaction = YAHOO.util.Connect.asyncRequest('POST', sUrl, projDelCallback, sArgs);

}

YAHOO.dulux.co.uk.deleteFromOwnRooms = function(id, el) {
	
	var newProgress;
	var divToDelete = el.parentNode.parentNode.parentNode;
	var divDelete = el.parentNode;
	
	//Remove the a href and image from the divDelete
	while(divDelete.hasChildNodes()){
			divDelete.removeChild(divDelete.childNodes[0])
	}

	newProgress = document.createElement("img");
	
	//Create a new Ajax progress indicator
	newProgress.src = "/web/images/furniture/scrapbook/indicator_white.gif"; 	
	YAHOO.util.Dom.setStyle(newProgress, 'left', "54px"); 	
	YAHOO.util.Dom.setStyle(newProgress, 'outline', "none"); 	
	YAHOO.util.Dom.setStyle(newProgress, 'width', "16px"); 	
	YAHOO.util.Dom.setStyle(newProgress, 'height', "16px"); 	
	YAHOO.util.Dom.setStyle(newProgress, 'margin-top', "4px"); 
	
	//Put the indicator in the delete div	
	divDelete.appendChild(newProgress);

	var projDelCallback =
		{
		  success: function(o) {
			// Delete the colour chip passed as o.argument from the array of chips
			var divToDelete = document.getElementById(o.argument);
	
			while(divToDelete.hasChildNodes()){
				divToDelete.removeChild(divToDelete.childNodes[0])
			}
			
			YAHOO.util.Dom.setStyle(divToDelete, 'visibility', 'hidden');
			
		},
		
		  failure: function(o) {alert("Could not delete this room.");},
		  argument: [divToDelete.id]
		}
	
	var sUrl="";
	var sArgs="";
	sUrl="/servlet/OwnRoomsHandler";
	sArgs="action=delete&successURL=/ajax/response.jsp&failURL=/ajax/response.jsp&imagecode="+id;
	
	var transaction = YAHOO.util.Connect.asyncRequest('POST', sUrl, projDelCallback, sArgs);

}
	
	
YAHOO.util.Event.addListener(window, 'load', YAHOO.dulux.co.uk.startList);
YAHOO.util.Event.addListener(window, 'load', YAHOO.dulux.co.uk.initScrapbook);
YAHOO.util.Event.onDOMReady(YAHOO.dulux.co.uk.initRollovers);
  
  
  

function jumpMenu(){
location=document.jump.menu.options[document.jump.menu.selectedIndex].value;
}


function popvis(page) {
OpenWin = this.open(page, "CtrlWindow", "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width=800,height=620");
}

YAHOO.namespace("dulux.co.uk.Flash");
/**
 * @namespace The contains methods to control and write Flash objects.
 */
YAHOO.dulux.co.uk.Flash = {
	_baseUrl: "/web/flash/",
	_supportedVersion: 7,
	_flashVersion: null,
	_defaultVars: {
	},
	_defaultParams: {
		"quality": "high",
		"pluginspage": "http://www.macromedia.com/go/getflashplayer",
		"wmode": "transparent"
	},
	/**
	 * Detect the protocol used in the browser to prevent security errors.
	 *
	 * @private
	 * @returns {String} The protocol currently used.
	 */
	_getProtocol: function() {
		var protocol = "https:";
		if (location.protocol.toLowerCase() === protocol) {
			return protocol;
		} else {
			return "http:";
		}
	},
	/**
	 * Browser sniff :( the Flash version.
	 *
	 * @private
	 */
	_getVersion: function() {
		/* detect which version of Flash installed, either  */
		this._flashVersion = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
		if (this._flashVersion) {
			this._flashVersion = parseInt(this._flashVersion.description.substring(this._flashVersion.description.indexOf(".")-2));
		} else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && navigator.userAgent.indexOf("Windows")>=0 ) {
			document.write('<script language=VBScript>\n');
			document.write('Dim hasPlayer, version\n');
			document.write('hasPlayer = false\n');
			document.write('version = 10\n');
			document.write('Do While version > 0\n');
			document.write('On Error Resume Next\n');
			document.write('hasPlayer = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & version)))\n');
			document.write('If hasPlayer = true Then Exit Do\n');
			document.write('version = version - 1\n');
			document.write('Loop\n');
			document.write('is_FlashVersion = version\n');
			document.write('is_Flash = hasPlayer\n');
			document.write('<\/script>\n');		
			if (version > 0) {
				this._flashVersion = version;
			}
		}
	},
	/**
	 * Get the Flash version once.
	 *
	 * @private
	 * @returns {Boolean} If the Flash version installed on the users machine can support the flash used on the site.
	 */
	_detect: function() {
		if (this._flashVersion === null) {
			this._getVersion();
			var css = [
				"<style type=\"text/css\"><!--",
				".noFlash {position: absolute; left: -999em;}",
				'--><\/style>'
			];
			document.write(css.join(""));
		}
		return (this._flashVersion >= this._supportedVersion); 
	},
	/**
	 * This can be called from the page and the Flash object will be written in place.
	 *
	 * @param {String} movie			The name of the Flash file to use without the file extension or directory.
	 * @param {Integer} width			The width of the Flash object.
	 * @param {Integer} height			The height of the Flash object.
	 * @param {String} [flashVars]		Flash variable value.
	 * @param {Integer} [minVersion]	The version of the Flash file.
	 */
	write: function(movie, width, height, flashVars, minVersion) {
		if ((minVersion && this._supportedVersion >= minVersion) || this._detect()) {
			var protocol = this._getProtocol();
			document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="' + protocol + '//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+this._supportedVersion+',0,0,0" ');
			document.write('width="'+width+'" height="'+height+'" id="visualiser">');
			document.write('<param name="movie" value="'+this._baseUrl+movie+'.swf?' + flashVars + '">');
			document.write('<param name="allowScriptAccess" value="sameDomain" />');
			document.write('<param name="wmode" value="transparent">');
			document.write('<embed src="'+this._baseUrl+movie+'.swf?' + flashVars + '" name="visualiser" width="'+width+'" height="'+height+'" ');
			document.write('wmode="transparent" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="' + protocol + '//www.macromedia.com/go/getflashplayer">');
			document.write('<\/object>');
		}
	},
	write2: function(movie, width, height, vars, param, version) {
		
	},
	/**
	 * This can be placed in the HEAD tag to be called to replace an HTML container without using the NOSCRIPT tag option and uses the SWFObject plugin.
	 *
	 * @requires SWFObject
	 * @param {String} el The container to replace.
	 */
	embed: function(move, el, width, height, vars, params, version) {
		var fVars = vars || this._defaultVars;
		var fParams = params || this.defaultParams;

		if (typeof swfobject !== "undefined") {
			swfobject.embedSWF(move, el, width, height, version, null, fVars, fParams);
		}
	},
	/**
	 * Safely removes a Flash movie from the page.
	 * @param {String} el Flash placeholder.
	 */
	remove: function(el) {
		swfobject.removeSWF(el);
	}
};

YAHOO.namespace("dulux.co.uk.Modal");

YAHOO.dulux.co.uk.Modal = {
	Flash: {	
		_modal: null,
		render: function(width, height, header) {
			var panel, hd, bd, ft;	
			
			if (this._modal) {
				this._modal.destroy();
			}

			panel = document.createElement("div");
			panel.id = "dulux-modal-flash";
			panel.className = "yui-panel-container yui-dialog shadow";

			hd = document.createElement("div");
			hd.className = "hd";

			bd = document.createElement("div");
			bd.className = "bd";

			ft = document.createElement("div");
			ft.className = "ft";

			panel.appendChild(hd);
			panel.appendChild(bd);
			panel.appendChild(ft);
			document.body.appendChild(panel);
			
			this._modal = new YAHOO.widget.Panel("dulux-modal-flash", { 
				width: (width + 38) + "px",
				height: (height + 86) + "px",
				fixedcenter : true,
				modal: true,
				visible : false, 
				close: true,
				constraintoviewport: true,
				zIndex: 1100,
				autofillheight: "body"
			});
		
			
			this._modal.setHeader(header);
			this._modal.setBody("<div id=\"dulux-modal-flash-movie\">Flash plugin is required to view \"" + header + "\".</div>");
			this._modal.render();
			this._modal.show();		
			this._modal.hideEvent.subscribe(function() {
				// This is to remove the Flash movie
				YAHOO.dulux.co.uk.Flash.remove("dulux-modal-flash-movie");
			});	
		},
		movie: function(e, flashName, width, height, vars, params, version) {		
			var ver = version || "8.0.0.",		
				height = height || 400,
				width = width || 400;			

			this.render(width, height, e.title || "");

			YAHOO.dulux.co.uk.Flash.embed(flashName, "dulux-modal-flash-movie", width, height, vars, params, ver);

			return false;
		},
		video: function(e, stream, width, height, vars, params, version) {
			var ver = version || "8.0.0.",		
				height = height || 339,
				width = width || 534;	

			this.render(width, height, e.title || "");

			var vars = {
				"MM_ComponentVersion": "1",
				"skinName": "/web/video/Halo_Skin_3",
				"streamName": "/web/video/" + stream,
				"autoPlay": "false",
				"autoRewind": true
			};

			var params = {
				"quality": "high",
				"scale": "noscale",
				"pluginspage": "http://www.macromedia.com/go/getflashplayer",
				"wmode": "transparent"
			};
			
			YAHOO.dulux.co.uk.Flash.embed("/web/video/FLVPlayer_Progressive.swf", "dulux-modal-flash-movie", width, height, vars, params, ver);

			return false;
		}
	}
};



YAHOO.namespace("dulux.co.uk.Color.TailorMade");

/**
 * TailorMade functionality for the Colour section.
 */
YAHOO.dulux.co.uk.Color.TailorMade = {
	_modal: null,
	/**
	 * Create a modal box with the Flash video content.
	 * @param {HTMLObject} e The HREF to the flash video.
	 * @param {String} steam Name of the FLV to stream in the Flash player
	 * @return {Boolean} Returns FALSE to prevent default link action.
	 */
	video: function(e, stream) {
		if (this._modal === null || !document.getElementById("tailor-made-color-panel")) {
			var panel = document.createElement("div");
			panel.id = "tailor-made-color-panel";
			panel.className = "yui-panel-container yui-dialog shadow";

			var hd = document.createElement("div");
			hd.className = "hd";

			var bd = document.createElement("div");
			bd.className = "bd";

			var ft = document.createElement("div");
			ft.className = "ft";

			panel.appendChild(hd);
			panel.appendChild(bd);
			panel.appendChild(ft);
			document.body.appendChild(panel);
			
			this._modal = new YAHOO.widget.Panel("tailor-made-color-panel", { 
				width: "572px",
				height: "425px",
				fixedcenter : true,
				modal: true,
				visible : false, 
				close: true,
				constraintoviewport: true,
				zIndex : 1100  
			});
		}

		this._modal.setHeader(e.title);
		this._modal.setBody("<div id=\"tailor-made-color-movie\">Flash required for viewing \"" + e.title + "\".</div>");
		this._modal.render();
		this._modal.show();		
		this._modal.hideEvent.subscribe(function() {
			// This is to remove the Flash movie
			YAHOO.dulux.co.uk.Flash.remove("tailor-made-color-movie");
		});		

		var vars = {
			"MM_ComponentVersion": "1",
			"skinName": "/web/video/Halo_Skin_3",
			"streamName": "/web/video/" + stream,
			"autoPlay": "false",
			"autoRewind": true
		};

		var params = {
			"quality": "high",
			"scale": "noscale",
			"pluginspage": "http://www.macromedia.com/go/getflashplayer",
			"wmode": "transparent"
		};

		YAHOO.dulux.co.uk.Flash.embed("/web/video/FLVPlayer_Progressive.swf", "tailor-made-color-movie", 534, 339, vars, params, "8.0.0");

		
		UKISA.Sitestat.hit("video.colouradvice." + stream);

		return false;
	}
};

var UKISA = UKISA || {};
UKISA.Sitestat = {
	/**
	 * Make a call to the Sitestat server to register a page view.
	 */
	hit: function(qs) {
		var url, ns_0, ns_pixelUrl;

		// This checks that the site is "live" as is must have the sitestat function.
		// This stops polluting the stats with UAT data.

		if (typeof sitestat === "function") {

			url = "http://int.sitestat.com/ici-paints/dulux-ie/s?" + qs;

			url += "&amp;ns__t=" + (new Date()).getTime();
			ns_pixelUrl = url;
			ns_0 = document.referrer;
			ns_0 = (ns_0.lastIndexOf("/") == ns_0.length - 1) ? ns_0.substring(ns_0.lastIndexOf("/"), 0) : ns_0;

			if(ns_0.length > 0) {
				url += "&amp;ns_referrer=" + escape(ns_0);
			}
			if(document.images){
				ns_1 = new Image();
				ns_1.src = url;
			} else {
				document.write('<img src="' + url + '" width="1" height="1" alt="" class="tracking" style=\"display: none;\" />');
			}
			
		}
	}
};