var geoMap=
{
	US:{code:"cn",noResults:"No Shortcut found. Try a full search of sterops.com.",viewAll:"View all search results",searchText:"??"},		
	AU:{code:"au"},
	NZ:{code:"nz"},
	CA_EN:{code:"ca",directory:"/ca"},
	CA_FR:{code:"ca",directory:"/ca/fr",viewAll:"Afficher tous les résultats",searchText:"Recherche"},
	DE:{code:"de",viewAll:"Alle Suchergebnisse"},
	UK:{code:"uk"},
	FR:{code:"fr",viewAll:"Afficher tous les résultats"},
	CH_DE:{code:"ce",viewAll:"Alle Suchergebnisse"},
	CH_FR:{code:"cr",viewAll:"Afficher tous les résultats"},
	IE:null,
	JP:{code:"jp",noResults:"??????????????????????????",viewAll:"???????????"},
	IT:{code:"it",viewAll:"Mostra tutti i risultati"},
	ES:{code:"es",viewAll:"Ver todos los resultados de búsqueda"},
	NL:{code:"nl",viewAll:"Toon alle zoekresultaten"},
	BE_FR:{code:"bf",viewAll:"Afficher tous les résultats"},
	BE_NL:{code:"bl",viewAll:"Toon alle zoekresultaten"},
	TW:null,LA:{code:"la"},
	KR:{code:"kr",noResults:"???? ????? ????. ?? ????.",viewAll:"?? ?? ?? ??."},
	SE:{code:"se",noResults:"Ingen genväg hittades. Prova att fulltextsöka på sterops.com.",viewAll:"Visa alla sökresultat"},
	DK:{code:"dk",noResults:"Ingen genvej fundet. Prøv at søge på hele sterops.com.",
	viewAll:"Vis alle søgeresultater"},
	FI:{code:"fi",noResults:"Ei oikotietä. Etsi koko sterops.com.",viewAll:"Katso hakutulokset"},
	NO:{code:"no",noResults:"Fant ingen snarvei. Søk på hele sterops.com.",viewAll:"Vis alle søkeresultater"},
	BR:{code:"br"},ZA:{code:"za"},
	CN:{code:"cn",noResults:"??????????????",viewAll:"??????",searchText:"??"},
	HK:null,
	RU:{code:"ru"},
	PT:null,
	PO:null,
	TR:null,
	UA:null,
	RO:null,
	CZ:null,
	HU:null,
	BG:null,
	HR:null,
	GR:null,
	IS:null
};
	
	var enhanceSearch=function(I)
	{
		var f=function(v)
		{
			var x=document.getElementById(v);
			x.parentNode.removeChild(x);
		};
		document.getElementById("g-search").setAttribute("action",I);
		document.getElementById("g-search").setAttribute("method","GET");
		f("search-oe");
		f("search-access");
		f("search-site");
		f("search-lr");
	};
	
	function loadShortcuts()
	{
		decorateGlobalSearchInput();
		if(typeof (searchCountry)=="undefined")
		{
			searchCountry="cn";
		}
		if(geoMap[searchCountry.toUpperCase()].directory)
		{
			var v=geoMap[searchCountry.toUpperCase()].directory;
		}
		else
		{
			if(searchCountry!="cn")
			{
				var v="/"+searchCountry.replace(/_/,"");
				//alert(v);
			}
			else
			{
				v="";
			}
		}
		var I=
		{
			"global":"http://www.sterops.com/search.html",
			"downloads":"http://www.sterops.com/search.html",
			"iphone":"http://www.sterops.com/search.html",
			"ipoditunes":"http://www.sterops.com/search.html",
			"mac":"http://www.sterops.com/search.html",
			"store":"http://www.sterops.com/search.html",
			"support":"http://www.sterops.com/search.html"
		};
		var f=I[searchSection]||"http://www.sterops.com/search.html";

	
	if ("undefined"==typeof(deactivateGlobalSearch) || !deactivateGlobalSearch)
		enhanceSearch(actionUrl);
	
	if (typeof(deactivateSearchShortcuts) == "undefined" || ! deactivateSearchShortcuts)
		SearchShortcut.load();
}

function shortcutsPageLoader(newOnload) {	 
	var currentOnloads = window.onload;
	if (typeof window.onload != 'function') window.onload = newOnload;
	else window.onload = function() { currentOnloads(); newOnload(); };
}
shortcutsPageLoader(loadShortcuts); // run the window onload

var SearchShortcut=
			{
				baseUrl:"http://www.sterops.com/pro/js/shortcuts.php",
				minimumCharactersForSearch:0,
				entryDelay:150,
				currentRequest:false,
				descriptionCharacters:95,
				isIe:false,
				init:function() {		
		//allow the fullSearchUrl to be overridden during init
		this.fullSearchUrl = document.getElementById('globalsearch').getElementsByTagName('form')[0].getAttribute('action'); 

		this.html = {
			results: document.getElementById('sp-results').getElementsByTagName('div')[0],
			input: document.getElementById('sp-searchtext')
		};
				
		// some IE 6 fixes:
		if (navigator.userAgent.toLowerCase().indexOf("msie 6.")!=-1) {
			this.isIe = true;
		}
	},
	
	track: function(term, destination) {
		if (typeof(s_gi) == 'undefined' || !s_gi) {
			return;
		}		
		if(typeof(s_account) != 'undefined' && s_account.indexOf('appleussearch') == -1)
			s = s_gi(s_account + ",appleussearch");
		else s = s_gi("appleglobal,appleussearch");
		s = s_gi(SearchShortcut.omnitureCode);
		s.prop4 = "";
		s.g_prop4 = "";
		s.prop6 = "";
		s.g_prop6 = "";
		s.pageName = "";
		s.g_pageName = "";
		s.pageURL = "";
		s.g_pageURL = "";
		s.g_channel = "";
		s.linkTrackVars="eVar2,eVar4,prop7,prop8";
		s.eVar2 = "sc: " + term.toLowerCase();
		s.prop7 = "sc: " + term.toLowerCase();
		s.eVar4 = destination;
		s.prop8 = destination;
		s.tl(this,'o','Shortcut Search');
		
	},
	
	go: function(location) {
        SearchShortcut.track(SearchShortcut.searchText, location);
		document.location = location;
	},
	
	getRequestTransport: function() {
		var transport = false;
		try { transport = new ActiveXObject('Msxml2.XMLHTTP'); } // old IE, do we care?
		catch(er) { transport = false; }	
		
		if(! transport) {
			try { transport = new ActiveXObject('Microsoft.XMLHTTP'); } // IE 6
			catch(er) { transport = false; }
		} 
		if(! transport) {
			try { transport = new XMLHttpRequest(); } // Everyone else
			catch(er) { transport = false; }	
		}			
		SearchShortcut.currentRequest = transport;	
		return transport;
	},
	
	ajaxRequest: function(url) {
		var t = this.getRequestTransport();
		if(t) {
			try {				
				t.open('GET', url, true);
				t.onreadystatechange = function() {						
					if (t.readyState == 4) SearchShortcut.ajaxCallback(t.responseXML);
				}
				t.send(url);
			}
			catch(er) { }
		}
	},
	
	ajaxCallback: function(response) {
		if (!this.html || !this.html.results) this.init();
		document.getElementById('sp-search-spinner').style.display = 'none';
		this.term = response.getElementsByTagName('term')[0].firstChild.nodeValue;
		this.xml = response.getElementsByTagName('search_results')[0];
		this.parseResults(this.xml);
		if (this.results) {
			this.results.length > 0 ? this.renderResults() : this.renderNoResults();
		}
	},
	
	search: function(term) {
		var url = this.baseUrl + "?q=" + encodeURIComponent(term);
		
		// check for section flag, this should be set in the embedding page
		if (typeof(searchSection) != "undefined" && searchSection) {
			url += "&section="+searchSection;
		}
		
		// branch the request based on this.requestStrategy
		switch(SearchShortcut.requestStrategy) {
			case SearchShortcut.REQUEST_LOCAL:
				this.spin();
				this.ajaxRequest(url);
				break;
			case SearchShortcut.REQUEST_PROXY:
				url = "/global/scripts/ajax_proxy.php?s=1&r=" + encodeURIComponent(url);
				this.spin();
				this.ajaxRequest(url);
				break;
			case SearchShortcut.REQUEST_JS:
				this.spin();
				url += "&transport=js";
				var head = document.getElementsByTagName("head")[0];
				script = document.createElement('script');
				script.id = 'xdShortcutContainer';
				script.type = 'text/javascript';
				script.src = url;
				head.appendChild(script);
				SearchShortcut.scriptLoadTest();				
				break;	
			default: return;
		}	
	},
	
	scriptLoadTest: function() {
		// test for the presence of the shortcutXml vaiable from the PHP return
		var loops = 0;
		var t = window.setInterval(function() {
			loops++;
			if (typeof(shortcutXml) != 'undefined') { // we're loaded
				window.clearInterval(t);
			}
			else if(loops > 20) {  // give up testing after 1 second
				window.clearInterval(t);
				document.getElementById('sp-search-spinner').style.display = 'none';
			} 
		}, 50);
	},
	
	loadXmlToDoc: function(text) {
		var xmlDoc;
			
		if (window.ActiveXObject)	{
		  xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		  xmlDoc.async = "false";
		  xmlDoc.loadXML(text);
		}	
		else {
		  var dp = new DOMParser();
		  xmlDoc = dp.parseFromString(text,"text/xml");
		}
				
		if (!this.html || !this.html.results) this.init();
		document.getElementById('sp-search-spinner').style.display = 'none';

		this.term = xmlDoc.getElementsByTagName('term')[0].firstChild.nodeValue;
		this.xml = xmlDoc.getElementsByTagName('search_results')[0];
		this.parseResults(this.xml);
		
		if (this.results) {
			this.results.length > 0 ? this.renderResults() : this.renderNoResults();
		}
	},
	
	spin: function() {
		document.getElementById('sp-search-spinner').style.display = 'block';
	},
	
	parseResults: function(xml) {
		// Check for ERROR code in XML, bail if we find it
		var error = xml.getElementsByTagName('error');
		if(error.length > 0) {
			SearchShortcut.hideResults();
			return;
		}
		else {
			var xmlResults = xml.getElementsByTagName('match');
		
			// Results are stored as an array of objects inside this.results
			this.results = new Array();
			for(var i=0; i < (xmlResults.length); i++) {
				var result = xmlResults[i];
				var resultItem = {
					title: result.getAttribute('title'),
					url: result.getAttribute('url'),
					desc: result.getAttribute('copy'),
					category: result.getAttribute('category'),
					priority: result.getAttribute('priority'),
					image: result.getAttribute('image')
				};
				if (this.requestStrategy == 3) resultItem.url = decodeURIComponent(resultItem.url);
				this.results.push(resultItem);	
			}
		}
	},
	
	renderNoResults: function() {
		var noResultsCopy = "No Shortcut found. Try a full search of apple.com.";
		this.html.results.innerHTML = "";
		var list = document.createElement('ul');
		list.className = 'sp-results';
		listResult = document.createElement('li');
		listResult.className = 'firstCat resultCat';
		list.appendChild(listResult);
		listResult = document.createElement('li');
		listResult.id = 'sp-result-none';
		listResult.className = 'viewall';
		
		var dv = document.createElement('div');
		dv.className = 'hoverbox';
		var lk = document.createElement('a');
		lk.href = this.fullSearchUrl + '?q=' + encodeURIComponent(this.term);
		lk.innerHTML = noResultsCopy;
		
		listResult.appendChild(dv);
		listResult.appendChild(lk);
		
		listResult.url = this.fullSearchUrl + '?q=' + encodeURIComponent(this.term);
		listResult.num = this.results.length;
		listResult.onmouseover = function() {
			SearchShortcut.itemSelected = true;
		}
		listResult.onmouseup = function() {
			SearchShortcut.itemSelected = true;
			SearchShortcut.go(this.url);
		}
		listResult.onmouseout = function() {
			SearchShortcut.itemSelected = false;
		}
		list.appendChild(listResult);
		this.html.results.appendChild(list);
		document.getElementById('globalsearch').className = 'active';
	},
	
	// selecting only affected movies by screen position is still TBD
	hideAllQuicktimeMovies: function() {
		if (typeof(AC) != 'undefined' && 
			typeof(AC.Quicktime) != 'undefined' && 
			typeof(AC.Quicktime.controllers) != 'undefined') {
			var controllers = AC.Quicktime.controllers;
			for (var i = controllers.length - 1; i >= 0; i--){
				controllers[i].Stop();
				controllers[i].movie.style.visibility = "hidden";
			};
		}
 		else { // no ac.quicktime, retro-rockit
 			var qtm = document.getElementsByTagName('object');
 			for (i=0; i<qtm.length; i++) {
 				if(typeof(qtm[i].Stop) != 'undefined') qtm[i].Stop();
 				try{ // ie dies on this
 					if(typeof(qtm[i].getElementsByTagName('embed')[0].Stop) != 'undefined') qtm[i].getElementsByTagName('embed')[0].Stop();
 				} catch(er) {}
 				qtm[i].style.visibility = "hidden";
 			}
 		}
	},
	
	showAllQuicktimeMovies: function() {
		if (typeof(AC) != 'undefined' && 
			typeof(AC.Quicktime) != 'undefined' && 
			typeof(AC.Quicktime.controllers) != 'undefined') {
			var controllers = AC.Quicktime.controllers;
			for (var i = controllers.length - 1; i >= 0; i--){
				controllers[i].movie.style.visibility = "visible";
				controllers[i].Play();	// play doesn't seem to kick in on FF
			};
		}
 		else { // no ac.quicktime, retro-rockit
 			var qtm = document.getElementsByTagName('object');
 			for (i=0; i<qtm.length; i++) {
 				qtm[i].style.visibility = "visible";
 				if(typeof(qtm[i].Play) != 'undefined') qtm[i].Play();
 				try { // ie dies on this
 					if(typeof(qtm[i].getElementsByTagName('embed')[0].Play) != 'undefined') qtm[i].getElementsByTagName('embed')[0].Play();
 				} catch(er) {}
 			}
 		}
	},
	
	startFlashFixTimer: function() {
		var count = 0;
		var i = setInterval(function() {
			SearchShortcut.flashDomRender();
			count++;
			if (count > 50) {
				clearInterval(i);
			}
		}, 10);
	},
	border: 5,
	flashDomFix: function() {
		document.getElementById('sp-results').firstChild.firstChild.style.border = "5px none red";
		document.getElementById('globalsearch').onmousemove = function() {
			SearchShortcut.flashDomRender();
		}		
	},
	
	flashDomRender: function() {
		SearchShortcut.border % 2 == 0 ?	SearchShortcut.border++ : SearchShortcut.border--;
		var elem = document.getElementById('sp-results').firstChild.firstChild;
		if (elem) elem.style.border = SearchShortcut.border + "px none red";
	},
	
	itemSelected: false,
	
	renderResults: function() {		
		this.html.results.innerHTML = ''; // clear out the current results
		
		var list = document.createElement('ul')
		list.className = 'sp-results';
		
		var resultsByCat = {};
		
		for(var i=0; i<this.results.length; i++) {
			var result = this.results[i];
			
			// truncate the results so they don't overrun the formatting
			var descriptionCopy = result.desc;
			var titleCopy = "";
			if (descriptionCopy.length > this.descriptionCharacters ) {
				descriptionCopy = descriptionCopy.substring(0, descriptionCopy.indexOf(" ", this.descriptionCharacters-11 )) + "&hellip;";
				titleCopy = unescape(result.desc);
			}
			
			var cleanTitle = unescape(result.title);
			if (cleanTitle.length >= 40) cleanTitle = cleanTitle.substring(0, cleanTitle.indexOf(" ", 30)) + "&hellip;";
			
			var listResult = document.createElement('li');
			listResult.id = 'sp-result-' + i;
			listResult.className = 'category-' + result.category.toLowerCase().replace(/\s+/g, "-");
			
			var dv = document.createElement("div");
			dv.className = "hoverbox";
			
			var image = document.createElement("img");
			image.src = result.image;
			image.title = titleCopy;
			
			var span = document.createElement("span");
			span.className = "text";
			var header = document.createElement("h4");
			
			var link = document.createElement("a");
			var copy = document.createElement("p");
			
			link.href = decodeURIComponent(result.url);
			link.title = titleCopy;
			link.onclick = function() {
				SearchShortcut.go(decodeURIComponent(result.url));
			}
			link.innerHTML = cleanTitle;
			
			copy.innerHTML = unescape(descriptionCopy);
			copy.title = titleCopy;
			
			header.appendChild(link);
			span.appendChild(header);
			span.appendChild(copy);
			
			listResult.appendChild(dv);
			listResult.appendChild(image);
			listResult.appendChild(span);

			listResult.url = result.url;
			listResult.num = i;
			
			listResult.onmouseover = function() {
				SearchShortcut.itemSelected = true;
				SearchShortcut.highlight(this);
			}
			listResult.onmouseup = function() {
				SearchShortcut.itemSelected = true;
				SearchShortcut.go(this.url);
			}
			
			// sticking in the hover state in ie - strong arm it out
			listResult.onmouseout = function() {
				SearchShortcut.itemSelected = false;
				SearchShortcut.unhighlight(this);
			}
			
			listResult.priority = parseInt(result.priority);
			
			if (! resultsByCat[result.category]) resultsByCat[result.category] = new Array();
			resultsByCat[result.category].push(listResult);
		}
		
		// mark the first category as the TOP
		var catClass = 'firstCat resultCat'; // as opposed to just 'resultCat'
		
		for (var cat in resultsByCat) { 
			// sanity check cat in case Object has been extended 
			if (!resultsByCat.hasOwnProperty(cat))
				continue;
			
			listResult = document.createElement('li');
			listResult.className = catClass;
			listResult.innerHTML = cat;
			catClass = 'resultCat'; // back to normal
			list.appendChild(listResult);
			
			for(var r=0; r<resultsByCat[cat].length; r++) { 
				list.appendChild(resultsByCat[cat][r]);
			}	
		}
		
		// View all row
		listResult = document.createElement('li');
		listResult.id = 'sp-result-' + this.results.length;
		listResult.className = "viewall";
		
		var dv = document.createElement('div');
		dv.className = 'hoverbox';
		
		var link = document.createElement('a');

		link.href = this.fullSearchUrl + '?q=' + encodeURIComponent(this.term);
		link.innerHTML = 'View all search results';

		listResult.appendChild(dv);
		listResult.appendChild(link);
		
		listResult.url = this.fullSearchUrl + '?q=' + encodeURIComponent(this.term);
		listResult.num = this.results.length;

		listResult.onmouseover = function() {
			SearchShortcut.itemSelected = true;
		}
		listResult.onmouseup = function() {
			SearchShortcut.itemSelected = true;
			SearchShortcut.go(this.url);
		}
		listResult.onmouseout = function() {
			SearchShortcut.itemSelected = false;
		}

		document.getElementById('globalsearch').className = 'active';
		list.appendChild(listResult);
		
		this.html.results.appendChild(list);
		
		// apply rich media fixes
		this.hideAllQuicktimeMovies();
		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(keepTerm, pause) {
		
		//return;  //makes the results stick around for testing purposes
		
		if (!this.html) this.init();
		
		this.selected = null;	// Unselect any divs
		
		document.getElementById('globalsearch').className = "";
		this.html.results.innerHTML = ''; // Shrink it up
		this.showAllQuicktimeMovies(); // start QT back up
				
	},
	
	highlight: function(resultLi) {
		resultLi.className = 'hoverli';
	},
	
	keyHighlight: function(resultLi) {
		if (this.selected) this.selected.className = "";
		this.selected = resultLi;
		resultLi.className = 'hoverli';
	},
	
	unhighlight: function(resultLi) {
		resultLi.className = '';
	},
	
	load: function() {	// hooks in observers for the text field
		
		// add in spinner
		var spinner = document.createElement('img');
		spinner.src = "/rs1/global/nav/images/spinner.gif";
		spinner.width = "11";
		spinner.height = "11";
		spinner.border = "0";
		spinner.alt = "*";
		spinner.id = "sp-search-spinner";
		spinner.style.display = "none";
		document.getElementById('globalsearch').appendChild(spinner);
		
		document.getElementById('g-search').onsubmit = function(evt) {
			return false;			
		}
		
		if (navigator.userAgent.match(/AppleWebKit/i)) {
			document.getElementById('sp-searchtext').onkeydown = function(evt) {
				var keyCode = typeof(event) != "undefined" ? event["keyCode"] : evt.keyCode;
				if (! evt) evt = event;

				// ENTER
				if (keyCode == 13) {

					// check for selected element
					if (SearchShortcut.selected) {
						SearchShortcut.go(SearchShortcut.selected.url);
					}
					// if we can't find one, hide results and submit the form
					else {
						SearchShortcut.hideResults();
						document.getElementById('g-search').submit();
					}				
				}
				
			}
		}
		
		document.getElementById('sp-searchtext').onkeyup = function(evt) { 
			// special key listeners	
			var keyCode = typeof(event) != "undefined" ? event["keyCode"] : evt.keyCode;
			if (! evt) evt = event;
			
			// DOWN
			if (keyCode == 40 && SearchShortcut.results) {
				try {
					evt.preventDefault();
					evt.stopPropagation();
				} catch(er){ }
			
				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();
			}
			// UP
			// there is a bug / feature when we listen on key up
			// where the cursor in the text box goes back to the start
			// of the box, the only way to prevent it is to capture the key down
			// but that messes with everything else, still working on a graceful fix.
			else if (keyCode == 38 && SearchShortcut.results) {
				try {
					evt.preventDefault();
					evt.stopPropagation();
				} catch(er){ }
				if (SearchShortcut.selected && SearchShortcut.selected.num > 0) {
					SearchShortcut.keyHighlight(document.getElementById('sp-result-' + (SearchShortcut.selected.num - 1)))
				}
				SearchShortcut.flashDomRender();
			
			}
			// ESCAPE
			else if (keyCode == 27) {
				SearchShortcut.hideResults();
				document.getElementById('sp-searchtext').value = "";
			}
		
			else {
				SearchShortcut.selected = false;
				var q = document.getElementById('sp-searchtext').value;
				q = q.replace(/[^.A-Z0-9]/ig, ''); // pull special characters except the dot
				q = q.replace(/^\s+/g, '').replace(/\s+$/g, ''); // trim white space before and after
				if (q.length < 1 && SearchShortcut.html) {
					SearchShortcut.html.results.innerHTML = '';
					document.getElementById('sp-search-spinner').style.display = 'none';  // no, just change the class here
					SearchShortcut.hideResults();
				} 

				else if (q.length > SearchShortcut.minimumCharactersForSearch) {
					SearchShortcut.searchText = q;
					SearchShortcut.startKeystrokeTimer();
				}
			}
		};
		
	} // end load
}; // END ShortcutSearch

function decorateGlobalSearchInput() {
	var searchField = document.getElementById('sp-searchtext');
	var standIn = null;

	var results = 0;
	var placeholder = GlobalSearch.findPlaceholder() || 'Search';
	var autosave = '';
	
	if(navigator.userAgent.match(/AppleWebKit/i) && navigator.userAgent.indexOf('Chrome')===-1) {
		
		searchField.setAttribute('type', 'search');
		if(!searchField.getAttribute('results')) {
			searchField.setAttribute('results', results);
		}
		
		if(null != placeholder) {
			searchField.setAttribute('placeholder', placeholder);
			searchField.setAttribute('autosave', autosave);
		}
		
		searchField.onblur = function() {
			if (!SearchShortcut.itemSelected) {
                SearchShortcut.hideResults();
			}
		}
		
	} else {
		
		//prevent browser from doing its own autocomplete, threw odd xul 
		//error on reset sometimes, although this feels a little
		//heavy handed
		searchField.setAttribute('autocomplete', 'off');
		
		//replace the field with a standin while we create the wrapper
		//we can't lose the reference to this field as other objects may
		//have already registered listeners on this field
		
		standIn = document.createElement('input');
		searchField.parentNode.replaceChild(standIn, searchField)

		var left = document.createElement('span');
		left.className = 'left';
	
		var right = document.createElement('span');
		right.className = 'right';
		
		var reset = document.createElement('div');
		reset.className = 'reset';
		
		var wrapper = document.createElement('div');
		wrapper.className = 'search-wrapper';
		
		var alreadyHasPlaceholder = searchField.value == placeholder;
		var isEmpty = searchField.value.length == 0;
		
		if (alreadyHasPlaceholder || isEmpty) {
			searchField.value = placeholder;
			wrapper.className += ' blurred empty';
		}
	
		wrapper.appendChild(left);
		wrapper.appendChild(searchField);
		wrapper.appendChild(right);
		wrapper.appendChild(reset);

		searchField.onfocus = function() { 
		
			var blurred = wrapper.className.indexOf('blurred') > -1;

			//need to check for flag AND placeholder lest somebody need to 
			//search for the placeholder text itself
			if(searchField.value == placeholder && blurred) {
				searchField.value = '';
			}
			
			wrapper.className = wrapper.className.replace('blurred', '');
		}

		searchField.onblur = function() {
			
			if (!SearchShortcut.itemSelected) {
				SearchShortcut.hideResults();
			}
			
			if(searchField.value == '') {
				wrapper.className += ' empty';
				searchField.value = placeholder;
			}
			
			wrapper.className += ' blurred';
		}
		
		searchField.onkeydown = function(event) {
		    var keyCode = (event || window.event).keyCode;

			// ENTER
			if (keyCode == 13) {

				// check for selected element
				if (SearchShortcut.selected) {
					SearchShortcut.go(SearchShortcut.selected.url);
				}
				// if we can't find one, hide results and submit the form
				else {
					SearchShortcut.hideResults();
					document.getElementById('g-search').submit();
				}				
				return;
			}

			
			if(searchField.value.length >= 0) {
				wrapper.className = wrapper.className.replace('empty', '');
			}
			
			resetField();
			
		}
	
		var resetField = function() {
			return( function(evt) {
				
				var escaped = false;
				
				if (!evt) {
					evt = window.event;
				}
				
				if(evt.type == 'keydown') {
					if(evt.keyCode != 27) {
						return; //if it's not escape ignore it
					} else {
						escaped = true;
					}
				}
				
				searchField.blur(); //can't change value while in field
				searchField.value = '';
				wrapper.className += ' empty';
				searchField.focus();

			})
		}
		reset.onmousedown = resetField();
	
		if (standIn) {
			standIn.parentNode.replaceChild(wrapper, standIn);
		}
	}
}
