var xmlHttp = createXHR();
var xmlData = null;
var open_status = false;
var open_func = null;

function createXHR()
{
	if (typeof XMLHttpRequest != "undefined") 
	{
		return new XMLHttpRequest();
	}
	else if (typeof ActiveXObject != "undefined")
	{
		if (typeof arguments.callee.activeXString != "string")
		{
			var versions = ["MSXML2.XMLHttp.6.0", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp"];
			for (var i=0,len=versions.length; i < len; i++)
			{
				try {
					var xhr = new ActiveXObject(versions[i]);
					arguments.callee.activeXString = versions[i];
					return xhr;
				} catch (ex) {
					//skip
				}
			}
		}

	return new ActiveXObject(arguments.callee.activeXString);
	} else {
		return false;
	}
}

function getXmlHttp(url,params)
{
	xmlData = '';
	var Url = url;
	if (params != '') Url += '?' + params + '&random=' + Math.random();
	
    if (xmlHttp == false) { return false; }

	xmlHttp.onreadystatechange = ProcessRequest;
	xmlHttp.open( "GET", Url, open_status );
	xmlHttp.send( null );
}

function getXmlHttpText(url,params)
{
	xmlData = '';
	var Url = url;
	if (params != '') Url += '?' + params + '&random=' + Math.random();
	
    if (xmlHttp == false) { return false; }

	xmlHttp.onreadystatechange = ProcessRequestText;
	xmlHttp.open( "GET", Url, open_status );
	xmlHttp.send( null );
}

function ProcessRequestText()
{
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
	{
		xmlData = xmlHttp.responseText;
		if (open_func != null) open_func();
	}
}

function ProcessRequest()
{
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
		xmlData = eval( "(" + xmlHttp.responseText + ")" );
}

function ObjectPosition(obj) {
    var curleft = 0;
      var curtop = 0;
      if (obj.offsetParent) {
            do {
                  curleft += obj.offsetLeft;
                  curtop += obj.offsetTop;
            } while (obj = obj.offsetParent);
      }
      return [curleft,curtop];
}

(function(){
var l=this,o=l.q=function(A,B){return o.fn.init(A,B);};
o.fn=o.prototype={
	init:function(A,B){
		var i;
		this.EB = null;
		if ((typeof A == 'string') && (i = document.getElementById(A))) { this.EB = i; }
		if (typeof A == 'object') { this.EB = A; }
		return this;
	},
	EB: null
};

o.extend=o.fn.extend=function(){
	var J=arguments[0],I=arguments.length,H=1;
	if (!J) return;
	if (typeof J === 'boolean' && J) J = o.fn;
	for (; H<I; H++) {
		var G = arguments[H];
		for (var F in G) {var L = G[F]; J[F] = L;}
	}
};

o.fn.extend(true,{
	ge:function(id){return document.getElementById(id);},
	posLeft:function(P) {
		var x = 0;
		while (P) {
			x += P.offsetLeft;
			P = P.offsetParent;
		}
		return x;
	},
	posTop:function(P) {
		var x = 0;
		while (P) {
			x += P.offsetTop;
			P = P.offsetParent;
		}
		return x;
	},
	getScrollXY:function() {
		var scrOfX = 0, scrOfY = 0;
		if( typeof( window.pageYOffset ) == 'number' ) {
			scrOfY = window.pageYOffset;
			scrOfX = window.pageXOffset;
		} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
			scrOfY = document.body.scrollTop;
			scrOfX = document.body.scrollLeft;
		} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
			scrOfY = document.documentElement.scrollTop;
			scrOfX = document.documentElement.scrollLeft;
		}
		return [ scrOfX, scrOfY ];
	},
	getWindowXY:function() {
		var myWidth = 0, myHeight = 0;
		if( typeof( window.innerWidth ) == 'number' ) {
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		}
		return [myWidth,myHeight];
	}
});

o.QS=o.prototype.QS={};
o.extend(o.QS,{
	E:null,
	set:function(){
		var L=o.fn.EB,D=document.createElement('div');
		D.className="hidden";
		D.id = 'sr_'+(new Date()).getTime()+Math.random();
		D.setAttribute('qT',null);
		D.setAttribute('qP',L.id);
		D.onmouseover = function(){o.QS.clearTimer(this);};
		D.onmouseout = function(){o.QS.setTimer(this);};
		
		L.setAttribute('qD',D.id);
		L.setAttribute('oV', '``!!@@##$$%%^^&&**(())');
		L.parentNode.appendChild(D);
		L.onkeyup=function(e){o.QS.get(this,e);};
		L.onmouseover = function(){o.QS.clearTimer(o.fn.ge(this.getAttribute('qD')));};
		L.onmouseout = function(){o.QS.setTimer(o.fn.ge(this.getAttribute('qD')));};
		this.setHelper(L);
	},
	setHelper:function(L) {
		L.value = 'Kohls';
		L.style.color = '#AAA';
		L.onfocus = function() { o.QS.hideHelper(this); }
	},
	hideHelper:function(L) {
		L.value = '';
		L.style.color = '#000';
		L.onfocus = null;
	},
	get:function(pt,e){
		var qS = pt.getAttribute('qS'), qC = pt.getAttribute('qC'), qSN = null, F=o.fn, oV = pt.getAttribute('oV');
		if (qS) qS = parseInt(qS);
		if (qC) qC = parseInt(qC);
		
		var Ev = e ? e : event;
		if (oV != '``!!@@##$$%%^^&&**(())' && qS != null && qC != null && qC > 0 && Ev.keyCode) {
			switch (Ev.keyCode) {
				case 38:
					qSN = qS - 1;
					if (qSN < 0) qSN = qC - 1;
					break;
				
				case 40:
					qSN = qS + 1;
					if (qSN == qC) qSN = 0;
					break;
					
				case 27:
					pt.value = pt.getAttribute('oV');
					q(pt).QS.hide();
					return;
			}
		}
		
		if (qSN != null) {
			this.move_cursor(pt,qSN);
		} else {
			with (o.ajax) {
				if(xh == null)return;
				xh.abort();
				o.QS.E = pt;
				get('/search/gs.v2/?text='+escape(pt.value),o.QS.show);
			}
		}
	},
	move_cursor:function(L,qSN) {
		var F=o.fn,D=F.ge(L.getAttribute('qD')), al = D.getElementsByTagName('a'), ai = L.getAttribute('qS'), A;
		if (ai == qSN) return;
		
		for (var i = 0, len = al.length; i < len; i++) {
			A = al[i].getAttribute('i');
			if (ai == A) {
				al[i].className = '';
			} else if (qSN == A) {
				al[i].className = 'select';
				L.value = al[i].innerHTML.replace('&amp;', '&');
			}
		}
		L.setAttribute('qS', qSN);
	},
	check_cursor:function(L) {
		var qS = L.getAttribute('qS'), F=o.fn;
		if (qS < 0) return true;
		var al = F.ge(L.getAttribute('qD')).getElementsByTagName('a');
		for (var i = 0, len = al.length; i < len; i++) {
			if (al[i].getAttribute('i') == qS) {
				document.location.href = al[i].href;
				break;
			}
		}
		return false;
	},
	show:function(data){
		var F=o.fn,Q=o.QS,L=Q.E;
		var D=F.ge(L.getAttribute('qD'));
		D.className = "hidden";
		Q.clearTimer(D);

		if (data === false || data.status != 'ok' || typeof data.list == 'undefined' || data.list == '') return;
		D.innerHTML = decodeURIComponent(data.list);
		var al = D.getElementsByTagName('a');
		for (var i = 0, len = al.length; i < len; i++) {
			al[i].setAttribute('i', i);
			al[i].setAttribute('t', L.id);
			al[i].onmouseover = function() { o.QS.move_cursor(document.getElementById(this.getAttribute('t')), this.getAttribute('i')); };
		}
		with (D.style) {
			top = F.posTop(L)+parseInt(L.offsetHeight)+'px';
			left = F.posLeft(L)+'px';
		}
		D.className = "sr_list";
		L.setAttribute('qS', -1);
		L.setAttribute('qC', data.count);
		L.setAttribute('oV', L.value);
		
		var FM = F.ge('form_'+L.id);
		FM.setAttribute('L', L.id);
		FM.onsubmit = function() { return o.QS.check_cursor(document.getElementById(this.getAttribute('L'))); };
	},
	hide:function() {
		var F=o.fn,L=F.EB,D=F.ge(L.getAttribute('qD'));
		D.className = "hidden";
		D.setAttribute('qT',null);
		L.setAttribute('qS', '');
		L.setAttribute('oV', '``!!@@##$$%%^^&&**(())');
	},
	clearTimer:function(D) {
		var T = D.getAttribute('qT');
		if (T != null) {
			window.clearTimeout(T);
			D.setAttribute('qT',null);
		}
	},
	setTimer:function(D) {
		D.setAttribute('qT',
			window.setTimeout(function(){q(D.getAttribute('qP')).QS.hide();},500));
	}
});

o.ajax = o.prototype.ajax = {};
o.extend(o.ajax, {
	xh:null,
	init:function() {
		var X = null;
		if (window.XMLHttpRequest) {
			X = new XMLHttpRequest();
			if (X.overrideMimeType) X.overrideMimeType('text/xml');
		} else if (window.ActiveXObject) {
			try {
				X = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					X = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}
		this.xh = X;
	},
	get:function(U,F,OS) {
		var X = this.xh;
		if (X == null) return;
		OS = OS || true;
			
			
		if (U.indexOf('?') < 0) U += '?'; else U += '&';
		U += 'mr='+(new Date()).getTime();
		
		X.onreadystatechange = function() { o.ajax.PR(F); };
		X.open( "GET", U, OS );
		X.send( null );	
	},
	PR:function(F) {
		var X = this.xh;
		if (X.readyState == 4 && X.status == 200) {
			try {  var v = eval("("+X.responseText+")"); }
			catch (e) { v = false; }
			return F(v);
		}
	}
});
o.ajax.init();

o.AT = o.prototype.AT = {};
o.extend(o.AT, {
	toBottom:function() {
		var F = o.fn, E = F.EB, dv = document.createElement('div');
		dv.appendChild(E.cloneNode(true));
		dv.className = 'rbPanel';
		document.body.appendChild(dv);
		var Func = function(data) { addthis_config.ui_offset_top = (F.getScrollXY())[1]; };
		o.WD.add(Func, dv, 'onscroll');
		o.WD.add(Func, dv, 'onresize');
	}
});

o.WD = o.prototype.WD = {};
o.extend(o.WD, {
	list:{'onresize':[], 'onscroll':[]},
	add:function(func,data,type) {with(this){
		if (typeof list[type] == 'undefined') return;
		list[type].push({'func':func, 'data':data});
	}},
	prResize:function() {with(this){
		var rs = list.onresize;
		for (var i in rs)
			if (typeof rs[i].func == 'function') rs[i].func(rs[i].data);
	}},
	prScroll:function() {with(this){
		var rs = list.onscroll;
		for (var i in rs)
			if (typeof rs[i].func == 'function') rs[i].func(rs[i].data);
	}},
	init:function() {
		window.onscroll = function() { o.WD.prScroll(); };
		window.onresize = function() { o.WD.prResize(); };
	}
});
o.WD.init();


})();
