/*IE5.0 ARRAY PROTOTYPE PUSH*/

if(typeof Array.prototype.push==="undefined"){
	Array.prototype.push=function(){
		for(var i=0;i<arguments.length;i++){
			this[this.length+i]=arguments[i];
			return this.length;
		}
	}
}
/* Pop-up windows */
function openPopup(href)
{
	var rand="window"+Math.floor(Math.random()*9999999999);
	var newWin = window.open(href,rand,"width=600,height=500,titlebar=no,scrollbars=yes");
	newWin.focus();
	return false;
}
function popup(){
	var els=LBI.Common.fuzzyClassName("a","popup:");
	for (var i=0;i<els.length;i++)	{
		els[i].onclick = function ()
		{
			this.removeAttribute("target");
			var cc=this.className;var cs=cc.substr(cc.indexOf("popup:")+6,cc.length);
			// QAS variant specifically for this process
			if (cs.indexOf("qas")===0) {
				var dma=(cs.substr(4,cs.indexOf(")")-1)).split(",");
				// get fields
				var grandparent=LBI.Common.getParentByTagName(this.parentNode,"div");
				var supp=(grandparent.id==="id_div_sec2")?"_sec2":"";
				window.QAS_opener=(supp==="")?"_sec1":"_sec2";
				var postcode=document.getElementById(window.VF_postcode+supp).value;
				var house=document.getElementById(window.VF_house+supp).value;
				var extras="?postcode="+postcode+"&house="+house;
			}	else	{
				var dma=(cs.substr(1,cs.indexOf(")")-1)).split(",");
				var extras="";
			}
			window.open(this.href+extras,'popupwindow','width='+dma[0]+',height='+dma[1]+',resizable=1,scrollbars=1,true,true');
			return false;
		}
	}
}
/* End Pop-up windows */
/*Input button rollover*/

function addHoverToInputImage(){
	$("input.hasRollOver").hover (
		function(){
			$(this).addClass('hover');
		},
		function(){
			$(this).removeClass('hover');
		}
	);
}

function formClear() {
	var inputFields = $("input:text");
	for (i=0; i<inputFields.length; i++) {
		var thisField = inputFields[i];
		var defaultValue = thisField.value;
		thisField.onfocus = function() {
			if (this.value === this.defaultValue) {
				this.value = "";
			}
		}
		thisField.onblur = function() {
			if (this.value == "") {
				this.value = this.defaultValue;
			}
		}
	}			
};


/*########################################################################################################*/
/* SUPPORTING FUNCTIONS */
// returns an array of elements withing the wrapping element oElm, of the tag type strTagName (or wildcard), with the classname strClassName
//UPDATED 2007-08-21, DB. Added in 2 replace commands to escape ( and )
//UPDATED 2008-09-12, TB. Replaced with added xpath and native function use

function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName === "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = [];
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];		
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}	
	}
	return (arrReturnElements);
}

/* END SUPPORTING FUNCTIONS */
/********** GENERAL DOM FUNCTIONS END **********/

/* LEGACY CODE */

/*LIGHTBOX
	a lightbox is a box of content that sits above the main area, which is usually faded out
	designed as an object because validation needs to access some of its functions.
	setting up the tint bg element at init phase works around a obscure IE bug
	REQUIRED:
		class 'PE_lightBox'  (NB case-sensitive) on the div to become a lightbox, this area must also have an id
		class 'PE_lightboxOpen(id_of_lightbox)' on the anchor that triggers the lightbox if triggered by a link
		class 'PE_lightboxIfInvalid(id_of_lightbox)' on the div with the PE_validate() class if the lightbox is triggered by an invalid field (see validate section comments for further details)
	UPDATE : 12.10.08 
		lightbox will now read if it is to load in a flash video player by reading the format of the href of the link that fires it.
		When this happens it takes the Heading text from the link title and the format from an additional class:
			'F_(large)' or 'F(small)'
		It will also use this information to size the content div to the dimensions selected and the flash will be loaded after the lightbox appears.		
*/
Lightbox = {
	active : 0,
	height: 0,
	init : function(){
		var lightboxes = LBI.Common.fuzzyClassName("div","PE_lightBox");
		var lightboxLinks = LBI.Common.fuzzyClassName("a","PE_lightboxOpen");
		for(var i=0;i<lightboxes.length;i++){
			var lightboxContainer = LBI.Common.getParentByTagName(lightboxes[0],"form");
			if(!lightboxContainer){lightboxContainer = document.getElementById("Page")};
			lightboxes[i].style.visibility = "visible";  //remove styles from IE foc prevention
			//take out of position in HTML and insert at end of page, necessary for placing above the tinted background in IE

			var lightbox = lightboxes[i].parentNode.removeChild(lightboxes[i]);
			lightboxContainer.appendChild(lightbox);
			lightbox.className += " hasJS";
			Lightbox.hideLightbox(lightbox);
			Lightbox.addBoxStyles(lightbox);
			Lightbox.addBoxClose(lightbox);
			Lightbox.closeKey(lightbox);
		}
		Lightbox.active = 0;
		Lightbox.setUpTintBg();
		var hasFlash = false;
		for(var h=0;h<lightboxLinks.length;h++){
			lightboxLinks[h].className = lightboxLinks[h].className.replace("hidden","");
			//Added for flash holder lightboxes generated off a link			
			lightboxLinks[h].onclick=function(){
				
				hasFlash = (Lightbox.testForFlash(this) === true) ? true : false;				
				var thisLightbox = document.getElementById(LBI.Common.getPEClassInfo(this,"PE_lightboxOpen"));
				var trackingRef = LBI.Common.getPEClassInfo(this,"T_");
				//Added for flash holder lightboxes
					if (hasFlash === true) {
						if($(".videoText").length !== 0){
							var videoText = $(".videoText", this).text();
						}
						else{
							var videoText = "";
						}
						
						thisLightbox = Lightbox.createFlashLightbox(this, videoText);					
					}
					if(typeof thisLightbox === "undefined") {
						alert("DEV ERROR: no element with ID specified in link's class");
						return;						
					}
				if(hasFlash === true) {
					Lightbox.showLightbox(thisLightbox, this);
				} else {
					Lightbox.showLightbox(thisLightbox);	
				}
				Lightbox.tintBg(trackingRef);
				return false;
			}
		}		
		//lightbox on page load - this should be the last part of init()
		if(location.hash.indexOf("lightbox_") != -1){
			var thisLightbox = document.getElementById(location.hash.replace("#",""));
			if(!thisLightbox){return;}
			Lightbox.showLightbox(thisLightbox);
			Lightbox.tintBg();
		}
	},
	createFlashLightbox : function(elem_lightboxLink, accessText) {
		var lightboxId = LBI.Common.getPEClassInfo(elem_lightboxLink,"PE_lightboxOpen");
		var lightboxHead = (elem_lightboxLink.href.indexOf(".flv") !== -1) ? elem_lightboxLink.title : "";
		var flashHolder = document.createElement("div");		
		flashHolder.id = lightboxId + "_fla";
		var flashType = LBI.Common.getPEClassInfo(elem_lightboxLink,"F_");		
		flashHolder.style.height = LBI.Data.flashType[flashType].height + "px";
		flashHolder.style.width = LBI.Data.flashType[flashType].width + "px";
		
		var textVideo = document.createTextNode(accessText);
		return Lightbox.create(lightboxHead, flashHolder, lightboxId, elem_lightboxLink, textVideo);

	},
	testForFlash : function(elLink) {
		if((elLink.href.indexOf(".swf") !== -1) || (elLink.href.indexOf(".flv") !== -1)) { 
			return true;
		} else {
			return false;	
		}		
	},
	/*dynamically creates a lightbox.
	takes either a string or node object for headNode and contentNode and a string for id*/
	create: function(headNode,contentNode,id,flashRef, videoTextDesc){
		var lightbox = document.createElement("div");
			lightbox.className = "lightBox PE_lightBox";
			//If no flash, lightbox will exist in markup so build from there
					var i=0;
					while(document.getElementById(id)){
						i++;
						var lastUScore = id.lastIndexOf("_");
						var ind = id.substring(lastUScore+1);
						if(parseInt(ind)){
							id = id.substring(0,lastUScore+1) + i;
						}
						else{
							id = id + "_" + i;
						}
				}

			lightbox.id = id;
		var lightboxHead = document.createElement("div");
			lightboxHead.className = "heading";
			if(typeof(headNode) === "string"){
				headNode = document.createTextNode(headNode);
			}
			lightboxHead.appendChild(headNode);
		var lightboxContent = document.createElement("div");
			lightboxContent.className = "content";
			if(typeof(contentNode) === "string"){
				contentNode = document.createTextNode(contentNode);
			}
		
		var accessibleCont = document.createElement("p");
			accessibleCont.className = "videoText";
			accessibleCont.appendChild(videoTextDesc)
		
		lightboxContent.appendChild(contentNode);
		lightboxContent.appendChild(accessibleCont);
		lightbox.appendChild(lightboxHead);											
		lightbox.appendChild(lightboxContent);							

		lightbox.className += " hasJS";
		Lightbox.hideLightbox(lightbox);
		Lightbox.addBoxStyles(lightbox);
		
		if (flashRef !== undefined) {
			Lightbox.addBoxClose(lightbox, true);
			Lightbox.closeKey(lightbox, true);
			var flashType = LBI.Common.getPEClassInfo(flashRef,"F_");			
			lightbox.style.width = (LBI.Data.flashType[flashType].width + 28) + "px";
			var lightboxTop = getElementsByClassName(lightbox, "div", "lightbox-top")[0];
			var lightboxBase = getElementsByClassName(lightbox, "div", "lightbox-base")[0];			
			lightboxTop.style.width = (LBI.Data.flashType[flashType].width + 12) + "px";
			lightboxBase.style.width = (LBI.Data.flashType[flashType].width + 12) + "px";
		} else { Lightbox.addBoxClose(lightbox);}
		var pageDiv = document.getElementById("Page");
		pageDiv.appendChild(lightbox);
		lightbox.style.visibility = "visible";  //remove styles from IE foc prevention
		return lightbox;
	},
	addBoxStyles : function(elem_lightbox){
		//middle - take all children of lightbox and put them into the boxRight div
		var boxRight = document.createElement("div");
			boxRight.className = "lightbox-right";
		while(elem_lightbox.childNodes.length > 0){			
			boxRight.appendChild(elem_lightbox.lastChild);
		}		
		var boxMain = document.createElement("div");
			boxMain.className = "lightbox-main";
			boxMain.appendChild(boxRight);
		elem_lightbox.appendChild(boxMain);
		//top
		var boxTop = document.createElement("div");
			boxTop.className = "lightbox-top"
		var boxTopLeft = document.createElement("div");
			boxTopLeft.className = "lightbox-top-left";
		var boxTopRight = document.createElement("div");
			boxTopRight.className = "lightbox-top-right";
			boxTopLeft.appendChild(boxTopRight);
			boxTopLeft.appendChild(boxTop);
			elem_lightbox.insertBefore(boxTopLeft,elem_lightbox.firstChild);
		//base
		var boxBase = document.createElement("div");
			boxBase.className = "lightbox-base";
		var boxBaseLeft = document.createElement("div");
			boxBaseLeft.className = "lightbox-base-left";
		var boxBaseRight = document.createElement("div");
			boxBaseRight.className = "lightbox-base-right";
			boxBaseLeft.appendChild(boxBaseRight);
			boxBaseLeft.appendChild(boxBase);
			elem_lightbox.appendChild(boxBaseLeft);
	},
	closeLightbox : function(elem_lightbox, isFlash){
		//Added for flash holder lightboxes generated off a link - element needs to be completely removed as cannot run invisibly
		if(isFlash === true) {
			Lightbox.active--;		
		} else {
			
			Lightbox.rehideLightbox(elem_lightbox);
		}
		if(elem_lightbox.className.indexOf("f(") !== -1) {

			var format = this.getFormat(elem_lightbox);			
			if (LBI.Data.flashType[format].eventOnClose === true) {
				LBI.Data.fireOnEvent[format].off();
			}
		}
		Lightbox.removeTintBg();
		//accessibility aid: refocus on the link or validated field that triggered the lightbox
		var lightboxTrigger = LBI.Common.fuzzyClassName("a","PE_lightboxOpen(" + elem_lightbox.id + ")")[0];
		if(!lightboxTrigger){
			var lightboxDiv = LBI.Common.fuzzyClassName("div","PE_lightboxIfInvalid(" + elem_lightbox.id + ")")[0];
			if(lightboxDiv){lightboxTrigger = lightboxDiv.getElementsByTagName("input")[0];}
		}
		if(lightboxTrigger){lightboxTrigger.focus();}
		if(isFlash === true) {
			LBI.Common.removeNodeByObj(elem_lightbox);			
		}
		return false;
	},
	addBoxClose : function(elem_lightbox, hasFlash){
		var closeLinkTxt = document.createTextNode("Close");
		closeLink = document.createElement("a");
		closeLink.href = "#";
		closeLink.id = "close_" + elem_lightbox.id;
		closeLink.className = "closeBtn clearfix";
		closeLink.appendChild(closeLinkTxt);
		closeLink.onclick = function(){
			if(hasFlash === true) {
				Lightbox.closeLightbox(elem_lightbox, true);				
			} else {
				Lightbox.closeLightbox(elem_lightbox);				
			}
			return false;
		}
		
		var lightboxHeading = getElementsByClassName(elem_lightbox,"*","heading")[0];
		lightboxHeading.insertBefore(closeLink,lightboxHeading.firstChild);
		lightboxHeading.className += " clearfix";
		//accessibility aid: add hidden close at bottom of lightbox
		var closeLinkHidden = document.createElement("a");
			closeLinkHidden.appendChild(document.createTextNode("End of in page popup. Close using this link to return to main content."));
			closeLinkHidden.href = "#";
			closeLinkHidden.className = "hidden";
			closeLinkHidden.onclick = closeLink.onclick;
		elem_lightbox.appendChild(closeLinkHidden);
		elem_lightbox.closeButtons = [closeLink,closeLinkHidden];
		//detect cancel buttons in HTML and use those too
		var cancelLinks = LBI.Common.fuzzyClassNameBlock(elem_lightbox,"a","PE_closeLightbox");
		for(var i=0;i<cancelLinks.length;i++){
			cancelLinks[i].onclick = closeLink.onclick;
			elem_lightbox.closeButtons.push(cancelLinks[i]);
		}
	return false;		
	},
	
	closeKey: function(elem_lightbox, hasFlash){
		document.onkeydown = function(e){   
			if (e == null) { // ie
			  keycode = event.keyCode;
			} else { // mozilla
			  keycode = e.which;
			}
			if(keycode == 27){ // close
			  if(hasFlash === true) {
					Lightbox.closeLightbox(elem_lightbox, true);
					//Lightbox.hideLightbox(elem_lightbox);
				} else {
					Lightbox.closeLightbox(elem_lightbox);
					var lightboxes = $(".lightBox");
					
					for (i=0; i<lightboxes.length ;  i++ ){
						$(lightboxes[i]).removeClass("hideLightbox");
						$(lightboxes[i]).addClass("hideLightbox");
					}
				}						
			}  
		}
	 },

	setUpTintBg : function(){
		/*@cc_on @*/
		/*@if (@_jscript_version < 5.6)
			return; // impossible in IE5
		/*@end @*/
		var pageDiv = document.getElementById("Page");
		var tint = document.createElement("div");
		tint.className = "tintedBg";
		pageDiv.insertBefore(tint,pageDiv.firstChild);
	},
	tintBg : function(refTrack){
		if(Lightbox.hasCSS() === false){return;}
		var tint = getElementsByClassName(document,"div","tintedBg")[0];
		if(!tint){return;}
		tint.style.height = "0px";
		var pageDimensions = LBI.Common.getFullPageDimensions();
		var newWidth = pageDimensions[0];
		var newHeight = pageDimensions[1];
		if(Lightbox.height > newHeight){
			tint.style.height = Lightbox.height +"px";
		}
		else{
			tint.style.height = newHeight +"px";
		}
		tint.style.width = newWidth +"px";
		
		if(refTrack!== undefined){
			if(refTrack == "dropdown"){
				NEWFLOOD_drop();
			}
			else if(refTrack == "footer"){
				NEWFLOOD_foot()
			}
		}
	},
	removeTintBg : function(){
		if(Lightbox.active > 0){return;}
		var tint = getElementsByClassName(document,"div","tintedBg")[0];
		if(!tint){return;}
		tint.style.width = "0px";
		tint.style.height = "0px";
	},
	showLightbox : function(elem_lightbox, flashRef){		
		if(LBI.Common.isLtIE7 === true){
			Lightbox.hideSelects(elem_lightbox); //hide select boxes due to buggy IE6 handling of them
		}
		if(elem_lightbox.className.indexOf("f(") !== -1) {
			var format = this.getFormat(elem_lightbox);
			if (LBI.Data.flashType[format].addAsClass !== -1 && LBI.Data.flashType[format].addAsClass === true) {
				elem_lightbox.className += " " + format;
			}
			if (LBI.Data.flashType[format].eventOnOpen === true) {
				LBI.Data.fireOnEvent[format].on();
			}
		}		
		elem_lightbox.className = elem_lightbox.className.replace(/ hideLightbox/g,"");
		//set the lightbox in the vertical center of the page, account for relatively-positioned parents
		// if the lightbox is bigger than the viewport, set its top to the top of the viewable screen
		var viewPortCenter = Math.round(LBI.Common.getViewPortHeight() / 2);
		var viewPortMiddle = Math.round(LBI.Common.getViewPortWidth() / 2);		
		var scrolledTop = LBI.Common.getScrollTop();
		var userViewCenter = parseInt(viewPortCenter) + parseInt(scrolledTop);
		var userViewMiddle = parseInt(viewPortMiddle);		
		var lightboxCenter = elem_lightbox.offsetHeight / 2;
		var lightboxMiddle = elem_lightbox.offsetWidth / 2;
		var lightboxRelativeTop = 0;			
		var lightboxRelativeLeft = -170;		
		var parent = elem_lightbox.parentNode;
		while(parent){
			if(parent.nodeName==="#document"){break;}
			if(LBI.Common.getStyle(parent,"position") === "relative"){
				lightboxRelativeTop += parent.offsetTop;
			}
			parent = parent.parentNode;
		}
		if(LBI.Common.getViewPortHeight() < elem_lightbox.offsetHeight){
			elem_lightbox.style.top = scrolledTop - lightboxRelativeTop + "px";
		}
		else{
			elem_lightbox.style.top = userViewCenter - lightboxCenter - lightboxRelativeTop + "px";			
		}		
		elem_lightbox.style.left = userViewMiddle - lightboxMiddle - lightboxRelativeLeft + "px";
		Lightbox.active++;
		Lightbox.height = parseInt(elem_lightbox.offsetHeight) + parseInt(elem_lightbox.offsetTop);
		//accessibility aid: send cursor to close button on the lightbox
		var closebtn = document.getElementById("close_" + elem_lightbox.id);
		var hiddenFocusLink = document.getElementById("hiddenFocus_" + elem_lightbox.id);
		if(!hiddenFocusLink){
			var hiddenFocusLink = document.createElement("a");
				hiddenFocusLink.href = "#";
				hiddenFocusLink.onclick = function(){return false;}
				hiddenFocusLink.id = "hiddenFocus_" + elem_lightbox.id;
				hiddenFocusLink.appendChild(document.createTextNode("In page pop-up layer.  Use close links to return to main content."));
			closebtn.parentNode.insertBefore(hiddenFocusLink,closebtn);
		}
		hiddenFocusLink.focus();	
		hiddenFocusLink.className = "hidden";
		if(flashRef !== undefined) {
			this.createFlashFromElm(elem_lightbox, flashRef);				
		}	
	
	},
	createFlashFromElm : function(elem_lightbox, linkElm) {
		var flashId = elem_lightbox.id + "_fla";					
		var flashType = LBI.Common.getPEClassInfo(linkElm,"F_");
		var height = LBI.Data.flashType[flashType].height + "px";
		var width = LBI.Data.flashType[flashType].width + "px";	
		var flashvars = {};
		if (linkElm.href.indexOf(".flv") !== -1) {
			flashvars.videoSource = linkElm.href;
			swfobject.embedSWF(LBI.Data.flashPlayer, flashId, width, height, "9.0.0", "expressInstall.html", flashvars, LBI.Data.videoOptions.params, LBI.Data.videoOptions.attributes);
		} else {
			var flashFile = linkElm.href;
			swfobject.embedSWF(flashFile, flashId, width, height, "9.0.0", "expressInstall.html");
		}
	},
	hideLightbox : function(elem_lightbox){
		if(LBI.Common.isLtIE7 === true){
			Lightbox.showSelects();
		}
		elem_lightbox.className += " hideLightbox";
		var hiddenFocusLink = document.getElementById("hiddenFocus_" + elem_lightbox.id);
		if(hiddenFocusLink){hiddenFocusLink.className = hiddenFocusLink.className.replace("hidden","");}
	},
	rehideLightbox : function(elem_lightbox){
		Lightbox.hideLightbox(elem_lightbox);
		Lightbox.active--;
	},
	//one for set up, one for show/hide
	//hide select boxes due to buggy IE<7 handling of them
	hideSelects : function(){
		var selects = document.getElementsByTagName("select");
		for(var i=0;i<selects.length;i++){
			selects[i].style.visibility = "hidden";
		}
	},
	showSelects : function(){
		var selects = document.getElementsByTagName("select");
		for(var i=0;i<selects.length;i++){
			selects[i].style.visibility = "visible";
		}
	},
	hasCSS : function(){
		var tintedBg = getElementsByClassName(document.body,"div","tintedBg")[0];
		if(LBI.Common.getStyle(tintedBg,"position") != "absolute"){
			return false;
		}
		return true;
	},
	getFormat : function(elem_lightbox) {
		var format = LBI.Common.getPEClassInfo(elem_lightbox,"f");
		if (format !== undefined) {
			if (LBI.Data.flashType[format].height !== undefined) {
				elem_lightbox.style.height = LBI.Data.flashType[format].height + "px";
			}
			if (LBI.Data.flashType[format].width !== undefined) {
				elem_lightbox.style.width = LBI.Data.flashType[format].width + "px";
			}
		}
		return format;
	}
}

/*PNG handling for inline images
based on supersleight.js
Edits:	took off setting for position relative on links
		Added a pngsToIgnore object to the Data object - png fix checks it for each object so we can use png8's (which don't need filtering)
*/
function pngHandling(wrapper){
var supersleight=function(){var root=wrapper;var applyPositioning=true;var shim=LBI.Data.pngFixPath + 't.gif';var shim_pattern=/t\.gif$/i;var fnLoadPngs = function(){if (root) {root = document.getElementById(root);}else {root = document;}if (!root) {return;}for (var i = root.all.length - 1, obj = null; (obj = root.all[i]); i--) {if(LBI.Data.pngsToIgnore.check(obj) === false) {if (obj.currentStyle.backgroundImage.match(/\.png/i) !== null) {bg_fnFixPng(obj);}if (obj.tagName === 'IMG' && obj.src.match(/\.png$/i) !== null) {el_fnFixPng(obj);if (applyPositioning && (obj.tagName === 'A' || obj.tagName === 'INPUT') && obj.style.position === '') {obj.style.position = 'relative';}}}}};var bg_fnFixPng=function(obj){var mode='scale';var bg=obj.currentStyle.backgroundImage;var src=bg.substring(5,bg.length-2);if(obj.currentStyle.backgroundRepeat==='no-repeat'){mode='crop';}
obj.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"', sizingMethod='"+mode+"')";obj.style.backgroundImage='url('+shim+')';};var el_fnFixPng=function(img){var src=img.src;img.style.width=img.width+"px";img.style.height=img.height+"px";img.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"', sizingMethod='scale')";img.src=shim;};return{init:function(){fnLoadPngs();},run:function(){fnLoadPngs();},limitTo:function(el){root=el;}};}();
if(LBI.Common.isLtIE7 === true){
	supersleight.init();
	}
}


//finds all inputs and adds a hover class when rolled over
function setupInputHover() {

	var inputs = document.getElementsByTagName("input");

	for (var i = 0; i < inputs.length; i++) {
		inputs[i].onmouseover = function() {
			this.className += " hover";
		}
		inputs[i].onmouseout = function() {
			this.className = this.className.replace("hover","");
		}
	}	

}

LBI = {};

LBI.Data = {
	bunCompareXML : "../consumer/consumerProducts/js/bundling/",
	bbCompareXML : "../consumer/consumerProducts/js/internet/",
	tariffsXML : "../consumer/consumerProducts/js/home_phone_services/",
	dsoXML : "../consumer/consumerProducts/js/entertainment/",
	jsonPath : "../consumer/consumerProducts/js/entertainment/",
	libPath : "../consumer/consumerProducts/images/products_and_services/entertainment/",
	commonImgPath : "../consumer/consumerProducts/common/products_and_services/",
	visionImgPath : "../consumer/consumerProducts/images/products_and_services/entertainment/",
	bundlingImgPath : "../consumer/consumerProducts/images/products_and_services/bundling/",
	pngFixPath : "../consumer/consumerProducts/common/products_and_services/",
	videoWidth : 640,
	extSrcExt : ".js",
	flashPath : "http://172.27.64.38/consumer/consumerProducts/flash/entertainment/",
	videoPath : "http://172.27.64.38/consumer/consumerProducts/flash/entertainment/videos/",
	flashPlayer : "../consumer/consumerProducts/flash/entertainment/BTVideoPlayer.swf",
	flashPlayerNew : "../consumer/consumerProducts/flash/entertainment/BTVideoPlayer_new.swf",
	flashPlayer01 : "../consumer/consumerProducts/flash/entertainment/BTVideoPlayer_01.swf",
	flashExt : ".swf",
	menuSections : ["packages", "phone", "bb", "vision"],
	flashType : {
		large : {
			height : 480,
			width : 640
		},
		small : {
			height : 360,
			width : 640
		},		
		tiny : {
			height : 240,
			width : 400,
			addAsClass : true
		},
		overview : {
			width : 967,
			addAsClass : true,
			eventOnOpen : true,
			eventOnClose : true
		},
		homehub : {
			height : 553,
			width :  940,
			addClass : true
		},
		visionHub : {
			height : 270,
			width :  480
		}
	},
	videoOptions : {
		params : {allowScriptAccess : "sameDomain"},
		attributes : null
	},
	pageVideoOptions : {
		params : {allowScriptAccess : "sameDomain", wmode: "transparent", allowFullScreen: "true"},
		attributes : null
	},
	flashDimensions: {
		Reviews: {
			height: "91",
			width: "250",
			params: {
				wmode: "Transparent"
			}
		},
		Preview: {
			height: "168",
			width: "300",
			params: {
				wmode: "Transparent"
			}
		},
		ball: {
			height: "310",
			width: "940"
		},
		bthomepageanim: {
			height: "254",
			width: "978",
			flashVars: {
				videoURL: "http://172.27.64.38/consumer/consumerProducts/flash/entertainment/videos/BT_vision.flv",
				videoXPos: "20",
				videoYPos: "4",
				swfURL: "http://172.27.64.38/consumer/consumerProducts/flash/entertainment/swf/homepageAnim.swf",
				swfXPos: "120",
				swfYPos: "38",
				imgStartURL: "http://172.27.64.38/consumer/consumerProducts/images/products_and_services/entertainment/start_screen.jpg",
				imgCompleteURL: "http://172.27.64.38/consumer/consumerProducts/images/products_and_services/entertainment/end_screen.jpg"
			},
			expressInstall: "expressInstall.swf"
		}
	},
	pngsToIgnore: {
		list: [],
		add: function(elmIgnore){
			this.list.push(elmIgnore);
		},
		check: function(elmToCheck){
			var noMatches = 0;
			for (var a = 0, b = this.list.length; a < b; a++) {
				if (this.list[a] === elmToCheck) {
					noMatches = noMatches + 1;
				} 				
			}
			if (noMatches === 0) {
				return false;
			} else {
				return true;
			}
		}
	},
	fireOnEvent : {
		overview : {
			on : function(){
				LBI.Custom.PEList.PE_sequencer.instLib[0].freezeAnim();
			},
			off : function() {
				LBI.Custom.PEList.PE_sequencer.instLib[0].restartAnim();
			}
		}
	}
}



LBI.Common = {
	isLtIE7 : false,
    detectLtIE7 : function() {
        var getIEMajorVersion = function() {
            if(navigator.appName === "Microsoft Internet Explorer"){
                var regExp = /MSIE\s(\d+)\./gi;
                var testUA = regExp.exec(navigator.userAgent);
                return testUA[1];
            }else{
                return false;
            }
        }
        var IEVersion = getIEMajorVersion();		
        if (IEVersion && IEVersion < 7) {
            this.isLtIE7 = true;
        }else {
            this.isLtIE7 = false;
        }
    },
	addDecimal : function(objOpt) {
		var places = [10, 100, 1000];
		var multi = places[(objOpt['places'] - 1)];
		if (objOpt['action'] === 'add') {
			result = parseInt((objOpt['item1'] * multi) + (objOpt['item2'] * multi), 10) / multi;
		} else {
			result = parseInt((objOpt['item1'] * multi) - (objOpt['item2'] * multi), 10) / multi;
		}
		return result;
	},
	objOpacity :  {
		set : function(elm, opacity) {
			$(elm).css({ 'opacity' : opacity});						
		},
		get : function(elm) {
			if(elm.filters !== undefined) { 
				return (elm.filters.alpha) ?  (elm.filters.alpha.opacity / 100) : 1;
			} else {
				return $(elm).css( 'opacity' );
			};			
		}
	},
	//get events, cross browser
	readEvent : function(oEvent, prop) {
		if(!oEvent) { var oEvent = window.event; }
		if(prop === "eventObj") { return oEvent; }
		if(prop === "target") {
			return (oEvent.target !== undefined) ? oEvent.target : oEvent.srcElement;
		}
	},
	//handle cross-browser reading of CSS-set styles
	getStyle : function(el,stylename){
		if(el.style[stylename]){
			return el.style[stylename];
		}
		else if(el.currentStyle){
			//handle IE's style-name to styleName convention
			if(stylename.indexOf("-") != -1 && !el.currentStyle[stylename]){
				//get 1st char after -, uppercase, rem -
				var preHyphen = stylename.substr(0,stylename.indexOf("-"));
				var postHyphenFirstLetter = stylename.substr(stylename.indexOf("-")+1,1).toUpperCase();
				var postHyphenRemainder = stylename.substr(stylename.indexOf("-")+2);
				stylename = preHyphen + postHyphenFirstLetter + postHyphenRemainder;
			}
			return el.currentStyle[stylename];
		}
		else if(document.defaultView && document.defaultView.getComputedStyle){
			return document.defaultView.getComputedStyle(el,null).getPropertyValue(stylename);
		}
		else{return false;}
	},
	//handle cross-browser viewport height
	getViewPortHeight : function(){
		if(window.innerHeight){
			return window.innerHeight;
		}
		else if(document.documentElement && document.documentElement.clientHeight){
			return document.documentElement.clientHeight;
		}
		else if(document.body){
			return document.body.clientHeight;
		}
		else{return false;}
	},
	//handle cross-browser viewport width
	getViewPortWidth : function(){
		if(window.innerWidth){
			return window.innerWidth;
		}
		else if(document.documentElement && document.documentElement.clientWidth){
			return document.documentElement.clientWidth;
		}
		else if(document.body){
			return document.body.clientWidth;
		}
		else{return false;}
	},
	//find and compare viewport and body heights and widths. return the largest of each dimension in array
	getFullPageDimensions : function(){
		var newHeight = LBI.Common.getViewPortHeight();
		var newWidth  = LBI.Common.getViewPortWidth();
		/*compare with body */
		if(newWidth < document.body.clientWidth){
			newWidth = document.body.clientWidth;
			newWidth += parseInt(LBI.Common.getStyle(document.body,"margin-left")) + parseInt(LBI.Common.getStyle(document.body,"margin-right"));
		}
		if(newHeight < document.body.clientHeight){
			newHeight = document.body.clientHeight;
			newHeight += parseInt(LBI.Common.getStyle(document.body,"margin-top")) + parseInt(LBI.Common.getStyle(document.body,"margin-bottom"));
			if(window.innerWidth && window.innerWidth > document.body.scrollWidth){newWidth -= 17;}//handle Firefox bug where it counts the scrollbar too for scrolling pages
		}
		else if(newHeight < document.body.scrollHeight){//quirksmode handling
			newHeight = document.body.scrollHeight;
		}
		
		return [newWidth,newHeight];
	},
	//handle cross-browser retrieval of how far user has scrolled down
	getScrollTop : function(){
		if(window.pageYOffset){
			return window.pageYOffset;
		}
		else if(document.documentElement && document.documentElement.scrollTop){
			return document.documentElement.scrollTop;
		}
		else if(document.body){
			return document.body.scrollTop;
		}
		else{return false;}
	},
	// returns values of all select options
	getSelectVals : function(oWrapper)	{
			var els=oWrapper.getElementsByTagName("select");var o=new Array();
			for (var aSelV=0;aSelV<els.length;aSelV++)	{o[aSelV]=els[aSelV].value;}
			return o;
	},
	// returns true if radio buttons inside object oWrapper is checked, else false
	getRadioSelected: function(oWrapper)	{
		var els=oWrapper.getElementsByTagName("input");
		for (var aSel=0;aSel<els.length;aSel++)	{
			if(els[aSel].checked)	{
				return true;
			}
		}
		return false;
	},	
	// returns check Boolean of first checkbox element inside object oWrapper
	getCheckboxVal: function(oWrapper)	{
		return oWrapper.getElementsByTagName("input")[0].checked;
	},
	// returns value of first textarea element inside object oWrapper
	getTextareaVal: function(oWrapper)	{
		return oWrapper.getElementsByTagName("textarea")[0].value;
	},
	// returns value of first input element inside object oWrapper
	getInputVal: function(oWrapper)	{
		return oWrapper.getElementsByTagName("input")[0].value;
	},
	// removes given node obj (oNode). returns true/false status on node removal
	removeNodeByObj: function(oNode)	{
		if (oNode)	{
			oNode.parentNode.removeChild(oNode);
			return true;
		}	else	{
			return false;
		}
	},
	// removes given node string (nodeId). returns true/false status on node removal
	removeNodeById: function(strNodeId)	{
		if (document.getElementById(strNodeId))	{
			var oNode=document.getElementById(strNodeId);
			return this.removeNodeByObj(oNode);
		}	else	{
			return false;
		}
	},
	// returns an absolute y position of the given element object 'o'.
	getAbsoluteY: function(o) {
		oTop=o.offsetTop;            
		while(o.offsetParent!=null) { 
			oParent=o.offsetParent;
			oTop+=oParent.offsetTop;
			o=oParent;
		}
		return oTop
	},
	// returns an absolute x position of the given element object 'o'.
	getAbsoluteX: function(o) {
		var oLeft = o.offsetLeft;
		while(o.offsetParent!=null) { 
			oParent=o.offsetParent;
			oLeft+=oParent.offsetLeft;
			o=oParent;
		}
		return oLeft
	},	
	// returns the object of the next parent/grand-parent etc. of the element object oEl of the tag type strTagName. Returns false if fails
	getParentByTagName: function(el,tagName){
	            var parent=el.parentNode;
	            while(tagName.toLowerCase()!=parent.nodeName.toLowerCase()){
	                        parent=parent.parentNode;
	                        if(!parent || parent.nodeName==="#document"){return false;}
	            }
	            return parent;
	},
	// simplifies fetching of first element by classname. returns element obj or false
	getFirstInstanceByClassName: function(oElm,strTagName,strClassName)	{
		var els=getElementsByClassName(oElm,strTagName,strClassName);
		if (els.length>0)	{
			return els[0];
		}
		return false;
	},
	//handle cross-browser adding events
	addEvent: function(obj,evt,fn){
		if(document.addEventListener){
			this.addEvent = function(obj,evt,fn){
				obj.addEventListener(evt,fn,false);
			}
		}
		else if(document.attachEvent){
			this.addEvent = function(obj,evt,fn){
				obj["e"+evt+fn] = fn;
				obj[evt+fn] = function() { obj["e"+evt+fn]( window.event ); }
				obj.attachEvent( "on"+evt, obj[evt+fn] );
			}
		}
		else{
			return false;
		}
		this.addEvent(obj,evt,fn);
	},
	fuzzyClassName: function(tag,fClass)	{
		var el = (tag === "*" && document.all) ? document.all : document.getElementsByTagName(tag);
		var o=new Array();
		for (var i=0;i<el.length;i++)	{
			if (el[i].className.indexOf(fClass)!=-1)	{
				o.push(el[i]);
			}
		}
		return o;
	},
	//as fuzzyClassName, but restriced to self and children of a specific DOM object
	fuzzyClassNameBlock : function(block,tag,fClass)	{
		var el = (tag === "*" && block.all) ? block.all : block.getElementsByTagName(tag);
	
		var o=new Array();
		for (var i=0;i<el.length;i++)	{
			if (el[i].className.indexOf(fClass)!=-1)	{
				o.push(el[i]);
			}
		}
		if(block.className.indexOf(fClass)!=-1){
			o.push(block);
		}
		return o;
	},
	//get the contents between ( and ) marks attached to a classname that starts with a given marker
 	getPEClassInfo: function(el,marker){
		var fullClass = el.className;
		var info = fullClass.substring(fullClass.indexOf(marker+"(")+marker.length+1);
		info = info.substring(0,info.indexOf(")"));
		return info;
	},
	/* function for making panels equal height */

	equalisePanelHeights: function() {
		var equal_container_divs = getElementsByClassName(document,'div','equalPanelHeights');
		for (var i=0; i<equal_container_divs.length; i++) {
			equalise(equal_container_divs[i]);
		}
		// the equaliser;
		function equalise(container_div) {
			var max_height = 0;
			//Get all the homePromos
			var content_divs = getElementsByClassName(container_div,'div','equalMe');
			//If there are more than 1 homePromos
			if(content_divs.length > 1) {
				//find the max height of the homePromos
				for (var i=0; i<content_divs.length; i++) {
						max_height = (content_divs[i].offsetHeight > max_height) ? content_divs[i].offsetHeight : max_height;
				}
				//set all the homePromo conts to be equivalent to this max height minus top and base
				for (var i=0; i<content_divs.length; i++) {
					//get each cont
					var innerDivToEnlarge = getElementsByClassName(content_divs[i], 'div', 'cont');
					//if there are conts
					if(innerDivToEnlarge.length > 0){
						//calculate new height
						var newHeight = equalPanel(max_height, 20)+"px";
						if (LBI.Common.isLtIE7 === true) {
							innerDivToEnlarge[0].style.height = newHeight;
						}
						innerDivToEnlarge[0].style.minHeight = newHeight;
					}
				}
			}
		}
		function equalPanel(intHeight, intExcess) {
		
		return intHeight - intExcess;
		
		}
	},
	//accessibility hack: updates the value of a hidden field to trigger a buffer refresh. called in the functions that are run when an AJAX call has returned data or error
	updateBuffer : function() {
		var bufferReset = document.getElementById("bufferReset");
		if(!bufferReset){
			var bufferReset = document.createElement("input");
			bufferReset.type="hidden";
			bufferReset.name="bufferReset";
			bufferReset.value=1;
			bufferReset.id="bufferReset";
			document.body.appendChild(bufferReset);
		}
		bufferReset.value++;
	},	
	getPEObj : function(intIdx, PEName) {
		return LBI.Custom.PEList[PEName].instLib[intIdx];
	},
	getPEName: function(strFullClass){
		var intPEStart = strFullClass.indexOf("PE_");
		return strFullClass.substring(intPEStart, strFullClass.indexOf("("));
	},
	applyAnim: function(oElm, action, anim, oAnimOpt){		
		var applyAnim = function() {
			var css = oAnimOpt.style;
			if(action !== undefined) {
				// if the action is set as a callback, run it as one. Otherwise, it gets called before the animation
				if(oAnimOpt.callback === true) {
					$(oElm).animate(css, oAnimOpt.time, oAnimOpt.tween, action);											
				} else {
					action();
					$(oElm).animate(css, oAnimOpt.time, oAnimOpt.tween);
				}
			} else {
					$(oElm).animate(css, oAnimOpt.time, oAnimOpt.tween);
			}
		};		
		var alterElm = function() {
			//if you want an animation					
			if(anim === true) {
				//run the function sent as the animation parameter
				applyAnim();						
			} else {
				action(oElm);
			}
		}
		alterElm();			
	},	
	stopAnim : function(arrAnims, arrTimeouts) {
		if(timeout !== undefined) {
			for(var timeout in arrTimeouts) {
				window.clearTimeout(arrTimeouts[timeout]);
			}
		}
		if(arrAnims !== undefined) {
			for(var anim in arrAnims) {
				$(arrAnims[anim]).stop();
			}
		}
	},
	createPE : function(oCore, intIdx, strPEName) {
		var constr = function() {};
		var oBase = new LBI.Custom.classLib.base(oCore, intIdx); // copy base
		for(var strProp in LBI.Custom.classLib[strPEName]) { // copy class members
			oBase[strProp] = LBI.Custom.classLib[strPEName][strProp];
		}		
		constr.prototype = oBase;
		oNewObj = new constr;
		if(oNewObj.arrMembers !== undefined) { oNewObj.getMembers(); }		
		return oNewObj;
	},
	
	/* ajaxLoader is a shell function for running a library-based ajax call 
	 * Parameters stored in an oOptions object are: 
	 * 	url (string)
	 * 	errorLog : function to run on error
	 * 	timer : how long before call times out (integer)
	 *  dataType : data type to request, i.e. xml (string)
	 *  coreObj : a reference to the oOptions object so it can use it's methods - usually this
	 *  successLog : function to run on success (for calls that need resulting data to be processed). Is passed resulting object as 1st param
	 */ 
	ajaxLoader : function(oOptions) {
		var strUrl = oOptions.url;
		var errorLog = oOptions.errorLog;		
		var intTimer = oOptions.timer;
		var successLog = oOptions.successLog;
		var strData = oOptions.data;
			$.ajax({
					type : "GET",
					url : strUrl,
					success : function(data) {
						successLog(data);
					},
					error : errorLog,
					timeout : intTimer,
					dataType : strData
			});	
	}
};

// function to open links in a new window

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
} 


/********** DOM READY STATE CHECKING, WITH ONLOAD FALLBACK. **********/
// hide masthead panels on Home page - to eliminate initial display of all panels in IE6/IE7 

/* DO NOT REMOVE THIS SECTION - IE CONDITIONAL COMPILATION */
/*@cc_on @*/
/*@if (@_win32)
document.write("<script id=el_ie defer src='../includes/consumer/consumerProducts/js/blank.js'><\/script>");var script = document.getElementById("el_ie");script.onreadystatechange = function() {
if (this.readyState === "complete") {onloadhandler();}}
/*@end @*/
/* IE CONDITIONAL COMPILATION ENDS */

window.initialised=false;
if (document.addEventListener) {document.addEventListener("DOMContentLoaded", layerinit, false);}

/* safari regular polling */
if (/WebKit/i.test(navigator.userAgent)) { // sniff webkit-based browser
	var _timer = setInterval(function() {
		if (/loaded|complete/.test(document.readyState)) {
			if (window.initialised){return;}
			layerinit(); // call the onload handler
		}
	}, 10);
}
/* fallback for all other browsers */
window.onload=onloadhandler;
/*########################################################################################################*/
// FUNCTIONS TO RUN WHEN DOM IS READY
function layerinit()	{
	window.initialised=true;
	LBI.Common.detectLtIE7();		
	popup();
	pngHandling();
	Lightbox.init(); //set up lightboxes
}

function onloadhandler()	{
	if (window.initialised){return;}
	layerinit(); // will only execute if layerinit hasn't already executed
}
/********** END DOM READY **********/
