function hasJS(){
	$("body").addClass("hasJS");	
}

/*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();
	}
}

var LBidata = {
	flashPath : "flash/entertainment/",
	flashPlayer : "../../flash/fibre/BTVideoPlayer.swf",
	flashType : {
		flashVideo : {
			height : 480,
			width : 640
		}
	},
	videoOptions : {
		params : {allowScriptAccess : "sameDomain", wmode: "transparent", allowFullScreen: "true"},
		attributes : null
	}
};

var LBi = {			
	carousel:function(){			
		if($(".carouselContainer").length !== 0){
			var carouselNumbers = $(".carouselContainer");
			
			//configurable options for each of the carousel
			//$(".carousel01 .carouselContent").css("height", 100);
			
			
			//general set up 
			$(".carouselContent ul").css("position", "absolute");
			$(".alternateControls").css("display", "block");
			
			$(carouselNumbers).each(function(){
				//setting up carousel's static values
				var carouselWidth = $(".carouselContent", this).css("width");					
				var carouselItems = $(".carouselContent .item", this);
			
				var initialHeight = $(carouselItems[0]).height();
				$(".carouselContent", this).css("height", initialHeight);
				
				var itemWidth = parseInt(carouselWidth);
				var carouselSpeed = 600;
				var fadeValue = 0.2;
				
				var carouselItems = $(".carouselContent li", this);
				var containerWidth = carouselItems.length * itemWidth;
				$(".carouselContent ul", this).css("width",containerWidth);
				var finalXpos = itemWidth - containerWidth;

				//create controls
				var cControls = $(".controls", this);		
				var cBack = document.createElement("a");
				$(cBack).attr( {
					href: "#"
				});
				$(cBack).addClass("left");
				cControls[0].appendChild(cBack);
				var lArrow = document.createElement("span");
				$(lArrow).addClass("hidden");
				$(lArrow).text("< Go left");
				cBack.appendChild(lArrow);
				
				var cFrwd = document.createElement("a");
				$(cFrwd).attr( {
					href: "#"
				} );
				$(cFrwd).addClass("right");
				cControls[0].appendChild(cFrwd);
				var rArrow = document.createElement("span");
				$(rArrow).addClass("hidden");
				$(rArrow).text("Go right >");
				cFrwd.appendChild(rArrow);
				
				//Assigning the current carousel
				var currentCarousel = $(".carouselContent ul", this);
				var currentCarouselContent = $(".carouselContent", this);
				var rightButton = $(".right", this);
				var leftButton = $(".left", this);
				var alternateControlItems = $('.alternateControls li a', this);
				var alternateControl = $('.alternateControls', this);
				
				//Setting default opacity to the left button
				$(leftButton).fadeTo("slow", fadeValue);
				$(rightButton).fadeTo("slow", 1.0);
				
				//Alternate controls to the carousel
				$(alternateControlItems).click(function tabCont(event) {
					 
					  // if the ul is already moving, then do nothing
					  if ($(".carouselContent ul:animated").length > 0)return false; 
				 
					  var clicked_item = $(event.target);			  
					  var current_active = $(".active", alternateControl);
					 
					  var current_index = $(".active", alternateControl).attr("rel");			  
					  var new_index = $(clicked_item).attr("rel");
					  
					  var move = new_index; // get how many items it should be moved
					  var contentIndex = move-1;
				 
					  if (new_index != current_index) {
						var moveValue = "-" + (itemWidth*(move -1));
						
						$(currentCarousel).animate({left: moveValue}, carouselSpeed);
						
						var newHeight = $(carouselItems[contentIndex]).height();
						$(currentCarouselContent).animate( { height:newHeight}, carouselSpeed );
						
						clicked_item.addClass("active");
						current_active.removeClass("active");
						
						if(new_index == carouselItems.length){
							$(rightButton).fadeTo("slow", fadeValue);
							$(leftButton).fadeTo("slow", 1.0);
						}
						else if (new_index == 1){
							$(leftButton).fadeTo("slow", fadeValue);
							$(rightButton).fadeTo("slow", 1.0);
						}
						else {
							$(rightButton).fadeTo("slow", 1.0);
							$(leftButton).fadeTo("slow", 1.0);
						}				
						return false
					  }		 
					  return false;
					});
				
				//Assigning function for right controls
				$(rightButton).click(			
					function goRight(){				
						$(leftButton).fadeTo("slow", 1.0);
						if ($(".carouselContent ul:animated").length > 0)return false;
						var currentXpos = $(currentCarousel).css("left");

						var currentX = parseInt(currentXpos);
						
						if(currentX !== finalXpos){
							currentX = currentX-itemWidth;
							
							$(currentCarousel).animate( { left:currentX}, carouselSpeed );					
							
							$(currentCarousel).css({left:currentX});										
							if(currentX === finalXpos){
								$(this).fadeTo("slow", fadeValue);
							}
												
							var currentTabValue = currentX/itemWidth;
							if (currentTabValue < 0){
								var currentTabValue = -1 * currentTabValue;
							}
							var currentTabValue = currentTabValue;
							
							var newHeight = $(carouselItems[currentTabValue]).height();
							$(currentCarouselContent).animate( { height:newHeight}, carouselSpeed );
							
							var alternateTabs = $("a", alternateControl);
							$(alternateTabs).removeClass("active");
							$(alternateTabs[currentTabValue]).addClass("active");
							
							return false;					
						}				
						return false;				
					}	
				)
				
				//Assigning function for left controls
				$(leftButton).click(		
					function goLeft(){
						$(rightButton).fadeTo("slow", 1.0);
						if ($(".carouselContent ul:animated").length > 0)return false;
						var currentXpos = $(currentCarousel).css("left");
						var currentX = parseInt(currentXpos);
						if(currentX !== 0){
							currentX = currentX+itemWidth;
							
							$(currentCarousel).animate( { left:currentX}, carouselSpeed );
							
							$(currentCarousel).css({left:currentX});										
							if(currentX === 0){
								$(this).fadeTo("slow", fadeValue);
							}
							
							var currentTabValue = currentX/itemWidth;
							if (currentTabValue < 0){
								var currentTabValue = -1 * currentTabValue;
							}
							var currentTabValue = currentTabValue;
							
							var newHeight = $(carouselItems[currentTabValue]).height();
							$(currentCarouselContent).animate( { height:newHeight}, carouselSpeed );
							
							var alternateTabs = $("a", alternateControl);
							$(alternateTabs).removeClass("active");
							$(alternateTabs[currentTabValue]).addClass("active");
							
							return false;
						}
						return false;
					}		
				)
		
			})
		}
	},
	
	videoPlayDetect: function(){
		if($("body").hasClass("landing")){
			return false;
		}
		else{
			Cufon.replace('h2');
			var urlString = window.location.href;
			var urlParts = urlString.split("#");
			
			for(i=0; i<urlParts.length; i++){
				var videoName = urlParts[i].split("_");
				if(videoName[0] == "VID"){
					$("#" + urlParts[i] + "-name").addClass("activeVideo");
					var flashToPlay = urlParts[i] + "-name";
					LBi.flashCarousel(flashToPlay);
				}
			}
		}
		
	},
	
	flashCarousel: function(pageLoadVid) {
		if ($(".flashContent").length !==0){	
			$(".videoHolder").removeClass("hidden");
			$(".fallback").addClass("hidden");
		
			var videoItems = $(".videoItemOuter");
			var videoLinks = $(".videoItemOuter a.videoLink");
			
			//Video play on page load
			var activeVideo = "#" + pageLoadVid;
			if($(activeVideo).length>0){
				LBi.flashPlay(activeVideo);
			}			
			else{
				LBi.flashPlay("#VID_video01")
			}
				
			$(videoItems).click(function(){	
				
				var nameVideo = "#" + $(this).attr("id");
				var urlName = LBicommon.getPEClassInfo(this, "N_");
				var windowUrl = window.location.href.split("#");
				window.location.href =  windowUrl[0] + "#VID_" + urlName;
				LBi.flashPlay(nameVideo);
				
				return false;
			})
		}	
	},
	homeFlash: function(){	
		if($("body").hasClass("landing")){
			var videoLinkRel = $("a.videoLink");
			var videoId = LBicommon.getPEClassInfo(videoLinkRel[0],"V_");
			var height = LBicommon.getPEClassInfo(videoLinkRel[0],"H_") + "px";
			var width = LBicommon.getPEClassInfo(videoLinkRel[0],"W_") + "px";
			var videoHeight = LBicommon.getPEClassInfo(videoLinkRel[0],"H_");
			var videoWidth = LBicommon.getPEClassInfo(videoLinkRel[0],"W_");
			
			var flashvars = {};
			var flashFile = videoLinkRel[0].href;
			swfobject.embedSWF(flashFile, videoId, width, height, "9.0.0", "expressInstall.swf");
		}
	},
		
	flashPlay: function(videoName){		
		var videoPlayRel = $(videoName);
		var videoItems = $(".videoItemOuter");		
		
		
		
		$(videoPlayRel).each(function(){
			//Display the relevant video description
			var videoLinkRel = $("a.videoLink", this);
			
			var videoType = LBicommon.getPEClassInfo(videoLinkRel[0],"T_");
			var descTitle = $(".videoLowerContent h3", this).text();
			var descCont = $(".videoLowerContent p.videoDesc", this).text();
			
			var videoDesc = $(".videoDesc");
			$(videoDesc).parent().parent().removeClass("business");
			$(videoDesc).parent().parent().removeClass("consumer");
			$("body").attr("id", videoType);
			
			if(videoType =="businessnew"){
				$("#findOut span").text("Find out how we can help your business today");
				$("#findOut").attr({href: "http://business.bt.com/broadband-and-internet/internet-access/fibre-broadband"});
				
				$("#seeBenefits").text("Find out more about BT Business Total Broadband Fibre");
				$("#seeBenefits").attr({href: "http://business.bt.com/broadband-and-internet/internet-access/fibre-broadband "});
			}
			
			else if(videoType =="consumer"){
				$("#findOut span").text("Find out more about BT Total Broadband today");
				$("#findOut").attr({href: "http://www.bt.com/broadband"});
				
				$("#seeBenefits").text("Find out if you can get super>fast broadband in your home");
				$("#seeBenefits").attr({href: "http://www.productsandservices.bt.com/consumerProducts/displayTopic.do?topicId=29019"});
			}

			else if(videoType =="business"){
				
				$("#findOut span").text("Find out how we can help your business today");
				$("#findOut").attr({href: "http://www.bt.com/business"});
				
				$("#seeBenefits").text("Find out more about BT Business Total Broadband Fibre ");
				$("#seeBenefits").attr({href: "http://business.bt.com/broadband-and-internet/internet-access/fibre-broadband"});


			}
			
			$("h2", videoDesc[0]).text(descTitle);
			$("p", videoDesc[0]).text(descCont);
			Cufon.replace('h2');
			
			//Playing video Content
			$(videoItems).removeClass("activeVideo");
			$(this).addClass("activeVideo");
			var flashType = LBicommon.getPEClassInfo(videoLinkRel[0],"F_");
			var videoId = LBicommon.getPEClassInfo(videoLinkRel[0],"V_");
			var height = LBicommon.getPEClassInfo(videoLinkRel[0],"H_") + "px";
			var width = LBicommon.getPEClassInfo(videoLinkRel[0],"W_") + "px";
			var videoHeight = LBicommon.getPEClassInfo(videoLinkRel[0],"H_");
			var videoWidth = LBicommon.getPEClassInfo(videoLinkRel[0],"W_");
			var startImageName = LBicommon.getPEClassInfo(videoLinkRel[0],"S_")
			var startimage = "../../images/products_and_services/fibre/" + startImageName + ".gif";
			var videotitle = $(videoLinkRel[0]).attr("title");
			
			var windowUrl = window.location.href.split("#");
			window.location.href =  windowUrl[0] + "#VID_" + startImageName;
			
			if( LBicommon.getPEClassInfo(videoLinkRel[0],"NV_") !== ""){
				var nextVideo = "#VID_" + LBicommon.getPEClassInfo(videoLinkRel[0],"NV_") + "-name" 
			}			
			else{
				var nextVideo = "";
			}


			var flashvars = {};
			if (videoLinkRel[0].href.indexOf(".flv") !== -1) {
				var videoLink = videoLinkRel[0].href;
				flashvars.videoSource= videoLink;
				flashvars.videoTitle = videotitle; 
				flashvars.nextVideoId = nextVideo;
				flashvars.width = videoWidth;
				flashvars.height = videoHeight;
				flashvars.autoplay = false;
				flashvars.muted = false;
				flashvars.showInteractive = false;
				flashvars.startImage = startimage;
				swfobject.embedSWF(LBidata.flashPlayer, videoId, width, height, "9.0.0", "expressInstall.swf",flashvars, LBidata.videoOptions.params);
			} else {
				var flashFile = videoLinkRel[0].href;
				swfobject.embedSWF(flashFile, videoId, width, height, "9.0.0", "expressInstall.swf");
			}
			
			return false;
		})
		
	},

	itemHover: function(){	
		$(".playIcon").fadeTo("fast", 0.0);
		
		$(".videoItemOuter").hover(function() {
			$(".playIcon", this).fadeTo("fast", 0.4);
			$(this).css("cursor", "pointer")
		}, function() {
			$(".playIcon", this).fadeTo("fast", 0.0);
		});
		
		var videoHome = $(".PE_hover");
		
		$(videoHome).hover(function() {
			$(".playIcon", this).fadeTo("fast", 0.4);
			$(this).css("cursor", "pointer")
		}, function() {
			$(".playIcon", this).fadeTo("fast", 0.0);
		});
		
		$(videoHome).click(function(){
			var hrefLink = $("a.videoLink", this).attr("href");
			window.open(hrefLink, "_self");
		})
		
		
	},
	

	//truncating text in video text description
	/*truncateVideoText: function() {
		var videoDesc = $(".videoLowerContent .videoDesc");
		$(videoDesc).each(function() {
			var videoDescText = $(this).text();
			var splitText = videoDescText.substr(0, 80) + "...";
			$(this).text(splitText);
		});
		
		LBi.flashCarousel(videoDescText);
	
	},*/			

	tabbed: function(){
		if($(".tabs").length !== 0){
			var tabbedElements = $(".tabs");
			
			$(tabbedElements).each(function(){
				var tabMenu = $("ul.tabMenu li a", this);
				$(tabMenu[0]).addClass("active");
				
				var tabContent = $(".tabContent .tabCont", this)
				$(tabContent).addClass("hidden");
				$(tabContent[0]).removeClass("hidden");
				
				$(tabMenu).click(function(){
					var relProp = $(this).attr("rel");
					var contentId = "#" + relProp;
					
					//var firstVideo = "#" + $(contentId + " .first").attr("id");
					//LBi.flashPlay(firstVideo);
					
					//var headImage = "url(images/fibre/hd_super_fast_bb_" + relProp + ".gif)"					
					//$("h1").css({"background-image": headImage});				
					
					$(tabMenu).removeClass("active");
					$(this).addClass("active");
					
					$(tabContent).addClass("hidden");
					$(tabContent).css({'display' : 'none'})
					$(contentId).removeClass("hidden");
					$(tabContent).css({'display' : 'block'})
					
					return false;
				})
			})
		}
	},
	
	popup: function(){
		var els=LBicommon.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=LBicommon.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;
			}
		}
	}
	

};

	
var LBicommon= {
	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 = LBidgets.Common.getViewPortHeight();
		var newWidth  = LBidgets.Common.getViewPortWidth();
		/*compare with body */
		if(newWidth < document.body.clientWidth){
			newWidth = document.body.clientWidth;
			newWidth += parseInt(LBidgets.Common.getStyle(document.body,"margin-left")) + parseInt(LBidgets.Common.getStyle(document.body,"margin-right"));
		}
		if(newHeight < document.body.clientHeight){
			newHeight = document.body.clientHeight;
			newHeight += parseInt(LBidgets.Common.getStyle(document.body,"margin-top")) + parseInt(LBidgets.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 (LBidgets.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++;
	},	
	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();
			}
		}
	},
	/* 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
			});	
	}
};

 $(document).ready(function(){
	hasJS();
	LBi.carousel();
	LBi.flashCarousel();
	LBi.itemHover();
	LBi.tabbed();
	LBi.videoPlayDetect();
	LBi.popup();
	LBi.homeFlash();
	//LBi.truncateVideoText();
 });
