addOnload(initCorrectURL);
addOnload(initInputCheck);
addOnload(initCurrentLink);
addOnload(initRecentlyViewed);
addOnload(initDeleteUnlistedFromWishlist); // under construction...
addOnload(initProducts);
addOnload(initIcons);
addOnload(initCurrentPage);
addOnload(initCategories);
addOnload(initSubcg);
addOnload(initSelectGo);
addOnload(initSortby);
addOnload(initSortSelectGo);
addOnload(initSortSelected);
addOnload(initPricelistMsg);
addOnload(initConvertWishList); // convert old wishlist to new wishlist.
addOnload(initAddToWishList);
addOnload(initDeleteFromWishList);
addOnload(initWishListCounter);
addOnload(initAddRecentlyViewed);
addOnload(initSubcgLink);
addOnload(initNewWin);
addOnload(initSearchKeywords);
window.onresize = initContentSize; 
window.onunload = function(){}; // window.onunload is for initSubcg.

function addOnload(newFunction){
	var oldOnload = window.onload;
	
	if(typeof oldOnload == "function"){
		window.onload=function(){
			if(oldOnload){
				oldOnload();
			}

		newFunction();

		}
	}

	else{
		window.onload=newFunction;
	}
}

//Start of General Variables
var IE = (navigator.appName=="Microsoft Internet Explorer")?true:false;
var NS = (navigator.appName=="Netscape")?true:false;

var thisFileLoc=window.location.href;
var startFileName = thisFileLoc.lastIndexOf("/")+1;
var endFileName = thisFileLoc.lastIndexOf(".");
var thisFileName = thisFileLoc.substring(startFileName,endFileName);

 
if(thisFileLoc.indexOf("=") > -1){
	var thisPageName = thisFileLoc.split("=")[1];
}



if(thisFileLoc.indexOf("?") > -1){
	var letterAnd = thisFileLoc.indexOf("&");
	var letterEqual = thisFileLoc.indexOf("=");

	if(letterAnd==-1 && letterEqual==-1){
		var thisPageName = thisFileLoc.split("?")[1];
	}	
	
	if(letterAnd==-1 && letterEqual>-1){
		var thisPageName = thisFileLoc.split("?")[1].split("=")[0];
	}	

	if(letterAnd>-1 && letterEqual>-1 && letterAnd < letterEqual){
		var thisPageName = thisFileLoc.split("?")[1].split("&")[0];
	}	

	if(letterAnd>-1 && letterEqual>-1 && letterAnd > letterEqual){
		var thisPageName = thisFileLoc.split("?")[1].split("=")[0];
	}	
}
//End of General Variables


//Start of Subcategory Infomation
var subcgInfo =  new Array(
"cecchini=cecchini:SS4_SS3_SS15_SS14_SS12_SS5_SS6_SS7_SS2_SS16_SS8_SS9_SS13_SS1_TB11_SS11_SL3_SS10_TB4_TB5_TB6_SL1_SL5_SL4",
"palau=palau:SE1_SE2_SE3_SE4_SE58_SE31_SE65_SE73_SE62_SE60_SE61_SE63_TB10",
"citeconcept=cite concept:SE75_SE5_SE6_SE98_SE72_SE12_SE11_SE8_SE9_SE10_SE70_SE68_SE76_SE20_SE45_SE21_SE78_SE46_SE22_SE71_SE69_SE25_SE23_SE100_SE77_SE26_SE99_SE79_SE66_SE47_SE81_SE80_SE74_SE64_SE32_SE34_SE43_TB20_TB31_TB1_TB21_TB2_TB23_TB26_TB27_TB28_TB29_TB30_TB22_TB3_TB19_LT60_LT59_LT62_AC107",
"verpan=verner panton:LT50_LT9_LT10_LT48_LT34_LT11_LT4_LT49_LT36_LT35_LT27_LT28_LT29_LT30_LT32_LT33_LT38_LT40_LT42_LT54_LT37_LT39_LT41_LT55_LT56_LT57_LT43_LT44_LT21_LT22_LT12_LT5_LT23_LT24_LT13_LT6_LT25_LT14_LT26_LT15_LT47",
"johnnyRivera=johnny rivera:AC114_AC111_AC109_AC108_AC110_AC112_AC113",
"johnnyswing=johnny swing:SE42_SE49_SE30_SE29_LT17",
"eeroaarnio=eero aarnio:SE50_SE51_SE52_SE41_TB14_TB15_TB16_TB17_TB18_SE53_SE54_SE57_TB7_TB8_TB9_SE55_SE56",
"nuevo=nuevo:",
"wabnitz=wabnitz:",
"maruni=maruni:SE96_TB24_SE82_SE83_SE84_SE85_SE86_SE87_SE88_SE89_SE90_SE91_SE92_SE93_SE94_SE95",
"floorlamps=floor lamps:LT62_LT52_LT2_LT3_LT4_LT5_LT6",
"tablelamps=table lamps:LT61_LT59_LT60_LT7_LT8_LT9_LT10_LT11_LT12_LT13_LT14_LT15_LT16_LT17",
"pendants=pendants:LT69_LT68_LT64_LT65_LT66_LT67_LT51_LT63_LT53_LT58_LT18_LT19_LT20_LT21_LT22_LT23_LT24_LT25_LT26_LT27_LT28_LT29_LT30_LT32_LT33_LT50_LT34_LT35_LT36_LT37_LT38_LT39_LT40_LT54_LT41_LT42_LT56_LT57_LT43_LT55_LT44",
"sconces=sconces:LT45_LT46_LT47_LT48_LT49",
"diningtables=dining tables:TB24_TB31_TB1_TB21_TB2_TB23_TB4_TB5_TB6_TB7_TB8_TB9",
"coffeetables=coffee tables:TB26_TB27_TB28_TB29_TB30_TB25_TB22_TB3_TB10_TB11_TB12_TB19",
"desks=desks:TB20",
"sofas=sofas:SE10_SE75_SE5_SE8_SE9_SE12_SE11_SE6_SE98_SE72_SE58_SE1_SE3_SE4_SE2_SE13_SE16_SE17_SE18",
"diningchairs=dining chairs:SE20_SE21_SE78_SE26_SE99_SE79_SE76_SE25_SE70_SE23_SE100_SE77_SE22_SE71_SE96_SE82_SE83_SE84_SE85_SE86_SE87_SE88_SE89_SE90_SE91_SE92_SE93_SE94_SE95_SE73_SE60_SE62_SE19_SE28_SE29_SE30",
"loungechairs=lounge chairs:SE80_SE74_SE81_SE32_SE64_SE34_SE65_SE31_SE41_SE39_SE37_SE36_SE33_SE40_SE59_SE42",
"officechairs=office chairs:SE43",
"stools=stools:SE45_SE46_SE66_SE47_SE68_SE69_SE61",
"chaises=chaises:SE49",
"shelving=shelving:SS1",
"credenzas=credenzas:SS2_SS16_SS3_SS4_SS15_SS14_SS5_SS12_SS6_SS7",
"cupboards=cupboards:SS13_SS8_SS9",
"wardrobes=wardrobes:SS10",
"chestofdrawers=chest of drawers:SS11",
"sleeping=sleeping:SL1_SL5_SL4_AC107_SL3_AC106_AC66",
"cite-goes-dutch=cite goes dutch:AC67_AC68_AC69_AC70_AC71_AC72_AC73_AC74_AC75_AC76_AC77_AC78_AC79_AC80_AC81_AC82_AC83_AC84_AC85_AC86_AC87_AC88_AC89_AC90_AC91_AC92_AC93_AC94_AC95_AC96_AC97_AC98_AC99_AC100_AC101_AC102_AC103_AC104_AC105",
"royal-vkb=royal vkb:AC91_AC116_AC119_AC121_AC122_AC124_AC126_AC127_AC130_AC131_AC132_AC133_AC138_AC142_AC143_AC145_AC146_AC147_AC148_AC149_AC150_AC151_AC152_AC117_AC120_AC125_AC128_AC129_AC134_AC135_AC136_AC137_AC139_AC140_AC141_AC144",
"jansen=jansen &#43; co:AC115_AC118_AC153_AC154_AC155_AC156_AC157_AC158_AC159_AC160_AC161_AC163_AC164_AC165_AC166_AC167_AC169_AC170_AC171_AC172_AC173_AC175_AC176_AC177_AC178_AC179_AC180_AC162_AC168_AC174",
"goods=goods:AC183_AC184_AC185_AC186_AC187_AC188_AC189_AC190_AC191_AC192_AC193_AC194_AC195_AC196_AC197_AC198_AC199_AC200",
"accessories-1=accessories-1:AC201_AC118_AC116_AC115_AC119_AC181_AC182_AC106_AC66_AC203_AC202_AC65_AC1_AC2_AC3_AC4_AC5_AC6_AC7_AC8_AC9_AC10_AC11_AC12_AC13_AC14_AC15_AC16_AC17_AC18_AC19_AC20_AC21_AC22_AC23_AC24_AC25_AC26_AC27_AC28_AC29_AC30_AC31_AC32_AC33_AC64",
"accessories-2=accessories-2:AC34_AC35_AC36_AC37_AC38_AC39_AC40_AC41_AC42_AC43_AC44_AC45_AC46_AC47_AC48_AC49_AC50_AC51_AC52_AC53_AC54_AC55_AC56_AC57_AC58_AC59_AC60_AC61_AC62_AC63",
"rugs=rugs:RG1_RG2",
"wishlist=my wish list:"

);

function findSubcgName(subcgTitle){
	for(var i=0;i<subcgInfo.length;i++){
		var thisSubcgTitle = subcgInfo[i].split("=")[1].split(":")[0];
		var thisSubcgName = subcgInfo[i].split("=")[0];
		if(thisSubcgTitle == subcgTitle){
			return thisSubcgName;
		}
		
	}
}

function findSubcgTitle(subcgName){
	for(var i=0;i<subcgInfo.length;i++){
		var thisSubcgTitle = subcgInfo[i].split("=")[1].split(":")[0];
		var thisSubcgName = subcgInfo[i].split("=")[0];
		if(thisSubcgName == subcgName){
			return thisSubcgTitle;
		}
		
	}
}
//End of Subcategory Infomation


//Start of Correct URL
function initCorrectURL(){
	var theLastChar = thisFileLoc.charAt(thisFileLoc.length-1);
	if(theLastChar=="#"){
		var theNewLoc = thisFileLoc.substring(0,thisFileLoc.length-1);
		window.location = theNewLoc;
	}
}
//End of Correct URL

//Start of Icons
function initIcons(){
	var iconImage='<img src="images/icon_image.jpg" \/>';
	var iconPdf='<img src="images/icon_pdf.jpg" \/>';
	
	if($('td.td_info')){
		$('td.td_info').find('a').each(
			function(){
				var $iconFile;
				if($(this).text().search('image')>-1){
							$(this).prepend(iconImage + '&nbsp;');
				}
				if($(this).text().search('price list')>-1){
							$(this).prepend(iconPdf + '&nbsp;');
				}
				if($(this).text().search('info')>-1){
							$(this).prepend(iconPdf + '&nbsp;');
				}
				if($(this).text().search('ny times')>-1){
							$(this).prepend(iconPdf + '&nbsp;');
				}
			}
		);
	}
}
//End of Icons

// Start of Subcg Link
function initSubcgLink(){
	for(var i=0;i<document.links.length;i++){
		var thisLink = document.links[i];
		switch(thisLink.id){
			case "nuevo":
				thisLink.onclick = linkNuevo;
				break;
			case "wabnitz":
				thisLink.onclick = linkWabnitz;
				break;
			default:
		}		
	}
}

function linkNuevo(){
	var nuevoWin = window.open("http://www.nuevoliving.com","nuevo","width=800,hight=400,resizable=yes,toolbar=yes,location=no,scrollbars=auto");
	nuevoWin.focus();
	return false;
}
function linkWabnitz(){
	var wabnitzWin = window.open("http://www.wabnitzeditions.com/","wabnitz","width=1000,hight=600,resizable=yes,toolbar=yes,location=no,scrollbars=auto");
	wabnitzWin.focus();
	return false;
}
// End of SubcgLink


//Start of Close Left Menu
function closeLeftMenu(){
	document.getElementById("left_navi").style.display="none";
	/*document.getElementById("recently-viewed").style.display="none";*/
	document.getElementById("recently-viewed").innerHTML="<a href='#' onclick='openLeftMenu();return false;'>&#62;&#62;<\/a>";
	document.getElementById("recently-viewed").style.background="none";
	document.getElementById("recently-viewed").style.width=30+"px";
	initContentSize()
	return false;
}
//End of Close Left Menu



// Start of Open Left Menu
function openLeftMenu(){
	document.getElementById("left_navi").style.display="block";
	document.getElementById("recently-viewed").style.width=120+"px";
	//document.getElementById("recently-viewed").style.marginLeft=-19+"px";
	document.getElementById("recently-viewed").style.background="url('images/recentlyViewedBackground.gif')";
	recentlyViewedArray();
	initAddRecentlyViewed();
	initSubcgLink()
	return false;
}
// End of Open Left Menu



//Start of Recently Viewed
function initAddRecentlyViewed(){
	 for(var i=0;i<document.links.length;i++){
		var thisLink = document.links[i];
		if(thisLink.className=="subcg"){
		    if(thisLink.innerHTML.indexOf("nuevo")==-1){
			thisLink.onclick = setValSubcg;
		    }
		}
		//if(thisLink.className=="itemId" || thisLink.parentNode.parentNode.id.split("=") == "productId"){
		if(thisLink.className=="itemId"){
			thisLink.onclick = setValItemId;
		}
	} 
}

function setValSubcg(){
	var thisSubcgName = this.href.split("?")[1];
		addRecentlyViewedSubcg(thisSubcgName);
}

function setValItemId(){
	var thisItemId = this.id;
		addRecentlyViewedSubcg("productId");
		addRecentlyViewedItem(this.id);
}

function addRecentlyViewedSubcg(thisSubcgName){
	var thisCookie = document.cookie.split("; ");
	var lastArray = new Array();
	var lastArrayCounter = 0;
	for(var i=0;i<thisCookie.length && i<10;i++){
		var cookieName = thisCookie[i].split("=")[0];
		if(cookieName=="recentlyViewedSubcg"){
			var thisCookieVal = thisCookie[i].split("=")[1];
			if(thisCookieVal.indexOf("_")>-1){
				lastArray = thisCookieVal.split("_")
			}else{
				lastArray[0] = thisCookieVal;
				
			} 
		}
	}

	var newCookieVal="";
	for(var i=0;i<lastArray.length;i++){
		if(lastArray[i]!=thisSubcgName){
			newCookieVal += "_" + lastArray[i];
		}
	}


	newCookieVal = thisSubcgName + newCookieVal;

	var expireDate = new Date();
	expireDate.setMonth(expireDate.getMonth()+365);
	//document.cookie = "recentlyViewedSubcg" + "=" + newCookieVal  + "; path=/retail/ ; expires=" + expireDate.toGMTString();
	document.cookie = "recentlyViewedSubcg" + "=" + newCookieVal  + "; expires=" + expireDate.toGMTString();
}


function addRecentlyViewedItem(thisItemId){
	var thisCookie = document.cookie.split("; ");
	var lastArray = new Array();
	for(var i=0;i<thisCookie.length;i++){     
		var cookieName = thisCookie[i].split("=")[0];
		if(cookieName=="recentlyViewedItems"){
			var thisCookieVal = thisCookie[i].split("=")[1];
			if(thisCookieVal.indexOf("_")>-1){
				lastArray = thisCookieVal.split("_")
			}else{
				lastArray[0] = thisCookieVal;
				
			} 
		}
	}

	var newCookieVal="";
	for(var i=0;i<lastArray.length && i<30;i++){ //max # of viewed items
		if(lastArray[i]!=thisItemId){
			newCookieVal += "_" + lastArray[i];
		}
	}


	newCookieVal = thisItemId + newCookieVal;

	var expireDate = new Date();
	expireDate.setMonth(expireDate.getMonth()+365);
	//document.cookie = "recentlyViewedItems" + "=" + newCookieVal  + "; path=/retail/ ; expires=" + expireDate.toGMTString();
	document.cookie = "recentlyViewedItems" + "=" + newCookieVal  + "; expires=" + expireDate.toGMTString();

}


function initRecentlyViewed(){
	if(document.cookie && document.getElementById("recently-viewed")){
		recentlyViewedArray();
	}
}


function recentlyViewedArray(){
	var thisCookie = document.cookie.split("; ");
	var lastSubcgArray = new Array();
	var lastItemArray = new Array();
	for(var i=0;i<thisCookie.length;i++){
		var cookieName = thisCookie[i].split("=")[0];
		if(cookieName == "recentlyViewedSubcg"){
			var thisCookieVal = thisCookie[i].split("=")[1];
			if(thisCookieVal.indexOf("_")>-1){
				lastSubcgArray = thisCookieVal.split("_")
			}else{
				lastSubcgArray[0] = thisCookieVal;
			} 
		}
		if(cookieName == "recentlyViewedItems"){
			var thisCookieVal = thisCookie[i].split("=")[1];
			if(thisCookieVal.indexOf("_")>-1){
				lastItemArray = thisCookieVal.split("_")
			}else{
				lastItemArray[0] = thisCookieVal;
			} 
		}
	}

	if(lastSubcgArray.length>0){
		showRecentlyViewed(lastSubcgArray,lastItemArray);
	}

}



function showRecentlyViewed(thisSubcgArray,thisItemArray){
 	var recentlyViewedList="&#60;&#60; <a href='#' onclick='closeLeftMenu();return false;'>close<\/a><br \/><ul><li>recently viewed<\/li>";
    if(thisSubcgArray){
	var counterSubcg = 0;
 	for(var i=1;i<thisSubcgArray.length && counterSubcg<3;i++){
	   if(thisSubcgArray[i]!="wishlist" && thisSubcgArray[i]!="recentlyviewed" && thisSubcgArray[i]!="productId"){
		recentlyViewedList += "<li><a class='subcg' href='products.html?" + thisSubcgArray[i] + "'>" + findSubcgTitle(thisSubcgArray[i]) + "<\/a><\/li>";
		counterSubcg++;
	   }
	}
	recentlyViewedList += "<br \/>";
    }

    if(thisItemArray){
	var counterItem = 0;
	for(var i=0;i<thisItemArray.length && counterItem<4;i++){
		recentlyViewedList += "<li><a id='" + thisItemArray[i] +"' class='itemId' href='products.html?productId=" + thisItemArray[i]  + "'><img src='images/" + imageInfo(thisItemArray[i]) + "_ss.jpg' alt='" + imageInfo(thisItemArray[i]) + "' \/><\/a><\/li>";
		counterItem++;
	}

	recentlyViewedList += (thisItemArray.length > 4 && thisPageName!='recentlyviewed')?"<li><a class='subcg' href='products.html?recentlyviewed'>more viewed items<\/a><\/li>":"";
    }

	recentlyViewedList += "<\/ul>";

	if(counterSubcg>0 || counterItem>0){
		document.getElementById("recently-viewed").style.width = 120 + "px";
		document.getElementById("recently-viewed").innerHTML = recentlyViewedList;
		document.getElementById("recently-viewed").style.backgroundImage ="url('images/recentlyViewedBackground.gif')"
		initContentSize();
	}
   
}
//End of Recently Viewed






// Start of Input Check
function initInputCheck(){
	if(document.getElementById("search_submit")){
		document.getElementById("search_submit").onclick = inputCheck;
	}
}

function inputCheck(){

	if(document.getElementById("input_text")){
		if(document.getElementById("input_text").value == "enter keyword(s)"){
			document.getElementById("input_text").value ="";
		}
	}
	
}
// End of Input Check



// Start of Convert Wish List
function initConvertWishList(){
	var counter = 0;
	var theWishlist = new Array();
	if(document.cookie){
		var thisCookie = document.cookie.split("; ");
		for(var i=0;i<thisCookie.length;i++){
			if(thisCookie[i].split("=")[0].indexOf("wishlist")>-1){
				theWishlist[counter] = thisCookie[i].split("=")[1]; 
				counter++;
			}
		}
	}

	if(theWishlist.length > 0){
		convertWishList(theWishlist);
	}
}

function convertWishList(thisList){
	var wishList = thisList[0];
   if(thisList.length>1){
	for(var i=1;i<thisList.length;i++){
		wishList += "_" + thisList[i];
	}
   }

	var expireDate = new Date();
	expireDate.setMonth(expireDate.getMonth()+36);
	document.cookie = "wishList=" + wishList + "; expires=" + expireDate.toGMTString(); 

	deleteOldWishlist();
}

function deleteOldWishlist(){
	var theWishlist = new Array();
	if(document.cookie){
		var thisCookie = document.cookie.split("; ");
		var expireDate = new Date();
		expireDate.setDate(expireDate.getDate()-1);
		for(var i=0;i<thisCookie.length;i++){
			var cookieName = thisCookie[i].split("=")[0];
			if(cookieName.indexOf("wishlist")>-1){
				document.cookie = cookieName + "=; expires=" + expireDate.toGMTString();
			}
		}
	}

	
}
// End of Convert Wish List


// Start of Wish List Counter
function initWishListCounter(){
	if(document.getElementById("wish-list")){
		wishListCounter();
	}
}

function wishListCounter(){
	var counter = 0;
	var theList = new Array();
	if(document.cookie){
		var thisCookie = document.cookie.split("; ");
		for(var i=0;i<thisCookie.length;i++){
			if(thisCookie[i].split("=")[0] == "wishList"){
				if(thisCookie[i].indexOf("_")>-1){
					theList = thisCookie[i].split("=")[1].split("_");
					counter = theList.length;
				}else{
					counter = 1;
				}
			}
		}
	}
	if(counter==0){
		document.getElementById("wish-list").innerHTML = "my wish list (" + counter + ")";
	}else{
		document.getElementById("wish-list").innerHTML = "my wish list <font color='white'> (" + counter + ")<\/font>";
	}
}
// End of Wish List Counter




// Start of Add To Wish List
function initAddToWishList(){
	 for(var i=0;i<document.links.length;i++){
		var thisLink = document.links[i];
		if(thisLink.className=="add-to-wishlist"){
			thisLink.onclick = addToWishList;
		}
	} 
}

function addToWishList(){
 	var thisCookie = document.cookie.split("; ");
	var theCurrentList = new Array();
	var counter = 0;
	for(var i=0;i<thisCookie.length;i++){
		if(thisCookie[i].split("=")[0]=="wishList"){
			var thisCookieVal = thisCookie[i].split("=")[1];
			if(thisCookieVal.indexOf("_")>-1){
				theCurrentList = thisCookieVal.split("_");
			}else{
				theCurrentList[0] = thisCookieVal;
			}
			counter = theCurrentList.length;
		}
	}

	for(var i=0;i<theCurrentList.length;i++){
		if(theCurrentList[i] == this.id){
			alert("This item is already in wish list.");
			addRecentlyViewedItem(this.id);
			return false;
		}
	}


    var theNewList;	
    if(theCurrentList.length>0){
	theNewList = theCurrentList[0];	
		for(var i=1;i<theCurrentList.length;i++){
			if(theCurrentList[i] != this.id){	
				theNewList += "_" + theCurrentList[i];
			}
		}
	theNewList += "_" + this.id;	
    }else{
	theNewList = this.id;
    }
    
	var expireDate = new Date();
	expireDate.setMonth(expireDate.getMonth()+36);
	document.cookie = "wishList=" + theNewList + ";expires=" + expireDate.toGMTString(); 
	var itemName = productInfoVal(this.id,"Item");
	itemName = (itemName.indexOf("<br")>-1)?itemName.split("<br")[0]:itemName;
	var alertMsg = itemName + " was successfully added to wish list.";
	alert(alertMsg);

	counter++;	

	document.getElementById("wish-list").innerHTML = "my wish list <font color='white'>(" + counter + ")<\/font>";

	addRecentlyViewedItem(this.id);

	return false;	
}
// End of Add To Wish List


// Start of Delete Form Wish List
function initDeleteFromWishList(){
	 for(var i=0;i<document.links.length;i++){
		var thisLink = document.links[i];
		if(thisLink.className=="delete-from-wishlist"){
			thisLink.onclick = deleteFromWishList;
			
		}
	} 
}

function deleteFromWishList(){
 	var itemName = (productInfoVal(this.id,"Item"))?productInfoVal(this.id,"Item"):"undefined";
	itemName = (itemName.indexOf("<br")>-1)?itemName.split("<br")[0]:itemName;
	var confirmMsg = "Do you want to delete " + itemName + " from wish list?";
  if(confirm(confirmMsg)){
	var expireDate = new Date();
	var thisCookie = document.cookie.split("; ");
	for(var i=0;i<thisCookie.length;i++){
		var cookieName = thisCookie[i].split("=")[0];
		var cookieVal = thisCookie[i].split("=")[1];
		if(cookieName=="wishList"){
		   var theCurrentList = new Array();
		   if(cookieVal.indexOf("_")>-1){
			theCurrentList = cookieVal.split("_");
		   }else{
			theCurrentList[0] = cookieVal;
		   }
		   if(theCurrentList.length > 1){
			var theNewList = (theCurrentList[0] != this.id)?theCurrentList[0]:theCurrentList[1];
		   	var counter = (theCurrentList[0] != this.id)?1:2;
		   	for(var j=counter;j<theCurrentList.length;j++){
		   		if(theCurrentList[j] != this.id){
					theNewList += "_" + theCurrentList[j];
				}
		   	}
		   	expireDate.setMonth(expireDate.getMonth()+36);
   	  	   	document.cookie = cookieName + "=" + theNewList  + "; expires=" + expireDate.toGMTString();
		   }else{
		   	expireDate.setMonth(expireDate.getDate()-3650);
  	  	   	document.cookie = cookieName + "=; expires=" + expireDate.toGMTString();
		   } 	

		}
	}
	window.location.reload();
   }	
	return false;	
    
}
// End of Delete Form Wish List

//Start of Delete Unlisted Items From Wishlist 
function initDeleteUnlistedFromWishlist(){
	
}
//End of Delete Unlisted Items From Wishlist 


//Start of Search Keywords
function initSearchKeywords(){
	if(thisPageName=="search"){
		searchKeywords();

	}
}

function searchKeywords(){

	var thisKeywords=thisFileLoc.split("=")[1];
	if(thisFileLoc.indexOf("&sortby")>-1){
		thisKeywords = thisKeywords.split("&sortby")[0];
	}
	var arrayKeywords = new Array();
	if(thisKeywords.indexOf("+")>-1){
		arrayKeywords = thisKeywords.split("+");
	}else{
		arrayKeywords[0] = thisKeywords;
	}
	var keyWords = arrayKeywords[0];
	for(var i=1;i<arrayKeywords.length;i++){
		keyWords += " " + arrayKeywords[i] ;
	}

	document.getElementById("input_text").value = keyWords;
}
//End of Search Keywords


//Start of Price List Message
function initPricelistMsg(){
	for(i=0;i<document.links.length;i++){
		var thisLink=document.links[i];
		if(thisLink.className=="pricelist_link"){
			var thisMsg=thisLink.childNodes[1]; 
			setPrincelistMsg(thisLink,thisMsg);
		}
	}
}

function setPrincelistMsg(thisLink,thisMsg){
	if(thisMsg){
		thisLink.msg=thisLink.childNodes[1];

		thisLink.onmouseover=showPricelistMsg;
		thisLink.onmouseout=hidePricelistMsg;
	}
	
}


function showPricelistMsg(){
	this.msg.style.visibility="visible";
	if(IE){
		this.msg.style.top=420+"px";
	}
}

function hidePricelistMsg(){
	this.msg.style.visibility="hidden";
}
//End of Price List Message




//Start of Change Content Size
function initContentSize(){
	if(document.getElementById("content") && thisPageName && document.getElementById("products_info")){
		changeContentSize();
	}
}


function changeContentSize(){
	var table1=document.getElementById("middle");
	var table2=document.getElementById("main");
	var table3=document.getElementById("content");
	var table4=document.getElementById("products_info");

	var tbH1 = table1.clientHeight;
	var tbW1= table1.clientWidth;
	var tbH2 = table2.clientHeight;
	var tbW2= table2.clientWidth;
	var tbH3 = table3.clientHeight;
	var tbW3= table3.clientWidth;
	var tbH4 = table4.clientHeight;
	var tbW4= table4.clientWidth;

	var bdH = document.body.clientHeight;
	var bdW = document.body.clientWidth;
	var leftW = document.getElementById("left_navi").clientWidth;
	var midLeftW = (document.getElementById("recently-viewed"))?document.getElementById("recently-viewed").clientWidth:0;
	var topH = document.getElementById("header").clientHeight;
	var bottomH = document.getElementById("bottom_navi").clientHeight;
 
	var NS = (navigator.appName=="Netscape")?true:false;
	var winH=(NS)?window.innerHeight:document.body.clientHeight;
	var footerH=document.getElementById("footer").clientHeight;

	//var newH = (tbH4 + 30 >500)?tbH4 + 30:500;
	var newH = (tbH3<505)?505:(bdH > tbH3 + 150)?tbH4:505;
	var newW = bdW;

//alert("tbH1 = " + tbH1 + " "+" tbH2 = " + tbH2 + " "+" tbH3 = "+ tbH3 + " "+" tbH4 = "+ tbH4 + " ");

	table1.style.width = newW + "px";
	table2.style.width = newW + "px";
	table3.style.width = newW - leftW - midLeftW - 15 + "px";

	//table1.style.height = newH + "px";
	//table2.style.height = newH + "px";
	//table3.style.height = newH + "px";
	
	if(tbW1 < tbW4){
		var msgArea=document.getElementById("bottom_msg");
		msgArea.innerHTML = "please scroll right to view more items.";
	}

	if(tbW1 > tbW4){
		var msgArea=document.getElementById("bottom_msg");
		msgArea.innerHTML = "";
	}

}
//End of Change Content Size



//Start of Show Current Navi
function initCurrentPage(){
	if(thisPageName && thisFileName!="print" && thisFileName!="popup"){
		showCurrentNavi();
	}
}

function showCurrentNavi(){
		var pageName="";
		switch(thisPageName){
			case "allproducts-1":
				pageName = "all items-1";
				break;
			case "allproducts-2":
				pageName = "all items-2";
				break;
			case "allproducts-3":
				pageName = "all items-3";
				break;
			case "allproducts-4":
				pageName = "all items-4";
				break;
			case "recentview":
				pageName = "recently viewed items";
				break;
			case "search":
				pageName = "search";
				break;
			case "productId":
				pageName = "recently viewed item";
				break;
			case "recentlyviewed":
				pageName = "recently viewed";
				break;
			default:
				pageName = subcgName(thisPageName);
		}



		var addData="";
		switch(thisPageName){
			case "search": 
				var thisKeywords=thisFileLoc.split("=")[1];
				if(thisFileLoc.indexOf("&sortby")>-1){
					thisKeywords = thisKeywords.split("&sortby")[0];
				}
				thisKeywords=(thisKeywords=="enter+keyword%28s%29")?"":thisKeywords;
				addData = "keyword(s): " + thisKeywords;
				break;
			case "cecchini":
				addData = "<img src='images/icon_pdf.jpg' \/>&nbsp;<a class='pricelist_link' href='#' id='pdf/cecchini_price-list.pdf' target='_blank'>price list ...<span class='pricelist_msg'>(817KB) loading may take a few minutes.<\/span><\/a>";
				break;
			case "verpan":
				addData = "<img src='images/icon_pdf.jpg' \/>&nbsp;<a class='pricelist_link' href='#' id='pdf/PantonLightingPriceList.pdf' target='_blank'>price list ...<span class='pricelist_msg'>(438KB) loading may take a few minutes.<\/span><\/a>";
				break;
			case "eeroaarnio":
				addData = "<img src='images/icon_pdf.jpg' \/>&nbsp;<a class='pricelist_link' href='#' id='pdf/EEROAARNIOEDITION.pdf' target='_blank'>price list ...<span class='pricelist_msg'>(170KB) loading may take a few minutes.<\/span><\/a>";
				break;
			case "cite-goes-dutch":
				addData = "<img src='images/icon_pdf.jpg' \/>&nbsp;<a class='pricelist_link' href='#' id='pdf/400YearsLater_CiteGoesDutch_Catalog.pdf' target='_blank'>catalog \/ booklet ...<span class='pricelist_msg'>(3393KB) loading may take a few minutes.<\/span><\/a>";
				break;
			case "maruni":
				addData = "<img src='images/icon_pdf.jpg' \/>&nbsp;<a class='pricelist_link' href='#' id='pdf/Maruni_12-30-2009.pdf' target='_blank'>price list ...<\/a>";
				break;
			case "recentview":
				break;
			default:

		}
			
		document.getElementById("navi_current").innerHTML = "<ul id='current_info'><li>you are in ... "  + pageName + "<\/li><li class='blank'>&nbsp;<\/li><li>" + addData + "<\/li><li class='blank'>&nbsp;<\/li><li>click on any image <br \/>for larger view<\/li><li class='blank'>&nbsp;<\/li><li>all prices are US$.<\/li>" ;
}

function subcgName(thisSubcgId){
	if(thisSubcgId){
		for(var i=0; i<subcgInfo.length; i++){
			if(subcgInfo[i].split("=")[0]==thisSubcgId){
				return subcgInfo[i].split("=")[1].split(":")[0];
			}
		}
	}
}
//End of Show Current Navi





// Start of Current Link
function initCurrentLink(){
	for(var i=0; i<document.links.length; i++){
		var thisLink = document.links[i];
		if(thisLink.href == thisFileLoc){
			changeStyle(thisLink);
		}
	}
}

function changeStyle(thisLink){
	thisLink.className = (thisLink.className)? thisLink.className + "current":"current";

}
// End of Current Link


// Start of Products
function initProducts(){
	if(thisPageName && thisFileName!="print" && thisFileName!="popup"){
		switch(thisPageName){
			case "recentlyviewed": 
				arrayRecentlyViewed();
				break;
			case "productId":
				arrayProductId();
				break;
			case "wishlist": 
				arrayWishList();
				break;
			case "search": 
				if(thisFileName!="products"){
					var keyWords = thisFileLoc.split("search=")[1];
					window.location = "products.html?search=" + keyWords;
				}
				arraySearch();
				break;
			case "allproducts-1":
			case "allproducts-2":
			case "allproducts-3":
			case "allproducts-4":
				arrayAllProducts();
				break;
			//case "recentview":
				//arrayRecentView();
				//break;
			default:
				arrayProducts();
		}

	}
	else{
		switch(thisFileName){
			case "popup": 
				return false;
				break;
			case "print":
				showPrintPage(thisPageName);
				break;
			default:
		}
	}

}



function arrayRecentlyViewed(){
	if(document.cookie){
		var thisCookie = document.cookie.split("; ");
		var theViewedItems = new Array();
		for(var i=0;i<thisCookie.length;i++){
			var thisCookieName = thisCookie[i].split("=")[0];
			if(thisCookieName.indexOf("recentlyViewedItems")>-1){
				theViewedItems = thisCookie[i].split("=")[1].split("_");
			}
		}
		showProducts(theViewedItems);
	}
	
}



function arrayProductId(){
	var thisProductId = thisFileLoc.split("=")[1];
	var theProductList = new Array();
	theProductList[0] = thisProductId;
	showProducts(theProductList);
}


function arraySearch(){
		var foundProducts = new Array;
		var allFoundProducts = new Array;
		var inputAllText = (thisFileLoc.indexOf("&")>-1)?thisFileLoc.split("=")[1].split("&")[0]:thisFileLoc.split("=")[1];
		var inputText = new Array;
		if(inputAllText.indexOf("+")>-1){
			inputText = inputAllText.split("+");
		}
		else{
			inputText[0] = inputAllText;
		}



   if(inputText[0]=="" | inputText[0]+inputText[1]=="enterkeyword%28s%29"){
			document.getElementById("content").innerHTML = "<br \/><br \/><br \/><br \/><br \/><br \/><br \/><br \/>Please input key word(s).";
			//thisFileLoc.split("=")[1]="";
			
			return false;
   }
   else{	
	var counterPI = 0;
	var productInfoL = productInfo.length;
		//document.getElementById("test").innerHTML=inputText.length + "==="  + productInfo.length;

	for(j=0; j<subcgInfo.length; j++){
		var thisSubcg = subcgInfo[j];
		var thisSubcgArray = thisSubcg.split(":")[1].split("_");
		var thisSubcgTitle = thisSubcg.split("=")[1].split(":")[0];
		for(n=0; n<thisSubcgArray.length; n++){
			productInfo[productInfoL + counterPI] = thisSubcgArray[n] + "_subcategory^=" + thisSubcgTitle;
			counterPI++;
		}
	}
		

	   for(k=0; k<inputText.length; k++){
		var thisKeyWord = inputText[k].toLowerCase();

		for(var i=0; i<productInfo.length; i++){		
			var productInfoId = productInfo[i].split("_")[0]+"_";
			var thisProductInfo = productInfo[i].toLowerCase();
			if(thisProductInfo.indexOf(thisKeyWord)>-1){
				if(!foundProducts[k]){
					foundProducts[k] = productInfoId;
				}
				if(foundProducts[k] && foundProducts[k].indexOf(productInfoId)==-1){
					foundProducts[k] += productInfoId;
				}
			}
			
		}
		if(!foundProducts[k] && k!=0){
			foundProducts[k]="_";
		}
	   }

	  if(!foundProducts[0]){
		document.getElementById("content").innerHTML = "<br \/><br \/><br \/><br \/><br \/><br \/><br \/><br \/>No items were found. Please try a different keyword.";
			return false;
	  }
	  else{	
	     	if(inputText.length==1){
			for(p=0;p<foundProducts[0].split("_").length-1;p++){
				allFoundProducts[p]=foundProducts[0].split("_")[p];
			}
	    	 }
	    	 else{
			var counterA = 0;
			var firstArray = foundProducts[0].split("_");
			for(m=0; m<firstArray.length-1; m++){
				var thisProduct = firstArray[m]+"_";
				var counterF = 0;
				for(n=1; n<foundProducts.length; n++){
					if(foundProducts[n].indexOf(thisProduct)>-1){
	  					counterF++;
					}
				}
				if(counterF==inputText.length-1){
					allFoundProducts[counterA] = thisProduct.split("_")[0];
					counterA++;	
				}
			}		
   	  	}

		if(allFoundProducts.length == 0){
			document.getElementById("content").innerHTML = "<br \/><br \/><br \/><br \/><br \/><br \/><br \/><br \/>No items were found. Please try a different keyword.";
			return false;
		}
		else{
			showProducts(allFoundProducts);
		}
	  }
   }
		
	   
}	

function arrayWishList(){
	var thisCookie = document.cookie.split("; ");
	var counter = 0;
	var theWishList = new Array();
	for(var i=0;i<thisCookie.length;i++){
		var thisCookieName = thisCookie[i].split("=")[0];
		var thisCookieVal = thisCookie[i].split("=")[1];
		if(thisCookieName == "wishList"){
			if(thisCookieVal.indexOf("_")>-1){
				theWishList = thisCookieVal.split("_");
			}else{
				theWishList[0] = thisCookieVal;
			}
			counter++;
		}
	}

	if(counter == 0){
		document.getElementById("content").innerHTML = "<br \/><br \/><br \/><br \/><br \/><br \/><br \/><br \/>No items were found in your wish list.";
	}else{
		showProducts(theWishList);
	}
}

function arrayAllProducts(){
		var allProductId = new Array;
		var n=0;
		var m=0;
		switch(thisPageName){
			case "allproducts-1":
				n=0;
				m=300;
				break;
			case "allproducts-2":
				n=300;
				m=600;
				break;
			case "allproducts-3":
				n=600;
				m=900;
				break;
			case "allproducts-4":
				n=900;
				m=productInfo.length-1;
				break;
			default:
		}

		for(var i=n; i<m; i++){
			var thisProductId = productInfo[i].split("_")[0];
			var counter=0;
			for(var j=0; j<allProductId.length; j++){
				if(allProductId[j] == thisProductId){
					counter++;
				}
			}
			if(counter == 0){
				allProductId[j] = thisProductId;
			}
		}
		showProducts(allProductId);
}



function arrayProducts(){
	// cecchini intro is under construction...
	//if (thisPageName == "cecchini") {
	//	cecchiniIntro()
	//}
	//else {
		for (var i = 0; i < subcgInfo.length; i++) {
			var thisInfoId = subcgInfo[i].split("=")[0];
			var thisInfoList = subcgInfo[i].split(":")[1].split("_");
			if (thisInfoId == thisPageName) {
				showProducts(thisInfoList);
			}
		}
	//}
}	

function cecchiniIntro(){
	//alert('test');
		closeLeftMenu();
		$('<div id="cecchini_frame">').appendTo('div#content');
		/*$('td#left_navi').add('div#recently-viewed').animate({
			width:'0'
		},2000,function(){
			$('td#left_navi').css('display','none');
			$('div#recently-viewed').css('width','30');
		});*/
		
		/*for (var i = 0; i < subcgInfo.length; i++) {
			var thisInfoId = subcgInfo[i].split("=")[0];
			var thisInfoList = subcgInfo[i].split(":")[1].split("_");
			if (thisInfoId == thisPageName) {
				showProducts(thisInfoList);
			}
		}*/
}

function showProducts(thisArray){
	if(thisArray){
		if(thisFileLoc.indexOf("&")>-1){
		
			thisArray = arraySortBy(thisArray);
		
		}
	
		document.getElementById("content").innerHTML = "<table id='products_info'>" +  tableData(thisArray) + "<\/table>";
	}


	var allLinks=document.links;
	for(var i=0; i<allLinks.length; i++){
		if(allLinks[i].id.indexOf("image=")>-1){
			var thisW = allLinks[i].firstChild.width;
			if(thisW > 200){
				allLinks[i].parentNode.style.width=(IE)?thisW:"";
				allLinks[i].parentNode.style.minWidth=(IE)?0:"200px";
			}
			else{
				allLinks[i].parentNode.style.width=(IE)?"200px":"";
				allLinks[i].parentNode.style.minWidth=(IE)?0:"200px";
			}
		}
	}

	if(document.getElementById){	
	}
	else{
		alert("Sorry, your browser doesn't support this script.");	
	}
	
	changeContentSize();
	return false;
}

function arraySortBy(thisArray){

	if(thisFileLoc.indexOf("sortby=")>-1){
		var theTempArray = new Array();
		var theSortedArray = new Array();
		var thisSortName = thisFileLoc.split("sortby=")[1];
		for(var i=0; i<thisArray.length; i++){
			var thisProductId = thisArray[i];
			var thisItem = productInfoVal(thisProductId,"Item");
			var thisList = productInfoVal(thisProductId,"List");
			//if(thisList && thisList.indexOf("$")>-1){
			if(thisList){
			   if(thisList.indexOf(" ")>-1 && thisList.indexOf("$")>-1){
				thisList = thisList.split("$")[1].split(" ")[0];
			   }
			   if(thisList.indexOf("<br />")>-1 && thisList.indexOf("$")>-1){
				thisList = thisList.split("$")[1].split("<br />")[0];
			   }
			   if(thisList.indexOf("$")>-1){
				thisList = thisList.split("$")[1];
			   }
			   if(thisList.indexOf("price upon request")>-1){
				thisList = 9999999999999;
			   }
			}else{
				thisList = 9999999999999;
			}

			thisList = Number(thisList);
			theTempArray[i] = {productId:thisProductId,itemName:thisItem,listPrice:thisList};
		    
		}

		function sortByNameAscend(a, b){
			a = a.itemName.toLowerCase();
			b = b.itemName.toLowerCase();
			return ((a < b) ? -1 : ((a > b) ? 1 : 0));
		}

		function sortByNameDescend(a, b){
			a = a.itemName.toLowerCase();
			b = b.itemName.toLowerCase();
			return ((a < b) ? 1 : ((a > b) ? -1 : 0));
		}

		function sortByPriceAscend(a, b){
			return a.listPrice - b.listPrice;
		
		}

		function sortByPriceDescend(a, b){
			return b.listPrice - a.listPrice;
		
		}


		switch(thisSortName){
			case "nameAscend":
				theTempArray.sort(sortByNameAscend);
				break;
			case "nameDescend":
				theTempArray.sort(sortByNameDescend);
				break;
			case "priceAscend":
				theTempArray.sort(sortByPriceAscend);
				break;
			case "priceDescend":
				theTempArray.sort(sortByPriceDescend);
				break;
			default:
		}
		

		for(var i=0; i<theTempArray.length; i++){
			theSortedArray[i]=theTempArray[i].productId;
		}
		

		return theSortedArray;
		
	}
}



function tableData(thisArray){
	var rowImage = "<tr>";
	var rowInfo = "<tr>";

	var imageVal = new Array;
	var itemVal = new Array;
	var itemBr = new Array;
	var descVal = new Array;
	var descBr = new Array;
	var colorVal = new Array;
	var colorBr = new Array;
	var dimVal = new Array;
	var dimBr = new Array;
	var avaVal = new Array;
	var avaBr = new Array;
	var listVal = new Array;
	var listBr = new Array;
	var miscVal = new Array;
	var miscBr = new Array;

	var counterImage = 0;
	var counterItem = 0;
	var counterDesc = 0;
	var counterColor = 0;
	var counterDim = 0;
	var counterAva = 0;
	var counterList = 0;
	var counterMisc = 0;


	for(var i=0; i<thisArray.length; i++){
			var allTitles = new Array("image","Item","Description","Color","Dimensions","Availability","List","");
			var counter = 0;
			for(var j=0; j<productInfo.length-1; j++){
				var thisInfoId = productInfo[j].split("_")[0];
				var nextInfoId = productInfo[j+1].split("_")[0];
				var thisInfoTitle = productInfo[j].split("_")[1].split("^=")[0];
				var thisTitle;
					switch(thisInfoTitle){
						case "Size": 
							thisTitle = "Dimensions";
							break;
						case "Materials":
							thisTitle = "Description";
							break;
						default:
							thisTitle = thisInfoTitle;
					}				
				var thisInfoVal = productInfo[j].split("^=")[1];
				

				if(thisArray[i]==thisInfoId){
					counter++;
					switch(thisTitle){
						case "image": 
							imageVal[i] = thisInfoVal;    
							allTitles[0] += "!";
							counterImage++;
							break;
						case "Item":
							itemVal[i] = thisInfoTitle + "===" + thisInfoVal; 
							itemBr[i] = thisInfoVal.split("<br").length; 
							allTitles[1] += "!";
							counterItem++;
							break;
						case "Description":
							descVal[i] = thisInfoTitle + "===" + thisInfoVal; 
							descBr[i] = thisInfoVal.split("<br").length; 
							allTitles[2] += "!";
							counterDesc++;
							break;
						case "Color":
							colorVal[i] = thisInfoTitle + "===" + thisInfoVal; 
							colorBr[i] = thisInfoVal.split("<br").length; 
							allTitles[3] += "!";
							counterColor++;
							break;
						case "Dimensions":
							dimVal[i] = thisInfoTitle + "===" + thisInfoVal;
							dimBr[i] = thisInfoVal.split("<br").length; 
							allTitles[4] += "!";
							counterDim++;
							break;
						case "Availability":
							avaVal[i] = thisInfoTitle + "===" + thisInfoVal; 
							avaBr[i] = thisInfoVal.split("<br").length; 
							allTitles[5] += "!";
							counterAva++;
							break;
						case "List":
							listVal[i] = thisInfoTitle + "===" + thisInfoVal; 
							listBr[i] = thisInfoVal.split("<br").length; 
							allTitles[6] += "!";
							counterList++;
							break;
						case "":
							miscVal[i] = thisInfoTitle + "===" + thisInfoVal; 
							miscBr[i] = thisInfoVal.split("<br").length; 
							allTitles[7] += "!";
							counterMisc++;
							break;
						default:	
					}
				   if(counter > 0 && thisArray[i]!=nextInfoId){
					j=productInfo.length;
				   }
				}
				
			}
	}

	for(k=0; k<thisArray.length; k++){
		var imageInfo =(imageVal[k])?imageVal[k]:"";
		//var itemInfo =(itemVal[k])? itemVal[k].split("===")[0] + ": " + itemVal[k].split("===")[1] + "=="+thisArray[k] :"&nbsp;";
		var itemInfo =(itemVal[k])? itemVal[k].split("===")[0] + ": " + itemVal[k].split("===")[1]:"&nbsp;";
		var itemNameInfo =(itemVal[k])? itemVal[k].split("===")[1]:"&nbsp;";
		var itemName =(itemNameInfo.indexOf("<br")>-1)? itemNameInfo.split("<br")[0]:itemNameInfo;
		var descInfo =(descVal[k])? descVal[k].split("===")[0] + ": " + descVal[k].split("===")[1]:"&nbsp;";
		var colorInfo =(colorVal[k])?colorVal[k].split("===")[0] + ": " + colorVal[k].split("===")[1]:"&nbsp;";
		var dimInfo =(dimVal[k])?dimVal[k].split("===")[0] + ": " + dimVal[k].split("===")[1]:"&nbsp;";
		var avaInfo =(avaVal[k])?avaVal[k].split("===")[0] + ": " + avaVal[k].split("===")[1]:"&nbsp;";
		var listInfo =(listVal[k])?listVal[k].split("===")[0] + " Price: " + listVal[k].split("===")[1]:"&nbsp;";
		if(miscVal[k]){
		var miscInfoIcon ="";
			if(miscVal[k].split("===")[1].indexOf("price list")>-1 || miscVal[k].split("===")[1].indexOf("more info")>-1){
				miscInfoIcon = "icon_pdf.jpg";
			}
			else{
				miscInfoIcon = "icon_image.jpg";
			}
		}
		//var miscInfo =(miscVal[k])?"<img src='images/" + miscInfoIcon + "' \/>&nbsp;" + miscVal[k].split("===")[1]:"&nbsp;";
		var miscInfo =(miscVal[k])?miscVal[k].split("===")[1]:"&nbsp;";
	

		if(counterImage!=0){
			rowImage += "<td class='td_image' valign='bottom'><div ><a href='#' id='image=" + thisArray[k] +  "' class='newWin'><img src='images/" + imageInfo + "_s.jpg' alt='" + itemName + "' \/><\/a><\/div><\/td>";
		}
		rowInfo += "<td class='td_info'><ul id='productId=" + thisArray[k] + "'>";
		if(counterMisc!=0){
			//rowInfo += "<li>" + miscInfo + tdBreak(miscBr,k);
			rowInfo += "<li>" + miscInfo + tdBreak(miscBr,k);
		}

		var wishlistLink;
		if(thisPageName=="wishlist"){
			wishlistLink = "<a href='#' id='" + thisArray[k] + "' class='delete-from-wishlist'>remove<\/a>";
		}else{
			wishlistLink = "<a href='#' id='" + thisArray[k] + "' class='add-to-wishlist'>add to wish list<\/a>";
		}
		//use upper line to show item IDs.
		//rowInfo += "<li>" + wishlistLink + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + "<img src='images/icon_print.jpg' \/>&nbsp;<a href='#' id='" + thisArray[k] + "' class='printWin'>print...<\/a> " + thisArray[k] +"<\/li><li class='td_blank'>&nbsp;<\/li>";
		rowInfo += "<li>" + wishlistLink + "&nbsp;&nbsp;&nbsp;" + "<img src='images/icon_print.jpg' \/>&nbsp;<a href='#' id='" + thisArray[k] + "' class='printWin'>print<\/a>&nbsp;&nbsp;&nbsp;<img src='images/icon_email.jpg' \/>&nbsp;<a href='#' id='product_email_form.php?productId=" + thisArray[k] + "' class='moreWin'>email<\/a><\/li><li class='td_blank'>&nbsp;<\/li>";

		if(counterItem!=0){
			rowInfo += "<li>"  + itemInfo + tdBreak(itemBr,k);
		}
		if(counterDesc!=0){
			rowInfo += "<li>"  + descInfo + tdBreak(descBr,k);
		}
		if(counterColor!=0){
			rowInfo += "<li>" + colorInfo + tdBreak(colorBr,k);
		}
		if(counterDim!=0){
			rowInfo += "<li>" + dimInfo + tdBreak(dimBr,k);
		}
		if(counterAva!=0){
			rowInfo += "<li>" + avaInfo + tdBreak(avaBr,k);
		}
		if(counterList!=0){
			rowInfo += "<li>" + listInfo + tdBreak(listBr,k);
		}
		

	}
		rowImage += "<\/tr>";
		if(thisPageName=="productId"){
			var thisProductId = thisFileLoc.split("=")[1];
			var subcgTitleList = new Array();
			var counter = 0;
			for(var i=0;i<subcgInfo.length;i++){
				var subcgInfoVal = subcgInfo[i].split(":")[1];
				var thisSubcgList = subcgInfoVal.split("_");
				var subcgTitle = subcgInfo[i].split("=")[1].split(":")[0];
				var listCounter = 0;
			   for(var j=0;j<thisSubcgList.length;j++){
				if(thisSubcgList[j]==thisProductId){
					listCounter++;
				}
			   }
			   if(listCounter>0){
					subcgTitleList[counter] = subcgTitle;
					counter++;
			   }

			}
		}

		if(subcgTitleList){
			var thesubcgTitleList = "<td class='td_info'><ul><li>subcategories<\/li><br \/>";
			for(i=0;i<subcgTitleList.length;i++){
				var thisSubcgName = findSubcgName(subcgTitleList[i]);
				thesubcgTitleList += "<li><a class='subcg' href='products.html?" + thisSubcgName + "'>" +subcgTitleList[i] + "<\/a><\/li><br \/>";
			}
			thesubcgTitleList += "<\/ul><\/td>"
		}


		rowInfo +=(thisPageName=="productId")?"<\/ul><\/td>" + thesubcgTitleList + "<\/tr>":"<\/ul><\/td><\/tr>";

		return rowImage+rowInfo;
}


function tdBreak(thisBr,thisNum){
	var allBr = "";
	var thisBrNum = (thisBr[thisNum])?thisBr[thisNum]:1;
	var difBr =maxNum(thisBr)-thisBrNum;

	if(difBr>0){
		for(i=0; i<difBr+1; i++){
			allBr += "<br \/>";
		}
	}

	allBr += "<\/li><li class='td_blank'>&nbsp;<\/li>";

	return  allBr;
}

function maxNum(thisArray){
	var maxNum = 0;
	for(i=0; i<thisArray.length; i++){
		if(thisArray[i]>maxNum){
			maxNum = thisArray[i];
		}
	}
	return maxNum;
}


function productInfoVal(thisId,thisTitle){
	var counter = 0;
	var thisVal;
	for(var i=0; i<productInfo.length; i++){
		var thisInfo=productInfo[i];
		var thisInfoId=thisInfo.split("_")[0];
		var thisInfoTitle=thisInfo.split("_")[1].split("^=")[0];
		var thisInfoDetail=thisInfo.split("^=")[1];
		if(thisId==thisInfoId && thisTitle==thisInfoTitle){
			thisVal = thisInfoDetail;
			counter++;
		}
	}	
	
	if(counter == 1){
		return thisVal;
	}
	if(counter == 0){
		//return "error: No data found.";
		return false;
	}
	else{
		return "error: Dupulicated data found.";
	}

}
// End of Products




// Start of Categories
function initCategories() {
	
	
	var allLinks = document.getElementsByTagName("a");
	
	for (var i=0; i<allLinks.length; i++) {
		if (allLinks[i].className.indexOf("category") > -1) {
			allLinks[i].onclick = function() {return false;}
			allLinks[i].onmouseover = toggleMenu;
		}
	}
}


function toggleMenu() {
	var startMenu = this.href.lastIndexOf("/")+1;
	var stopMenu = this.href.lastIndexOf(".");
	var thisMenuName = this.href.substring(startMenu,stopMenu);

	document.getElementById(thisMenuName).style.display = "block";
	document.getElementById(thisMenuName).style.visibility = "visible";
	

	this.parentNode.className = thisMenuName;
	this.parentNode.onmouseover = toggleDivOn;
	this.parentNode.onmouseout = toggleDivOff;
}

function toggleDivOn() {
	document.getElementById(this.className).style.display = "block";
	//document.getElementById(thisMenuName).style.visibility = "hidden";

}

function toggleDivOff() {
	document.getElementById(this.className).style.display = "none";
	
}
// End of Categories




// Start of Subcategories
function initSubcg(){
	var theSubcg=document.getElementById("subcategories");
	if(theSubcg){
		writeSubcg(theSubcg);
	}
}


function writeSubcg(thisSubcg){
	subcgInfo.sort();

	var allOptions;

	for(var i=0; i<subcgInfo.length; i++){
		allOptions += "<option value='" + subcgInfo[i].split("=")[0] + "'>" + subcgInfo[i].split("=")[1].split(":")[0] + "</option>";
	}	

	thisSubcg.innerHTML="<select id='newLocation'><option selected='selected'>subcategories</option>" + allOptions + "</select>";

}
// End of Subcategories	



// Start of Select Go
function initSelectGo(){
	if(document.getElementById("newLocation")){
		document.getElementById("newLocation").selectedIndex = 0;
		document.getElementById("newLocation").onchange = jumpPage;
	}
}

function jumpPage(){
	var newLoc = document.getElementById("newLocation");
	var newPage = newLoc.options[newLoc.selectedIndex].value;

	if(newPage!=""){
		switch(newPage){
			case "nuevo":
				var nuevoWin = window.open("http://www.nuevoliving.com","nuevo","width=800,hight=400,resizable=yes,toolbar=yes,location=no,scrollbars=auto");
				nuevoWin.focus();
				document.getElementById("newLocation").selectedIndex = 0;
				break;
			case "wabnitz":
				var wabnitzWin = window.open("http://www.wabnitzeditions.com/","wabnitz","width=1000,hight=600,resizable=yes,toolbar=yes,location=no,scrollbars=auto");
				wabnitzWin.focus();
				document.getElementById("newLocation").selectedIndex = 0;
				break;
			default:
				addRecentlyViewedSubcg(newLoc.options[newLoc.selectedIndex].value);
				window.location = "products.html?" + newPage ;
		}		

		/*if(newPage == "nuevo"){
			var nuevoWin = window.open("http://www.nuevoliving.com","nuevo","width=800,hight=400,resizable=yes,toolbar=yes,location=no,scrollbars=auto");
			document.getElementById("newLocation").selectedIndex = 0;
		}
		else{
			addRecentlyViewedSubcg(newLoc.options[newLoc.selectedIndex].value);
			window.location = "products.html?" + newPage ;
		}*/
	}

}
// End of Select Go


// Start of Sort By
function initSortby(){
	var theSortby=document.getElementById("sortbyNames");
	if(theSortby && thisPageName){
		writeSortby(theSortby);
	}
	if(theSortby && !thisPageName){
		document.getElementById("category-1").style.top = "190px";
		document.getElementById("category-2").style.top = "215px";
		document.getElementById("category-3").style.top = "240px";
		document.getElementById("category-4").style.top = "265px";
		document.getElementById("category-5").style.top = "290px";
		//document.getElementById("category-6").style.top = "315px";
		document.getElementById("category-6").style.top = "330px";
		//document.getElementById("category-8").style.top = "385px";
	}

}


function writeSortby(thisSortNames){

	thisSortNames.innerHTML='<select id="newSort"><option onchange="location.href=this[this.selectedIndex].value">sort by&nbsp</option><option value="nameAscend">item: a to z&nbsp</option><option value="nameDescend">item: z to a&nbsp</option><option value="priceAscend">price: low to high&nbsp</option><option value="priceDescend">price: high to low&nbsp</option></select>';

}
// End of Sort By	



// Start of Sort Select Go
function initSortSelectGo(){
	if(document.getElementById("newSort")){
		document.getElementById("newSort").selectedIndex = 0;
		document.getElementById("newSort").onchange = sortPage;
	}
}

function sortPage(){
	var newLoc = document.getElementById("newSort");
	var newSortName = newLoc.options[newLoc.selectedIndex].value;
	var theFileLoc=(thisFileLoc.indexOf("&")>-1)?thisFileLoc.split("&")[0]:thisFileLoc;
	
	window.location = theFileLoc + "&sortby=" + newSortName ;

}
// End of Sort Select Go

// Start of Sort Selected
function initSortSelected(){
	if(thisFileLoc.indexOf("sortby=")>-1){

		sortSelected();
	}
}

function sortSelected(){
	var theSortList = document.getElementById("newSort");
	var thisSortName = thisFileLoc.split("sortby=")[1];
	switch(thisSortName){
		case "nameAscend":
		theSortList.selectedIndex=1;
		break;
		case "nameDescend":
		theSortList.selectedIndex=2;
		break;
		case "priceAscend":
		theSortList.selectedIndex=3;
		break;
		case "priceDescend":
		theSortList.selectedIndex=4;
		break;
		default:
	}
}
// End of Sort Selected


// Start of New Window
function initNewWin(){

	var allLinks = document.getElementsByTagName("a");
	for(var i=0; i<allLinks.length; i++){
		/*if(allLinks[i].className == "imageWin"){
			allLinks[i].onclick = imageWindow;
			
		}*/

		
		if(allLinks[i].className == "newWin"){
			allLinks[i].onclick = newWindow;
			
		}

		if(allLinks[i].className == "printWin"){
			allLinks[i].onclick = printWindow;
			
		}

		if(allLinks[i].className == "moreWin"){
			allLinks[i].onclick = moreWindow;
			
		}
		if(allLinks[i].className == "more-images"){
			allLinks[i].onclick = moreImages;
			
		}

		if(allLinks[i].className == "pricelist_link"){
			allLinks[i].onclick = moreWindow;
			
		}
	}
}

function moreImages(){
	//var theProductId = $(this).parents.parents.attr('id');
	var theProductId = $(this).parent().parent().attr('id').split("=")[1];
	var theCaptions = productInfoVal(theProductId,'caption');
	var theCaptionsArray = new Array();
	if(theCaptions.indexOf("_")>-1){
		theCaptionsArray = theCaptions.split("_");
	}else{
		theCaptionsArray[0] = theCaptions;
	}
	//var theCaptionsNum = (theCaptionsArray[0]=="")?0:theCaptionsArray.length;
	var theCaptionsNum = theCaptionsArray.length;
	var imageCounter = 1;

	$(function(){
		$('body').css('height', '100%'); // IE6 Hack
		$('<div id="overlay"></div>').appendTo('body');
		$('div#overlay').css('filter','alpha(opacity=70)'); // For IE
		$('div#overlay').fadeIn(500);
		$('<div id="more-images_frame"></div>').appendTo('body').fadeIn(500);
		$('div#more-images_frame').animate({
			height: '600px'
		},500);
		var slideShowWidth=(theCaptionsNum<8)?'690px':'750px';
		$('div#more-images_frame').animate({
			width: slideShowWidth
		},1000);
		$('<div id="more-images_thumbnails"></div>').appendTo('div#more-images_frame');
		$('<div id="more-images_thumbnails_2"></div>').appendTo('div#more-images_frame');

		
		$(function(){
			var imageCounter=1;
			for (var i = 0; i < theCaptionsNum; i++) {
				if(imageCounter==1){
					$('<a href="#"><img class="current" src="images/' + imageInfo(theProductId) + '_' + imageCounter + '_ss.jpg" /></a><br />').appendTo('div#more-images_thumbnails');
				}else if (imageCounter < 8) {
					$('<a href="#"><img src="images/' + imageInfo(theProductId) + '_' + imageCounter + '_ss.jpg" /></a><br />').appendTo('div#more-images_thumbnails');
				}else{
					$('<a href="#"><img src="images/' + imageInfo(theProductId) + '_' + imageCounter + '_ss.jpg" /></a><br />').appendTo('div#more-images_thumbnails_2');
				}
				imageCounter++;
			}
			
		//preloading images
		$('div#more-images_thumbnails img').add('div#more-images_thumbnails_2 img').each(
			function(){
			var theImgSrc = $(this).attr('src').split('_ss')[0] + '.jpg';
			$('<img>').attr('src',theImgSrc);
			}
		);
			
			if(imageCounter<8){
				$('div#more-images_thumbnails_2').hide();
			}
		});
		$('<div id="more-images_main"></div>').appendTo('div#more-images_frame');
		$('<a id="more-images_close" href="#">close&nbsp;<img src="images/close_icon.jpg" alt="close" /></a>').appendTo('div#more-images_main');
		$('<div id="more-images_title"><h1>Item&#58;&nbsp;'+ productInfoVal(theProductId,'Item')+'</h1></div>').appendTo('div#more-images_main');
		$('<div id="slideShowImage"><img src="images/'+ imageInfo(theProductId)+ '_1.jpg" /></div>').appendTo('div#more-images_main');
		$('<div id="more-images_caption">' + theCaptionsArray[0] + '</div>').appendTo('div#more-images_main');
		$('<div id="more-images_navi"><a id="previousImage" href="#">&lt;&lt;previous</a>&nbsp;&nbsp;&nbsp;<a id="nextImage" href="#">next&gt;&gt;</a></div>').appendTo('div#more-images_main');
		if(theCaptionsNum>7){
			$('div#more-images_main').addClass('wider');	
		}


		$('div#more-images_frame').children().hide();
		setTimeout("$('div#more-images_frame').children().fadeIn(1000);",2000);
		
		$('div#more-images_thumbnails a img').add('div#more-images_thumbnails_2 a img').click(
			function($e){
				$e.preventDefault();
				var theImageFile = $(this).attr('src').split('_ss')[0];
				imageCounter = theImageFile.split('_').pop();
				$('div#more-images_caption').text(theCaptionsArray[imageCounter-1]);
				$('div#slideShowImage img').attr('src', theImageFile + '.jpg').hide().fadeIn(1000);
				$('div#more-images_thumbnails a img').add('div#more-images_thumbnails_2 a img').removeClass('current');
				$(this).addClass('current');
				
			}
		);
		
		$('a#nextImage').click(
			function($e){
				$e.preventDefault();
				if(imageCounter==theCaptionsNum){
					imageCounter = 1;
				}else{
					imageCounter ++;
				}
				var theImageFile=imageInfo(theProductId)+ '_' + imageCounter;
				$('div#more-images_caption').text(theCaptionsArray[imageCounter-1]);
				$('div#slideShowImage img').attr('src','images/' + theImageFile + '.jpg').hide().fadeIn(1000);
				$('div#more-images_thumbnails a img').add('div#more-images_thumbnails_2 a img').removeClass('current').filter(
					function(){
						return $(this).attr('src').split('images/')[1].split('_ss')[0]==theImageFile;
					}
				).addClass('current');
				$(this).blur();
			}
		);
		$('a#previousImage').click(
			function($e){
				$e.preventDefault();
				if(imageCounter==1){
					imageCounter = theCaptionsNum;
				}else{
					imageCounter --;
				}
				var theImageFile=imageInfo(theProductId)+ '_' + imageCounter;
				$('div#more-images_caption').text(theCaptionsArray[imageCounter-1]);
				$('div#slideShowImage img').attr('src','images/' + theImageFile + '.jpg').hide().fadeIn(1000);
				$('div#more-images_thumbnails a img').add('div#more-images_thumbnails_2 a img').removeClass('current').filter(
					function(){
						return $(this).attr('src').split('images/')[1].split('_ss')[0]==theImageFile;
					}
				).addClass('current');
				$(this).blur();
			
			}
		);
		
		$('a#more-images_close').click(
			function($e){
				$e.preventDefault();
				$('div#more-images_frame').fadeOut(500, function(){$(this).remove();});
				$('div#overlay').fadeOut(500,function(){$(this).remove();});
			}
		);
		
	});
	addRecentlyViewedItem(theProductId)
	return false;		
}

function moreWindow(){
	var winName = this.id + "Win";
	var openFile = this.id; 
	var PDF = (this.id.split(".")[1]=="pdf")?true:false;
	var webLink = (this.id.indexOf('http')>-1)?true:false;
    if(PDF){
		var newWindow = window.open(openFile,winName,"width=800,height=600,toolbar=yes,resizable=yes");
    }else if (webLink) {
		var newWindow = window.open(openFile,winName,"width=800,height=600,toolbar=yes,resizable=yes");
 	}else {
		var newWindow = window.open(openFile, winName, "width=200,height=200,toolbar=no,resizable=no");
	}
	newWindow.focus();
	theProductId = this.parentNode.parentNode.id.split("=")[1];
   if(this.className!="pricelist_link"){
	addRecentlyViewedItem(theProductId);
   }
	return false;	


}

function newWindow(){
	if(this.id.indexOf("=")>-1){
		var thisImageInfo = imageInfo(this.id.split("=")[1]);
	}
	else{
		var thisImageInfo = this.id;
	}
	var winName = thisImageInfo + "Win";
	
	var newWindow = window.open("popup.htm?"+thisImageInfo,winName,"width=200,height=200,toolbar=no,resizable=no");
	newWindow.focus();

	theProductId = (this.id.indexOf("image=")>-1)?this.id.split("=")[1]:this.parentNode.parentNode.id.split("=")[1];
	addRecentlyViewedItem(theProductId)
	return false;	
}

function printWindow(){
	var thisImageInfo = imageInfo(this.id);
	var winName = this.id + "Win";
	var newWindow = window.open("print.html?"+this.id+"="+thisImageInfo,winName,"toolbar=yes,menubar=yes,scrollbars=auto,resizable=yes,width=840,height=638");
	
	return false;

}

function imageInfo(thisProductId){
	for(var i=0; i<productInfo.length; i++){
		var thisInfoId = productInfo[i].split("_")[0];
		var thisInfoTitle = productInfo[i].split("_")[1].split("^=")[0];
		var thisInfoDetail = productInfo[i].split("^=")[1];
		if(thisInfoId == thisProductId){
				if(thisInfoTitle == "image"){
					return thisInfoDetail;
				}
		}
	}

}
// End of New Window


// Start of Show Print Page
function showPrintPage(thisProduct){
	document.getElementById("product_info").innerHTML = productInfo[0];


	var thisAllInfo = "<ul>";
	for(var i=0; i<productInfo.length; i++){
		var thisInfoId = productInfo[i].split("_")[0];
		var thisInfoTitle = productInfo[i].split("_")[1].split("^=")[0];
		var thisInfoDetail = productInfo[i].split("^=")[1];
		
		if(thisInfoId == thisProduct){
				if(thisInfoTitle == "image"){
					var thisImageInfo = thisInfoDetail;
				}
			if(thisInfoTitle == "Item"){
				var thisItem = thisInfoDetail;
			}
			if(thisInfoId && thisInfoTitle && thisInfoDetail && thisInfoTitle!="image"){
				switch(thisInfoTitle){
					case "List":
						thisAllInfo += "<li>" + thisInfoTitle + " Price: " + thisInfoDetail + "<\/li><br \/>";
						break;
					default:
						thisAllInfo += "<li>" + thisInfoTitle + ": " + thisInfoDetail + "<\/li><br \/>";
				}
			}
		}
		
	}
	thisAllInfo += "<\/ul>";
		

	
	
	document.getElementById("product_info").innerHTML = thisAllInfo;

	var productId = (arrTemp.length>0)?arrTemp[0].split("?")[1]:"";
	var itemName = productInfoVal(productId,"Item");
	itemName = (itemName.indexOf("<br")>-1)?itemName.split("<br")[0]:itemName;
	document.title = itemName;
	//document.title = thisItem;
	
	imageResize(document.images[0]);

	
	window.print();	

	addRecentlyViewedItem(productId);

}

function imageResize(thisImage){
	var maxW=500;
	var maxH=400;
	var theW=thisImage.width;
	var theH=thisImage.height;
	var iW;
	var iH;
	if(theW-maxW > 0){
		iW = maxW;
	}
	else{
		iW = theW;
	}
	if(theH*iW/theW - maxH > 0){
		iH = maxH;
		iW = theW*iH/theH;
	}
	else{
		iH = theH*iW/theW;
	}
	document.images[0].width = iW;
	document.images[0].height = iH;
}
// End of Show Print Page




/*
CITE
retail specialists commercial interiors
home furnishings and accessories
131 greene st. nyc,10012
tel.212.431.7272
fax.212.431.4470
toll-free.866.764.0888
www.citenyc.com
citehome@citenyc.com
*/

















