// JavaScript Document
var homepageURLs = new Array();
homepageURLs[0] = "livingspace-3dcart.3dcartstores.com/";
homepageURLs[1] = "livingspace-3dcart.3dcartstores.com/index.html";
homepageURLs[2] = "shop.livingspace.com/";
homepageURLs[3] = "shop.livingspace.com/index.html";
homepageURLs[4] = "livingspace-3dcart.gssiwebs.com/";
homepageURLs[5] = "livingspace-3dcart.gssiwebs.com/index.html";
homepageURLs[6] = "www.shop.livingspace.com/";
homepageURLs[7] = "www.shop.livingspace.com/index.html";

function isHomepage()
{
	var strHref = window.location.href;
	strHref = strHref.replace("https://", "").replace("http://","")
	
	for(var i = 0; i < homepageURLs.length; i++)
	{
		if(strHref == homepageURLs[i])
		{
			return true;
		}
	}
	return false;
}

function loadBanner()
{
	var contentEle = document.getElementById("content");
	var contentbodyEle = document.getElementById("content-body");
	var catEle = document.getElementById("category-fullline");
	var h1Ele = document.getElementsByTagName("h1");
	var catsValue;
	var catsArray;
	
	if(catEle != null)
	{
//		catsValue = catEle.innerText + catEle.textContent; //combine value for IE and Other browsers
//		catsValue = catsValue.replace("undefined","");
		catsValue = catEle.innerText || catEle.textContent;  //cross browsers
		catsArray = catsValue.split(">",2);
	}
	
	if(h1Ele[0] == null && catEle != null) // put headings for product listing page
	{
		var idx = catsValue.lastIndexOf(">");
		var lastCatName = catsValue.substr(idx+2);
		//alert(lastCatName);
		var h1EleNew = document.createElement('h1');
		h1EleNew.innerHTML = lastCatName;
		contentbodyEle.insertBefore(h1EleNew, contentbodyEle.childNodes[0]);
	}
	
	if(catEle != null && contentEle != null)
	{
		var catV = trim(catsArray[1].toLowerCase());
		if(catV.indexOf("lighting") > -1)
			contentEle.style.backgroundImage = "url(assets/templates/custom1/images/banner-lighting.jpg)";
		else if (catV.indexOf("furniture") > -1)
			contentEle.style.backgroundImage = "url(assets/templates/custom1/images/banner-furniture.jpg)";
		else if (catV.indexOf("accessories") > -1)
			contentEle.style.backgroundImage = "url(assets/templates/custom1/images/banner-accessories.jpg)";
		else if (catV.indexOf("outdoor") > -1)
			contentEle.style.backgroundImage = "url(assets/templates/custom1/images/banner-outdoor.jpg)";
		else if (catV.indexOf("office") > -1)
		{
			contentEle.style.backgroundImage = "url(assets/templates/custom1/images/banner-office.jpg)";
			if(h1Ele[0] != null)
				h1Ele[0].style.color = "black";
		}
		else
		{
			contentEle.style.backgroundImage = "url(assets/templates/custom1/images/banner-generic.jpg)";
			if(h1Ele[0] != null)
				h1Ele[0].style.color = "black";
		}
		contentEle.style.backgroundRepeat = "no-repeat";
	}
	else
	{
		if(!isHomepage() && contentEle != null)
		{
			contentEle.style.backgroundImage = "url(assets/templates/custom1/images/banner-generic.jpg)";
			contentEle.style.backgroundRepeat = "no-repeat";
			if(h1Ele[0] != null)
				h1Ele[0].style.color = "black";
		}
		else //homepage
		{
			//var flashdiv = document.createElement('div');
//			flashdiv.setAttribute("id","flash-container");
//			flashdiv.style.height = "439px";
//			flashdiv.style.width = "769px";
//			flashdiv.style.padding = "0";
//			flashdiv.style.margin = "0";
//			flashdiv.style.position = "absolute";
//
//			flashdiv.style.backgroundImage = "url(assets/templates/custom1/images/flash-holder.jpg)";
//			flashdiv.style.backgroundRepeat = "no-repeat";
//			flashdiv.style.backgroundPosition = "top left";
//			
//			contentEle.insertBefore(flashdiv, contentEle.childNodes[0]);
//
//			var mainEle = document.getElementById("mainsection");
//			mainEle.style.backgroundImage = "url(assets/templates/custom1/images/home-section-bg.png)";
//			
//			// contentEle.style.marginLeft = "201px";
//			var contentbodyEle = document.getElementById("content-body");
//			contentbodyEle.style.backgroundImage = "url(assets/templates/custom1/images/home-content-bg.png)";
//			contentbodyEle.style.backgroundRepeat = "no-repeat";
//			contentbodyEle.style.backgroundPosition = "0 439px";
//			contentbodyEle.style.paddingTop = "489px";
		}
	}
}

/********  trim leading spaces *************/
function trim(s) 
{
	while (s.substring(0,1) == ' ') {
		s = s.substring(1,s.length);
	}
	while (s.substring(s.length-1,s.length) == ' ') {
		s = s.substring(0,s.length-1);
	}
	return s;
}
