var BaynoteJSVersion="$Revision: 1.25 $";var BN_READY_SIGNAL="ReadySignal";if(typeof(baynote_globals)=="undefined")var baynote_globals=new Object();baynote_globals.waitForReady=false;function BNLog(){this.timeBase=new Date().getTime();this.lines=new Array();this.lastLine="";this.repCount=0;}
BNLog.prototype.log=function(str){if(str==this.lastLine){++this.repCount;return;}
if(this.repCount>0){this.lines.push("___ ABOVE REPEATED "+this.repCount+" TIME"+((this.repCount>1)?"S":""));}
this.lastLine=str;this.repCount=0;var elapsed=new Date().getTime()-this.timeBase
this.lines.push(elapsed+": "+str);}
BNLog.prototype.toString=function(){if(this.repCount>0){this.lines.push("___ ABOVE REPEATED "+this.repCount+" TIME"
+((this.repCount>1)?"S":""));this.lastLine="";this.repCount=0;}
return this.lines.join("\n");}
if(typeof(bnLog)=="undefined"){var bnLog=new BNLog();}
function BNCriticalSectionQueue(){this.waitList=new Object();this.lastId=0;}
BNCriticalSectionQueue.prototype.issueId=function(){return++this.lastId;}
BNCriticalSectionQueue.prototype.enqueue=function(id,item){this.waitList[id]=item;}
BNCriticalSectionQueue.prototype.getWaiter=function(id){return(id==null)?null:this.waitList[id];}
BNCriticalSectionQueue.prototype.firstWaiter=function(){return this.getWaiter(this.nextWaiterKeyAfter(null));}
BNCriticalSectionQueue.prototype.nextWaiterAfter=function(id){return this.getWaiter(this.nextWaiterKeyAfter(id));}
BNCriticalSectionQueue.prototype.nextWaiterKeyAfter=function(id){for(var currKey in this.waitList){if(typeof(this.waitList[currKey])!="object")continue;if(id==null)return currKey;if(id==currKey)id=null;}
return null;}
BNCriticalSectionQueue.prototype.nextPredecessor=function(target,start){for(var currWaiter=start;currWaiter!=null;currWaiter=this.nextWaiterAfter(currWaiter.id)){if(currWaiter.enter||(currWaiter.number!=0&&(currWaiter.number<target.number||(currWaiter.number==target.number&&currWaiter.id<target.id)))){return currWaiter;}}
return null;}
function BNCriticalSection(csQueue){this.csQueue=csQueue;this.debug=1;}
BNCriticalSection.prototype.enter=function(enterFunc){this.enterFunc=enterFunc;this.id=this.csQueue.issueId();this.csQueue.enqueue(this.id,this);this.enter=true;this.number=(new Date()).getTime();this.enter=false;this.attempt(this.csQueue.firstWaiter());}
BNCriticalSection.prototype.leave=function(){if(this.debug)bnLog.log("LEAVE "+this.id);this.number=0;}
BNCriticalSection.prototype.attempt=function(start){var nextReady=this.csQueue.nextPredecessor(this,start);if(nextReady!=null){if(this.debug)bnLog.log("WAIT "+this.id);var me=this;return setTimeout(function(){me.attempt(nextReady);},50);}
if(this.debug)bnLog.log("ENTER "+this.id);this.enterFunc();}
function BNResourceManager(){this.csQueue=new BNCriticalSectionQueue();this.critSec=null;this.debug=1;this.resources=new Object();this.waiting=new Object();}
BNResourceManager.prototype.getResource=function(rId){return this.resources[rId];}
BNResourceManager.prototype.loadResource=function(rId,rAddress,rType){if(typeof(this.resources[rId])!="undefined")return;this.resources[rId]=null;var critSec=new BNCriticalSection(this.csQueue);critSec.enter(function(){bnResourceManager.inject(rId,rAddress,rType,critSec);});}
BNResourceManager.prototype.inject=function(rId,rAddress,rType,critSec){this.critSec=critSec;if(this.debug)bnLog.log("INJECT "+this.critSec.id+" ("+rId+")");if(!rType||rType=="script"){var scriptTag1=document.createElement("script");scriptTag1.language="javascript";scriptTag1.src=rAddress;var head=document.getElementsByTagName("head");head[0].appendChild(scriptTag1);}
else if(rType=="img"){var img=document.createElement("IMG");var handler=function(){bnResourceManager.registerAndAddResource(rId,img);};if(img.addEventListener)img.addEventListener("load",handler,false);else if(img.attachEvent)img.attachEvent("onload",handler);else img["onload"]=handler;img.src=rAddress;}
else alert("Unexpected resource type to loadResource: "+rType);}
BNResourceManager.prototype.waitForResource=function(rId,callbackCode,rAddress,rType){with(this){if(getResource(rId)){this.runCallback(callbackCode);}
else{if(typeof(waiting[rId])=="undefined")waiting[rId]=new Array();var waitingList=waiting[rId];waitingList[waitingList.length]=callbackCode;if(rAddress)this.loadResource(rId,rAddress,rType);}}}
BNResourceManager.prototype.wakeUpWaiting=function(rId){with(this){var waitingList=waiting[rId];if(!waitingList)return;for(var i=0;i<waitingList.length;i++){if(waitingList[i]){var codeToEval=waitingList[i];waitingList[i]=null;if(this.debug&&codeToEval)bnLog.log("CALLBACK "+rId+": "+codeToEval);this.runCallback(codeToEval);}}}}
BNResourceManager.prototype.registerAndAddResource=function(rId,resource){if(this.debug)bnLog.log("REGISTER "+(this.critSec?this.critSec.id:"")+" ("+rId+")");this.resources[rId]=resource;this.wakeUpWaiting(rId);this.critSec.leave();setTimeout("bnResourceManager.wakeUpWaiting('"+rId+"')",5000);}
BNResourceManager.prototype.registerResource=function(rId){this.registerAndAddResource(rId,true);}
BNResourceManager.prototype.runCallback=function(callback){if(typeof(callback)=="string")eval(callback);else if(typeof(callback)=="function")callback();else alert("Invalid callback, type="+typeof(callback));}
if(typeof(bnResourceManager)=="undefined"){var bnResourceManager=new BNResourceManager();}
function BNSystem(){this.testServer=null;}
BNSystem.prototype.getCookieValue=function(cookieName,cookieSubDomain){if(!cookieSubDomain)cookieSubDomain=baynote_globals.cookieSubDomain;if(cookieSubDomain)cookieName+=("-"+cookieSubDomain);var sRE="(?:; )?"+cookieName+"=([^;]*);?";var oRE=new RegExp(sRE);if(oRE.test(document.cookie)){return decodeURIComponent(RegExp["$1"]);}else{return null;}}
BNSystem.prototype.setCookie=function(cookieName,cookieValue,cookiePath,cookieExpires,cookieDomain,cookieSubDomain){cookieValue=encodeURIComponent(cookieValue);if(cookieExpires=="NEVER"){var nowDate=new Date();nowDate.setFullYear(nowDate.getFullYear()+500);cookieExpires=nowDate.toGMTString();}
else if(cookieExpires=="SESSION")cookieExpires="";if(cookiePath!="")cookiePath=";Path="+cookiePath;if(cookieExpires!="")cookieExpires=";expires="+cookieExpires;if(!cookieDomain)cookieDomain=(baynote_globals.cookieDomain)?baynote_globals.cookieDomain:"";if(cookieDomain!="")cookieDomain=";domain="+cookieDomain;if(!cookieSubDomain)cookieSubDomain=baynote_globals.cookieSubDomain;if(cookieSubDomain)cookieName+=("-"+cookieSubDomain);var cookieStr=cookieName+"="+cookieValue+cookieExpires+cookiePath+cookieDomain;if(cookieStr.length>4096)return false;document.cookie=cookieStr;return true;}
BNSystem.prototype.removeCookie=function(cookieName,cookieDomain){this.setCookie(cookieName,"","/","Mon, 1 Jan 1990 00:00:00",cookieDomain);}
BNSystem.prototype.getURLParam=function(name,url){if(!url)var url=window.location.href;var regex=new RegExp("[\\?&]"+name+"=([^&#]*)");var match=regex.exec(url);if(!match)return null;else return match[1];}
BNSystem.prototype.getTestServer=function(){if(this.testServer!=null)return this.testServer;var testServer=this.getURLParam("bn_test");if(testServer)this.setCookie("bn_test",testServer,"/","SESSION");else if(testServer=="")this.removeCookie("bn_test");else{testServer=this.getCookieValue("bn_test");if(!testServer)testServer="";}
this.testServer=testServer;return testServer;}
if(typeof(bnSystem)=="undefined"){var bnSystem=new BNSystem();}
if(typeof(BNTag)=="undefined"){function BNTag(previousTag){if(previousTag){this.id=previousTag.id+1;this.server=previousTag.server;this.customerId=previousTag.customerId;this.code=previousTag.code;}
else this.id=0;this.attrs=new Object();this.docAttrs=new Object();this.css=new Object();}}
BNTag.prototype.getCommonResourceId=function(){return"Common";}
BNTag.prototype.getCommonResourceAddress=function(tag){return(this.server+"/baynote/tags2/common.js");}
BNTag.prototype.getFailsafeResourceId=function(){return"Failsafe";}
BNTag.prototype.getFailsafeResourceAddress=function(){var v=BaynoteJSVersion.split(" ")[1];var u=bnSystem.getCookieValue("bn_u");return(this.server+"/baynote/customerstatus2?customerId="+this.customerId+"&code="+this.code+"&x="+this.id+(new Date().getTime())+"&v="+v+"&u="+u);}
BNTag.prototype.show=function(parentElemId){if(this.id==0)document.write("<span id='bn_placeholder_global'></span>");this.placeHolderId="bn_placeholder"+this.id;var placeHolderType;if(this.placeHolderElement)placeHolderType=this.placeHolderElement;else placeHolderType=this.popup?"span":"div";if(parentElemId){var placeHolder=document.createElement(placeHolderType);placeHolder.id=this.placeholderId;document.getElementById(parentElemId).appendChild(placeHolder);}
else document.write("<"+placeHolderType+" id='"+this.placeHolderId+"'></"+placeHolderType+">");window["bn_tags"][this.id]=this;var testServer=bnSystem.getTestServer();if(testServer){var reValidTestServer=new RegExp("^https?://[^/]*\.baynote\.(com|net)(:\d+)?(/.*)?");if(reValidTestServer.test(testServer))this.server=testServer;else alert("Ignoring invalid test server \""+testServer+"\"");}
this.showWhenReady(this);baynote_tag=new BNTag(this);}
BNTag.prototype.showWhenReady=function(tag){if(baynote_globals.waitForReady&&!bnResourceManager.getResource(BN_READY_SIGNAL)){bnResourceManager.waitForResource(BN_READY_SIGNAL,function(){tag.showWhenReady(tag);});return;}
var failsafeId=this.getFailsafeResourceId();if(!bnResourceManager.getResource(failsafeId)){bnResourceManager.waitForResource(failsafeId,function(){tag.showWhenReady(tag);},this.getFailsafeResourceAddress(),"img");return;}
var commonId=this.getCommonResourceId();if(!bnResourceManager.getResource(commonId)){bnResourceManager.waitForResource(commonId,function(){tag.showWhenReady(tag);},this.getCommonResourceAddress(),"script");return;}
bnTagManager.show(tag.id);}
BNTag.prototype.noshow=function(){window["bn_tags"][this.id]=this;baynote_tag=new BNTag(this);}
BNTag.prototype.getParam=function(name,defaultValue){var value=this[name];if(typeof(value)=="undefined"||value==null)return defaultValue;else return value;}
if(typeof(baynote_tag)=="undefined"){window["bn_tags"]=new Array();var baynote_tag=new BNTag(null);}
function bnReadySignal(){bnResourceManager.registerResource(BN_READY_SIGNAL);}
function bnCall(resName,methodName,methodArg){var resource=bnResourceManager.getResource(resName);if(!resource){bnResourceManager.waitForResource(resName,function(){bnCall(resName,methodName,methodArg);});return;}
if(typeof(resource)!="object"){return;}
var method=resource[methodName];if(typeof(method)!="function"){return;}
method.call(resource,methodArg);}

// begin baynote-guide.js 
/*
 * Baynote Recommendations for houseofantiquehardware.com
 * Last updated: Dec 8, 2008
 */
 function bn_isNotEmpty(name) {
	return (name != null) && (name != "");
}
 
function bn_getUrlParam(name) {
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp(regexS,"i");
	var tmpURL = window.location.href;
	var results = regex.exec(tmpURL);
	if(results == null)
		return "";
	else
		return unescape(results[1]);
}
function bn_getPageUrl() {
	var pageUrl = baynote_tag.url; 
	if ((typeof(pageUrl) == "undefined") || (pageUrl == null) || (pageUrl == ""))
	  pageUrl = window.location.href;
	return pageUrl;
}
function bn_getSearchTerm() {
  var searchTerm = bn_getUrlParam("search");  
  return unescape(searchTerm);
}

function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	//strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}

function baynote_waitForGuide(bn_wait_count) {
    var bn_results = getElementsByClassName(document, "a", "bn_g_result_link");
    if(bn_isNotEmpty(bn_results)){
         
         for(var j=0; j <bn_results.length; j++){
        	 var str = bn_results[j].firstChild.nodeValue;
        	 if(str.length > 30){
        		 var spaceIndex =str.indexOf(" ", 25);
        		 if(spaceIndex > -1){
        			 str=str.substring(0, spaceIndex) + "...";
        		 }else if(str.indexOf(" ", 20) > -1){
        			 spaceIndex=str.indexOf(" ", 20);
        			 str=str.substring(0, spaceIndex) + "...";
        		 }
        	 }
        	 bn_results[j].firstChild.nodeValue = str;
         }
	}
    else if(bn_wait_count < 10){
          bn_wait_count++;
          setTimeout("baynote_waitForGuide("+bn_wait_count+")", 200);
     }
}

function baynote_showGuide(guideType, listSize) {
	bn_customerId = "hoah"; /* 1. set customer id */
	bn_code = "www"; /* 2. set customer code */
	var bn_locHref = window.location.href;
	if (bn_locHref.indexOf("https://") == 0) {
		baynote_tag.server = "https://" + bn_customerId + "-" + bn_code + ".baynote.net";
	} else {
		baynote_tag.server = "http://" + bn_customerId + "-" + bn_code + ".baynote.net";
	}
	baynote_tag.customerId="hoah";
	baynote_tag.code="www";
	baynote_tag.type="guide";				
	baynote_tag.guide= guideType;
	if(bn_isNotEmpty(listSize)){
		baynote_tag.listSize=listSize;
	}else{
		baynote_tag.listSize=6;
	}
	
	var query = bn_getSearchTerm();
	baynote_tag.query=query;
	baynote_tag.show();
	bnResourceManager.waitForResource("GLResults0", "baynote_waitForGuide(1)");
}

/* begin Collections Nav Helper JS code DN Nov 2009 */
function setNavHighlight() {
    //var CRUMB_ROOT_TEXT = 'Special Collections';
	var COLLECTION_ROOT_TEXT = 'special collections';
	var SBS_ROOT_TEXT = 'shop by style';
	var SBTTEXT = 'shop by type';
    var crumbs,collection,category,collections;
    crumbs = Array();
    try {
        //crumbs = jQuery('bcrumb').getElements('a.crumb'); // get all breadcrumbs
		crumbs = jQuery('#bcrumb').children('a.crumb'); // get all breadcrumbs
    } 
	catch(e) {
		if(jQuery('#testdiv').length > 0){
			jQuery('#testdiv').append(e.message);
		}
	}

	// check to see if the root breadcrumb is 'Shop by Type'
	if( crumbs.length > 0 && jQuery.trim(jQuery(crumbs).get(0).innerHTML.toLowerCase()) === SBTTEXT ) {
		try {
			jQuery('#sbt').addClass('openItem');
		} catch(e) {
			if(jQuery('#testdiv').length > 0){
				jQuery('#testdiv').append(e.message);
			}			
		}
	}
    // check to see if the root breadcrumb is 'Special Collections'
    if( jQuery(crumbs).length == 3 && jQuery.trim(jQuery(crumbs).get(0).innerHTML.toLowerCase()) === COLLECTION_ROOT_TEXT ) {
		try {
			collection = jQuery.trim(jQuery(crumbs).get(1).innerHTML.toLowerCase()); // Pull out collection name
			collection = collection.replace(/&amp;/, "&");
			category = jQuery.trim(jQuery(crumbs).get(2).innerHTML.toLowerCase()); // Pull out style category name
			category = category.replace(/&amp;/, "&");
			collections = jQuery('#collMenu').children('li');
			//switch on the master Special Collections list
			jQuery('#collMenu').css('display','block');
			//collapse the Shop by Type menu
			jQuery('#sbtM > li > ul').css('display','none');
		} catch(e) {
			if(jQuery('#testdiv').length > 0){
				jQuery('#testdiv').append(e.message);
			}
        }
        // loop through collections menu and try to find a match
        if(collections) {
			if(jQuery('#testdiv').length > 0){
				jQuery('#testdiv').append(category);
			}
			try {
				jQuery('#collMenu').addClass('openItem');
				jQuery.each(collections,function(item,index){
					var thisCollection = jQuery(this).find('a:first');
					thisCollectionText = jQuery.trim(jQuery(thisCollection).text().toLowerCase());
					if(thisCollectionText === collection) {
						thisCollection.addClass('openItem');
						catmenu = jQuery(this).children('ul').children('li');
						thislist = jQuery(this).children('ul');
						jQuery(thislist).css('display','block');
						jQuery.each(catmenu,function(item,index){
							jQuery(this).css('display','list-item');
							thisCat = jQuery(this).find('a:first');
							thisCatText = jQuery.trim(jQuery(thisCat).text().toLowerCase());
							if(thisCatText === category){
								//thisCat.addClass('openItem');
								thisCat.addClass('activeNavItem');
								//switch off any "open" arrows in the Shop by Type menu to avoid confusion
								jQuery('#sbtM > li > a').addClass('inactiveNavItem');
								thisList = jQuery(this).parent('ul');
								jQuery(thisList).css('display','block');
								//jQuery(thisList).children('li').css('display','list-item');
							}
						});
                    }   
                }); 
            } 
			catch(e) {
				if(jQuery('#testdiv').length > 0){
					jQuery('#testdiv').append(e.message);
				}
            }
        }           
    }	
    // check to see if the root breadcrumb is 'Shop by Style'
    if( jQuery(crumbs).length == 4 && jQuery.trim(jQuery(crumbs).get(0).innerHTML.toLowerCase()) === SBS_ROOT_TEXT ) {
		try {
			style = jQuery.trim(jQuery(crumbs).get(1).innerHTML.toLowerCase()); // Pull out collection name
			style = style.replace(/&amp;/, "&");
			category = jQuery.trim(jQuery(crumbs).get(2).innerHTML.toLowerCase()); // Pull out style category name
			category = category.replace(/&amp;/, "&");
			subcategory = jQuery.trim(jQuery(crumbs).get(3).innerHTML.toLowerCase()); // Pull out style subcategory name
			subcategory = subcategory.replace(/&amp;/, "&");
			stylemenu = jQuery('#sbsM').children('li');
			//switch on the master SBS list
			jQuery('#sbsM').css('display','block');
		} catch(e) {
			if(jQuery('#testdiv').length > 0){
				jQuery('#testdiv').append(e.message);
			}
        }
        // loop through style menu and try to find a match
        if(stylemenu) {
			try {
				jQuery('#sbs').addClass('openItem');
				jQuery.each(stylemenu,function(item,index){
					var thisStyle = jQuery(this).find('a:first');
					thisStyleText = jQuery.trim(jQuery(thisStyle).text().toLowerCase());
					if(thisStyleText === style) {
						if(jQuery('#testdiv').length > 0){
							jQuery('#testdiv').append(style);
						}						
						thisStyle.addClass('openItem');
						catmenu = jQuery(this).children('ul').children('li');
						jQuery.each(catmenu,function(item,index){
							jQuery(this).css('display','block');
							thisCat = jQuery(this).find('a:first');
							thisCatText = jQuery.trim(jQuery(thisCat).text().toLowerCase());
							if(thisCatText === category){
								thisCat.addClass('openItem');
								thisList = jQuery(this).parent('ul');
								jQuery(thisList).css('display','block');
								jQuery(thisList).children('li').css('display','list-item');
								subcatmenu = jQuery(this).children('ul').children('li');
								jQuery.each(subcatmenu,function(item,index){
									thisSubcat = jQuery(this).find('a:first');
									thisSubcatText = jQuery.trim(jQuery(thisSubcat).text().toLowerCase());
									if(thisSubcatText === subcategory){
										thisList = jQuery(this).parent('ul');
										jQuery(thisList).css('display','block');
										jQuery(thisList).children('li').css('display','list-item');
										//thisSubcat.addClass('openItem');
										thisSubcat.addClass('activeNavItem');
										//switch off any "open" arrows in the Shop by Type menu to avoid confusion
										jQuery('ul#sbtM > li > a').addClass('inactiveNavItem');										
									}
								});
							}
						});
                    }   
                }); 
            } 
			catch(e) {
				if(jQuery('#testdiv').length > 0){
					jQuery('#testdiv').append(e.message);
				}
            }
        }           
    }	
}

//activate nav highlighting on document ready
jQuery(document).ready(function() {
	setNavHighlight();
});
/* end collectionsnavhelper */

function trackBN () { // set GA variable
	_gaq.push(['_setCustomVar',5,'Product Finding Method','Baynote',1]);	
	return true;
}
