if (typeof WowuiSearch == "undefined") {
    var WowuiSearch = new
    function() {
		// Start Up
		
		var is_hover,
		headTag,
		headLink,
		headJS,
		searchElement,
		pIcon,
		clearHideDelay = 750,
		searchDelay = 100,
		searchTimer,
		clearHideTimer,
        pIcon,
		divIcon,
		tipTable,
		wowuidrop,
		dropHTML,
		item_array = new Array(),
		element_array = new Array(),

        ie6 = navigator.userAgent.indexOf("MSIE 6.0") != -1;
		
		
		
		
				
		// Functions
				
				
		function initialize(){

			
			// Stylesheet link
			headTag = document.getElementsByTagName("head")[0];
			headLink = document.createElement("link");
			headLink.setAttribute("rel","stylesheet");
			headLink.setAttribute("href","http://wowui.worldofwar.net/static/external_search.css");
			headLink.setAttribute("type","text/css");
			headTag.appendChild(headLink);
			
			if (ie6) {
                headLink = document.createElement("link");
				headLink.setAttribute("rel","stylesheet");
				headLink.setAttribute("href","http://wowui.worldofwar.net/static/external_search_ie6.css");
				headLink.setAttribute("type","text/css");
				headTag.appendChild(headLink);  
            }
        	
			// Find input/search element, attach onchange/onkeyup event
			// If not exist, do nothing further
			searchElement = document.getElementById("wowui_search");
			
			if(!searchElement)
				return false;

			makeDrop();
			
			//if(!searchElement.onkeyup)
				searchElement.onkeyup = KeyUp;
				searchElement.onblur = OnBlur; 
				searchElement.onfocus = OnFocus; 
				return true;
								
			
			
			
		}

		function KeyUp(e){
			if (!e) e = window.event;
			var lastVal = searchElement.value;
			if(e.keyCode == 13 || e.keyCode == 27){
				clearHideDrop();
				return false;
			}
			clearTimeout(searchTimer);
			if(lastVal != "" && lastVal.length > 2)
				searchTimer = setTimeout(function () {getSearchJSON(lastVal)}, searchDelay);
			if(lastVal.length < 3)
				hideDrop();
			
			return e.keyCode;
		}
		
		function clearHideDrop(){
				//searchElement.value = "";
				hideDrop();
		}
		
		function OnBlur(){
				clearHideTimer = setTimeout(function () { clearHideDrop();}, clearHideDelay);
		}
		function OnFocus(){
				clearTimeout(clearHideTimer);

		}
		
		
		
		function getSearchJSON(searchterm) {
			/*item_array[item_id] = setTimeout(function() {
                showLoadSearch.apply(this, [item_id]);
            },
            200);*/
			if(headJS){
				headTag.removeChild(headJS);
			}
			headJS = document.createElement("script");
			headTag.appendChild(headJS);
			
			headJS.setAttribute("type","text/javascript");
			if(typeof(wowui_search_powered_hide) != "undefined"){
				var powered_show = "false";
			}
			else
				var powered_show = "true";
			
			headJS.setAttribute("src", "http://wowui.worldofwar.net/search_assistant.php?q=" + searchterm);
			//_showDrop(searchterm);
			
        }
		
		
        function showLoadSearch(id) {
            if (is_hover == 1 && this_id == id) {
                _showDrop('Loading');
                item_array[this_id] = setTimeout(function() {
                    loadError.apply(this, [id]);
                },
                7000);
            }
        }
		
        function loadError(id) {
            item_array[id] = undefined;
            if (this_id == id && is_hover == 1)
                _showDrop('No response');
        };
		
		
		
		
		
        this.loadSearchJSON = function(data) {
			if(data.data != "")
        		_showDrop(data.data);
			else
				hideDrop();
			
        };
		

		

		
		function makeDrop() {
			if (!wowuidrop) {
				
				var div = document.createElement("div");
				var div_wrapper = document.createElement("div");
				var em = document.createElement("em");
				var var_element = document.createElement("var");
				var strong = document.createElement("strong");
				
				div.className = "wowui_search_assistant";
				div_wrapper.className = "wowui_search_assistant_wrapper";
				
				div_wrapper.appendChild(div);
				document.body.appendChild(div_wrapper);
				wowuidrop = div_wrapper;
				dropHTML = div;
				wowuidrop.appendChild(em);
				wowuidrop.appendChild(var_element);
				wowuidrop.appendChild(strong);
				positionDrop(searchElement);
				hideDrop();
				
			}
		}
		
		
		function findPosX(obj)
		{
			var curleft = 0;
			if(obj.offsetParent)
				while(1) 
				{
					curleft += obj.offsetLeft;
					if(!obj.offsetParent)
						break;
				  	obj = obj.offsetParent;
				}
			else if(obj.x)
				curleft += obj.x;
			return curleft;
	  	}
	
	  	function findPosY(obj)
	  	{
			var curtop = 0;
			if(obj.offsetParent)
				while(1)
				{
			  		curtop += obj.offsetTop;
			  		if(!obj.offsetParent)
						break;
			  		obj = obj.offsetParent;
				}
			else if(obj.y)
				curtop += obj.y;
			return curtop;
	  	}
	

		function positionDrop(obj) {
			var curleft = curtop = 0;
			
			curleft = findPosX(obj);
			curtop = findPosY(obj);
			var searchElementWidth = obj.offsetWidth;
			var searchElementHeight = obj.offsetHeight;
			var searchElementLeft = curleft;
			var searchElementTop = curtop;
			
			

			wowuidrop.style.top = searchElementTop + searchElementHeight + "px";
			wowuidrop.style.left = searchElementLeft +"px";
			wowuidrop.style.width = searchElementWidth  + "px";
			



		}
		

		
		function getBrowserSize()
		{
			var frameWidth = 0, frameHeight = 0;
			if (self.innerWidth)
			{
				frameWidth = self.innerWidth;
				frameHeight = self.innerHeight;
			}
			else if (document.documentElement && document.documentElement.clientWidth)
			{
				frameWidth = document.documentElement.clientWidth;
				frameHeight = document.documentElement.clientHeight;
			}
			else if (document.body)
			{
				frameWidth = document.body.clientWidth;
				frameHeight = document.body.clientHeight;
			}
			return {
                width: frameWidth,
                height: frameHeight
            };
		}

		
		function getBrowserScroll(){
			var frameScrollX = 0,frameScrollY = 0;
			if (self.pageYOffset) // all except Explorer
			{
				frameScrollX = self.pageXOffset;
				frameScrollY = self.pageYOffset;
			}
			else if (document.documentElement && document.documentElement.scrollTop)
				// Explorer 6 Strict
			{
				frameScrollX = document.documentElement.scrollLeft;
				frameScrollY = document.documentElement.scrollTop;
			}
			else if (document.body) // all other Explorers
			{
				frameScrollX = document.body.scrollLeft;
				frameScrollY = document.body.scrollTop;
			}
			return {
                x: frameScrollX,
                y: frameScrollY
            };
		}

		function hideDrop(){
			if (wowuidrop){
				wowuidrop.style.display = "none";
				wowuidrop.style.visibility = "hidden";
			}
		}
		
		this.hideDrop = function() {
			hideDrop();
		};
		function _showDrop(data) {

            if (!wowuidrop) {
                makeDrop();
            }
			
			dropHTML.innerHTML = data;
			wowuidrop.style.display = "block";
			wowuidrop.style.visibility = "visible";
           	wowuidrop.style.display = "";

        }
		
		
		function showDrop(id) {
			is_hover = 1;
            this_id = id;
            if (typeof item_array[id] == "object") {
                _showDrop(item_array[id].tooltip, item_array[id].icon);
            } else {
				if (!item_array[id]) 
                    getSearchJSON(id);
				else
					_showDrop('Loading');

            }
        }

		function CheckWhenReady(){
			/* for Mozilla */
			if (document.addEventListener) {
				document.addEventListener("DOMContentLoaded", initialize, false);
				return;
			}
			
			/* for Internet Explorer */
			/*@cc_on @*/
			/*@if (@_win32)
				document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
				var script = document.getElementById("__ie_onload");
				script.onreadystatechange = function() {
					if (this.readyState == "complete") {
						initialize(); // call the onload handler
						return;
					}
				};
			/*@end @*/
			
			/* for Safari */
			if (/WebKit/i.test(navigator.userAgent)) { // sniff
				var _timer = setInterval(function() {
					if (/loaded|complete/.test(document.readyState)) {
						initialize(); // call the onload handler
						return;
					}
				}, 10);
			}
			//window.onload = initialize;
			return;
		}
		
		var FastInitSearch = {
			onload : function() {
				if (FastInitSearch.done) { return; }
				FastInitSearch.done = true;
				for(var x = 0, al = FastInitSearch.f.length; x < al; x++) {
					FastInitSearch.f[x]();
				}
			},
			addOnLoad : function() {
				var a = arguments;
				for(var x = 0, al = a.length; x < al; x++) {
					if(typeof a[x] === 'function') {
						if (FastInitSearch.done ) {
							a[x]();
						} else {
							FastInitSearch.f.push(a[x]);
						}
					}
				}
			},
			listen : function() {
				if (/WebKit|khtml/i.test(navigator.userAgent)) {
					FastInitSearch.timer = setInterval(function() {
						if (/loaded|complete/.test(document.readyState)) {
							clearInterval(FastInitSearch.timer);
							delete FastInitSearch.timer;
							FastInitSearch.onload();
						}}, 10);
				} else if (document.addEventListener) {
					document.addEventListener('DOMContentLoaded', FastInitSearch.onload, false);
				} else if(!FastInitSearch.iew32) {
					if(window.addEventListener) {
						window.addEventListener('load', FastInitSearch.onload, false);
					} else if (window.attachEvent) {
						return window.attachEvent('onload', FastInitSearch.onload);
					}
				}
			},
			f:[],done:false,timer:null,iew32:false
		};
		/*@cc_on @*/
		/*@if (@_win32)
		FastInitSearch.iew32 = true;
		document.write('<script id="__ie_onload" defer src="' + ((location.protocol == 'https:') ? '//0' : 'javascript:void(0)') + '"><\/script>');
		document.getElementById('__ie_onload').onreadystatechange = function(){if (this.readyState == 'complete') { FastInitSearch.onload(); }};
		/*@end @*/
		FastInitSearch.listen();
		FastInitSearch.addOnLoad(initialize);
		
		//CheckWhenReady();

	};
}