var searchSection = 'global';
var searchCountry = 'us';
var geoMap={US:{code:"",noResults:"No Shortcut found. Try a full search of wenatcheeworld.com.",viewAll:"View all search results",searchText:"Search News"}};
var enhanceSearch=function(B){
	document.getElementById("g-search").setAttribute("action",B);
	document.getElementById("g-search").setAttribute("method","GET");
};
var loadsub=function(){
   		var $div = $('#cmty_menu');
//		var height = $div.height();
		var height = 25;
		var visible = $div.is(":visible");
		
		$div.hide().css({ height : 0 });
	
		$('#ww-communities a').click(function () {
			if ($div.is(':visible')) {
				$div.animate({ height: 0 }, { duration: 250, complete: function () {
					$div.hide();
				} });
			} else {
				$div2.hide();
				$div.show().animate({ height : height }, { duration: 250 });
			}
			
			return false;
		});
		var $div2 = $('#class_menu');
		var height2 = $div2.height();
		var visible2 = $div2.is(":visible");
		
		$div2.hide().css({ height : 0 });
	
		$('#ww-classifieds a').click(function () {
			if ($div2.is(':visible')) {
				$div2.animate({ height: 0 }, { duration: 250, complete: function () {
					$div2.hide();
				} });
			} else {
				$div.hide();
				$div2.show().animate({ height : height2 }, { duration: 250 });
			}
			
			return false;
		});
	};

function loadShortcuts(){
	decorateGlobalSearchInput();
	if(typeof (searchCountry)=="undefined"){
		searchCountry="us"
	}
	if(geoMap[searchCountry.toUpperCase()].directory){
		var D=geoMap[searchCountry.toUpperCase()].directory
	}else{
		if(searchCountry!="us"){
			var D="/"+searchCountry.replace(/_/,"")
		}else{
			D=""
		}
	}
	var C={"global":"/apps/pbcs.dll/search?"};
	var B=C[searchSection]||"/apps/pbcs.dll/search?";
	enhanceSearch(B);
	var A=navigator.userAgent.match(/AppleWebKit/i)&&navigator.userAgent.match(/Mobile/i);
	if(!A&&(typeof (deactivateSearchShortcuts)=="undefined"||!deactivateSearchShortcuts)){
		SearchShortcut.load()
	}
};
function shortcutsPageLoader(B){
	var A=window.onload;
	if(typeof window.onload!="function"){
		window.onload=B
	}else{
		window.onload=function(){
			A();
			B()
		}
	}
};
shortcutsPageLoader(loadShortcuts);
var SearchShortcut={minimumCharactersForSearch:0,init:function(){
	this.fullSearchUrl=document.getElementById("globalsearch").getElementsByTagName("form")[0].getAttribute("action");
	this.noResults=geoMap["US"].noResults;
	this.viewAll=geoMap["US"].viewAll;
	if(typeof (searchCountry)!="undefined"&&searchCountry){
		this.noResults=geoMap[searchCountry.toUpperCase()].noResults||this.noResults;this.viewAll=geoMap[searchCountry.toUpperCase()].viewAll||this.viewAll
	}
	this.html={results:document.getElementById("sp-results").getElementsByTagName("div")[0],input:document.getElementById("sp-searchtext")};
	if(navigator.userAgent.toLowerCase().indexOf("msie 6.")!=-1){
		document.getElementById("sp-results").style.left="171px";
		this.isIe=true
	}
	this.pausedControllers=[]
},go:function(A){
	SearchShortcut.track(SearchShortcut.searchText,A);document.location=A
},search:function(C){
	var A=this.baseUrl+"?q="+encodeURIComponent(C);
	if(typeof (searchSection)!="undefined"&&searchSection){
		A+="&section="+searchSection
	}
	if(typeof (searchCountry)!="undefined"&&searchCountry){
		A+="&geo="+searchCountry.toLowerCase()
	}
	this.spin();
	A+="&transport=js";
	var B=document.getElementsByTagName("head")[0];
	script=document.createElement("script");
	script.id="xdShortcutContainer";
	script.type="text/javascript";
	script.src=A;
	B.appendChild(script);
	SearchShortcut.scriptLoadTest()
},flashDomRender:function(){
		SearchShortcut.border%2==0?SearchShortcut.border++:SearchShortcut.border--;
		var A=document.getElementById("sp-results").firstChild.firstChild;
		if(A){
			A.style.border=SearchShortcut.border+"px none red"
		}
	},itemSelected:false,renderResults:function(){
		this.html.results.innerHTML="";
		var J=document.createElement("ul");
		J.className="sp-results";
		var L={};
		for(var H=0;H<this.results.length;H++){
			var Q=this.results[H];
			var P=unescape(Q.desc);
			var E="";
			if(P.length>this.descriptionCharacters){
				P=P.substring(0,P.lastIndexOf(" ",this.descriptionCharacters-11))+"&hellip;";
				E=unescape(Q.desc)
			}
			var D=unescape(Q.title);
			if(D.length>this.titleCharacters){
				D=D.substring(0,D.lastIndexOf(" ",30))+"&hellip;"
			}
			var G=document.createElement("li");
			G.id="sp-result-"+H;
			G.className="category-"+unescape(Q.category).toLowerCase().replace(/\s+/g,"-");
			var C=document.createElement("div");
			C.className="hoverbox";
			var F=document.createElement("img");
			F.src=Q.image;
			F.title=E;
			var O=document.createElement("span");
			O.className="text";
			var I=document.createElement("h4");
			var N=document.createElement("a");
			var B=document.createElement("p");
			N.href=decodeURIComponent(Q.url);
			N.title=E;
			N.onclick=function(){
				SearchShortcut.go(decodeURIComponent(Q.url))
			};
			N.innerHTML=D;
			B.innerHTML=P;
			B.title=E;
			I.appendChild(N);
			O.appendChild(I);
			O.appendChild(B);
			G.appendChild(C);
			G.appendChild(F);
			G.appendChild(O);
			G.url=Q.url;
			G.num=H;
			G.onmouseover=function(){
				SearchShortcut.itemSelected=true;
				SearchShortcut.highlight(this)
			};
			G.onmouseup=function(){
				SearchShortcut.itemSelected=true;
				SearchShortcut.go(this.url)
			};
			G.onmouseout=function(){
				SearchShortcut.itemSelected=false;
				SearchShortcut.unhighlight(this)
			};
			G.priority=parseInt(Q.priority);
			if(!L[Q.category]){
				L[Q.category]=new Array()
			}
			L[Q.category].push(G)
		}
		var K="firstCat resultCat";
		for(var M in L){
			if(!L.hasOwnProperty(M)){continue}
			G=document.createElement("li");
			G.className=K;
			G.innerHTML=unescape(M);
			K="resultCat";
			J.appendChild(G);
			for(var A=0;A<L[M].length;A++){
				J.appendChild(L[M][A])
			}
		}
		G=document.createElement("li");
		G.id="sp-result-"+this.results.length;
		G.className="viewall";
		var C=document.createElement("div");
		C.className="hoverbox";
		var N=document.createElement("a");
		N.href=this.fullSearchUrl+"?q="+encodeURIComponent(this.term);
		N.innerHTML=this.viewAll;
		G.appendChild(C);
		G.appendChild(N);
		G.url=this.fullSearchUrl+"?q="+encodeURIComponent(this.term);
		G.num=this.results.length;
		G.onclick=function(){
			SearchShortcut.go(this.url)
		};
		G.onmouseover=function(){
			SearchShortcut.itemSelected=true
		};
		G.onmouseout=function(){
			SearchShortcut.itemSelected=false
		};
		document.getElementById("globalsearch").className="active";
		J.appendChild(G);
		this.html.results.appendChild(J);
		if(typeof (flashOnPage)!="undefined"&&flashOnPage){
			this.flashDomFix();
			this.startFlashFixTimer()
		}
	},startKeystrokeTimer:function(){
		if(this.timeoutId){
			window.clearTimeout(this.timeoutId)
		}
		this.timeoutId=window.setTimeout("SearchShortcut.commitKeystroke()",this.entryDelay)
	},commitKeystroke:function(){
		this.search(this.searchText)
	},hideResults:function(A,B){
		if(!this.html){
			this.init()
		}
		this.selected=null;
		document.getElementById("globalsearch").className="";
		this.html.results.innerHTML="";
	},highlight:function(A){
		A.className="hoverli"
	},keyHighlight:function(A){
		if(this.selected){
			this.selected.className=""
		}
		this.selected=A;
		A.className="hoverli"
	},unhighlight:function(A){
		A.className=""
	},load:function(){
		var A=document.createElement("img");
		if(location.protocol.match(/https/)){
			A.src="http://wenatcheeworld.com/images/spinner.gif"
		}else{
			A.src="http://wenatcheeworld.com/images/spinner.gif"
		}
		A.width="11";
		A.height="11";
		A.border="0";
		A.alt="*";
		A.id="sp-search-spinner";
		A.style.display="none";
		document.getElementById("globalsearch").appendChild(A);
		document.getElementById("g-search").onsubmit=function(B){return false};
		if(navigator.userAgent.match(/AppleWebKit/i)){
			document.getElementById("sp-searchtext").onkeydown=function(B){
				var C=typeof (event)!="undefined"?event["keyCode"]:B.keyCode;
				if(!B){B=event}
				if(C==13&&!B.altKey){
					if(B.target.value.length===0){return false}
					if(SearchShortcut.selected){
						SearchShortcut.go(SearchShortcut.selected.url)
					}else{
						SearchShortcut.hideResults();
						document.getElementById("g-search").submit()
					}
				}
			}
		}
		document.getElementById("sp-searchtext").onkeyup=function(B){
			var D=typeof (event)!="undefined"?event["keyCode"]:B.keyCode;
			if(!B){B=event}
			if(D==40&&SearchShortcut.results){
				try{
					B.preventDefault();
					B.stopPropagation()
				}
				catch(E){}
				if(SearchShortcut.selected&&(SearchShortcut.results.length>SearchShortcut.selected.num+1)){
					SearchShortcut.keyHighlight(document.getElementById("sp-result-"+(SearchShortcut.selected.num+1)))
				}
				if(!SearchShortcut.selected&&SearchShortcut.results.length>0){
					SearchShortcut.keyHighlight(document.getElementById("sp-result-0"))
				}
				SearchShortcut.flashDomRender()
			}else{
				if(D==38&&SearchShortcut.results){
					try{
						B.preventDefault();
						B.stopPropagation()
					}
					catch(E){}
					if(SearchShortcut.selected&&SearchShortcut.selected.num>0){
						SearchShortcut.keyHighlight(document.getElementById("sp-result-"+(SearchShortcut.selected.num-1)))
					}
					SearchShortcut.flashDomRender()
				}else{
					if(D==27){
						SearchShortcut.hideResults();
						document.getElementById("sp-searchtext").value=""
					}else{
						SearchShortcut.selected=false;
						var C=document.getElementById("sp-searchtext").value;
						C=C.replace(/[%\^\?\!\*\/<>\$]/ig,"");
						C=C.replace(/^\s+/g,"").replace(/\s+$/g,"");
						if(C.length<1&&SearchShortcut.html){
							SearchShortcut.html.results.innerHTML="";
							document.getElementById("sp-search-spinner").style.display="none";
							SearchShortcut.hideResults()
						}else{
							if(C.length>SearchShortcut.minimumCharactersForSearch){
								SearchShortcut.searchText=C;
								SearchShortcut.startKeystrokeTimer()
							}
						}
					}
				}
			}
		}
	}
};
function decorateGlobalSearchInput(){
	var L=document.getElementById("sp-searchtext");
	var E=null;
	var D=0;
	var I="Search";
	if(typeof (searchCountry)=="undefined"){
		searchCountry="us"
	}
	if(geoMap[searchCountry.toUpperCase()].searchText){
		I=geoMap[searchCountry.toUpperCase()].searchText
	}
	var H="";
	if(navigator.userAgent.match(/AppleWebKit/i)){
		if(navigator.userAgent.match(/win/i)){
			L.className+=" not-round"
		}
		L.setAttribute("type","search");
		if(!L.getAttribute("results")){
			L.setAttribute("results",D)
		}
		if(null!=I){
			L.setAttribute("placeholder",I);
			L.setAttribute("autosave",H)
		}
		L.onblur=function(){
			if(!SearchShortcut.itemSelected){
				SearchShortcut.hideResults()
			}
		}
	}else{
		L.setAttribute("autocomplete","off");
		E=document.createElement("input");
		L.parentNode.replaceChild(E,L);
		var B=document.createElement("span");
		B.className="left";
		var J=document.createElement("span");
		J.className="right";
		var G=document.createElement("div");
		G.className="reset";
		var A=document.createElement("div");
		A.className="search-wrapper";
		var F=L.value==I;
		var C=L.value.length==0;
		if(F||C){
			L.value=I;
			A.className+=" blurred empty"
		}
		A.appendChild(B);
		A.appendChild(L);
		A.appendChild(J);
		A.appendChild(G);
		L.onfocus=function(){
			var M=A.className.indexOf("blurred")>-1;
			if(L.value==I&&M){L.value=""}
			A.className=A.className.replace("blurred","")
		};
		L.onblur=function(){
			if(!SearchShortcut.itemSelected){SearchShortcut.hideResults()}
			if(L.value==""){A.className+=" empty";L.value=I}
			A.className+=" blurred"
		};
		L.onkeydown=function(M){
			var O=typeof (event)!="undefined"?event["keyCode"]:M.keyCode;
			if(!M){M=event}
			if(O==13&&!M.altKey){
				var N=null;
				if(M.target){
					N=M.target
				}else{
					if(M.srcElement){N=M.srcElement}
				}
				if(N.value.length===0){return false}
				if(SearchShortcut.selected){SearchShortcut.go(SearchShortcut.selected.url)
				}else{
					SearchShortcut.hideResults();
					document.getElementById("g-search").submit()
				}
				return 
			}
			if(L.value.length>=0){
				A.className=A.className.replace("empty","")
			}
			K()
		};
		var K=function(){
			return(function(M){
				var N=false;
				if(!M){M=window.event}
				if(M.type=="keydown"){
					if(M.keyCode!=27){return 
					}else{
						N=true
					}
				}
				L.blur();
				L.value="";
				A.className+=" empty";
				L.focus()
			})
		};
		G.onmousedown=K();
		if(E){
			E.parentNode.replaceChild(A,E)
		}
	}
}