(function(){

function B(a,b,c) {
	if(!a||typeof c!="string") return;
	b=b?b:"";
	c=c?c:"";
	a.style[b]=c;
	return a
}
function C(a,b){
	if(!b)return;
	if(typeof b=="string")
	{
		var re=/\s?([a-z\-]*)\:\s?([^;]*);?/gi,c;
		while((c=re.exec(b))!=null)
		{
			B(a,c[1],c[2])
		}
	}
	else if(typeof b=="object")
	{
		for (var d in b)
		{
			B(a,d,b[d])
		}
	}
}
function creatDom(a,b){

	var d=ce(a.tag||'div');
	for(var c in a)
	{
		if(c=="tag"||c=="children"||c=="cn"||c=="html"||c=="style"||typeof a[c]=="function") continue;
		if(c=="cls")
		{
			d.className=a["cls"];
		}
		else
		{
			if(d.setAttribute) sa(d,c,a[c]);
			else d[c]=a[c];
		}
	}
	if(a.html)
	{
		d.innerHTML=a.html
	}
	C(d,a.style);
	if(b) ap(b,d);
	return d
}
function gts(a,b){return a.getElementsByTagName(b)}
function gt(a,b){var c=gts(a,b);return c&&c.length>0?c[0]:null}
function forArray(a,b){var c=gl(a),i;for(i=0;i<c;i++){b(a[i],i)}}
function ce(a){return document.createElement(a)}
function lf(a,b){a.style.left=px(b)}
function gl(a){return a.length}
function px(a){return a+"px"}
function ap(a,b){a.appendChild(b)}
function sa(a,b,c){a.setAttribute(b,c)}
function tp(a,b){a.style.top=px(b)}
function toArr(a){return a&&(!a.length||typeof(a)=="string")?[a]:a;}
function _el(a){return document.getElementById(a)}
function loadCssText(css){
    var a=_el("dcss");
    if(!a)a=loadCssText.create();
    if(a.styleSheet) a.styleSheet.cssText+=css;
    else ap(a,document.createTextNode(css));
}
loadCssText.$id="dcss";
loadCssText.create=function(){
    var a=ce("style");
    a.id=loadCssText.$id
    sa(a,"type","text/css");
    ap(gt(document,"head"),a);
    return a;
}
function E1(){};
E1.addListener=E1.a=function(a,b,c){var d=E1.e(b);if(a[d]){a[d].push(c)}else{a[d]=[c]}function _E(a,b,c){this.instance=a;this.propertyName=b;this.listenerFn=c}return new _E(a,d,c)};
E1.removeListener=E1.b=function(a){var b=a.instance[a.propertyName];for(var c=0;c<b.length;c++){if(b[c]==a.listenerFn){b.splice(c,1);return}}};
E1.clearListeners=E1.c=function(a,b){var c=E1.e(b);a[c]=null};
E1.trigger=E1.d=function(a,b){var c=E1.e(b);var d=a[c];if(d&&d.length>0){var e=[];for(var f=2;f<arguments.length;f++){e.push(arguments[f])}for(var f=0;f<d.length;f++){var g=d[f];if(g){try{g.apply(this,e)}catch(h){L2.a(h+"\n"+a.getClassName()+" "+b+"\n"+g,"Event.trigger() exception")}}}}};
E1.e=function(a){return"_e__"+a};
E1.addBuiltInListener=E1.f=function(a,b,c){
	if(a.addEventListener){a.addEventListener(b,c,false)}
	else if(a.attachEvent){a.attachEvent("on"+b,c)}
	else{a["on"+b]=c}
	var d={obj:a,ev:b,func:c},e=a["__ev__"];
	if(!e) e=a["__ev__"]=[];
	e.push(d);
	return d
};
E1.removeBuiltInListener=E1.g=function(a,b,c){
	var d=a;if(!b&&!c){a=d.obj;b=d.ev;c=d.func}
	if(a.removeEventListener){a.removeEventListener(b,c,false)}
	else if(a.detachEvent){a.detachEvent("on"+b,c)}else{a["on"+b]=null}
};
var z=0,w=window,SEvent=w.SEvent||E1;
if(!w.SGS){z=1;w.SGS={}}
if(!SGS.tools_head) SGS.tools_head=function(a){w["fnInitHead"]=a();delete SGS.tools_head;if(z)window.SGS=null;};

// Same with tools/head.js start
SGS.tools_head&&SGS.tools_head(function(){
	var inited=0,bu="map.sogou.com",cd=creatDom,u=void(0),w=window;
	var L0=0,R0=0,t0,p0,m0,i0,c0,f0,fnc,s0;
	var fs=[
		["\u9996\u9875","/home/[c=?c]#from=[?from]","0,1,2,3,4,5,6","0,7,8,9,0,9,8,7",0,0]
		,["\u5730\u56FE","/#[c=?c&]from=[?from]","0,1,2,3,4,5,6","0,7,8,9,10,9,8,7",0,0]
		,["\u5546\u5E97","/store/[c=?c]#from=[?from]","0,1,2,3,4,5,6","0,7,8,9,10,9,8,7",0,0]
//		,["\u627E\u623F","/house/c=[?c]#from=[?from]","0,1,2,3,4,5,6","0,7,8,9,0,9,8,7",1,0]
		,["\u8DEF\u4E66","/lushu/#from=[?from]","0,1,2,3,4,5,6","0,7,8,9,10",0,0]
		,["\u8DEF\u51B5","/ssjt2/#from=[?from]","0,1,2,3,4,5,6","0,7,8,9",0,0]
		,["\u793E\u533A","/bbs/#from=[?from]","0,1,2,3,4,5,6","7,8,9,10,7,8,9,0",0,0]
		,["\u624B\u673A","/shouji/#from=[?from]","0,1,2,3,4,5,6","0,7,8,9",1,0]
//		,["\u5B9A\u4F4D","/sosgps/#from=[?from]","0,1,2,3,4,5,6","7,8,9,0,9,8,7,0",0,1]
	];

	function create1(){

var a='.mapmore ';
loadCssText([
a,'{color:#4C4942;font:12px "宋体",Arial;text-align:center;position:aboslute;}'
,a,'.headclip{position:absolute;width:430px;height:264px;top:0;left:0;background:url(',i0+"i/5.gif",')}'
,a,'.headwin1{position:relative;overflow:hidden;width:35px;height:35px;left:0;top:0;margin:auto;}'
,a,'.headwin2{position:absolute;overflow:hidden;width:31px;height:12px;left:30px;top:1px;}'
,a,'.headrect{position:absolute;left:0;top:0;width:55px;height:50px;}'
,a,'.headmask{border:0px;}'
,a,'.ccurr{font-weight:bold;}'
,a,'.ccurr a{cursor:default;}'
].join(""));

		var a,b,c,d,e,li,h=_el(t0),_d0,m,k,d0,s=s0*fs.length-40;
		var loc =location.href.split('#')[0];
		var lreg = new RegExp("^(http://|/)(([^#?/]*)/)?"),lrs,frs;
		var alist=[],ahrefs=[];
		if(!h) return;
		h.className="mapmore";
		lrs = loc.match(RegExp("^([^:/?#.]+://)?([\\w\\d\\.%]+/(?:[^?#/]*/)?)"));
		lrs = lrs&&lrs[2]||"";
		forArray(fs,function(g,i){
			g[2]=repeat(g[2], 1);g[3]=repeat(g[3], 3);
			if(frs=lreg.exec(g[1])) {
				g.key = frs[3]||"ROOT";
				g.url = frs[1]=="/"? "http://"+bu+g[1]: g[1];
			}
		});
		
		_d0 = new driver(50);
		// 根据当前页路径调整链接
		forArray(fs,function(g,i){
			var _c,b=c0==g.key,o=cd({"cls":"headrect"+(b?" ccurr":"")},h),d=cd({"cls":"headwin1"},o),e=cd({"html":g[0]},o),f=g[4]&&cd({"cls":"headwin2"},o);
			lf(o,s0*i);
			a=cd({"tag":"a"},o);sa(a,"target",g[5]==1?"_blank":"_self");
			k=cd({"tag":"img","cls":"headrect headmask","name":g.key,"src":i0+"i/pixel.gif"},a);
			alist.push(a);
			ahrefs.push(b?"javascript:void(0)":g.url);
			_c = new clip(d, 0, -i*36, 36, 36, fs[i], b?11:0);
			_c.more = f&&new clip(f, -20, -7*36, 36, 36, fs[i], 9);
			if (!b) {
				k.onmouseover = _c.mouseover;
				k.onmouseout = _c.mouseout;
			}
		});
		SEvent&&SEvent.addBuiltInListener(w,"resize",updateLayout);
		m0&&m0.map&&SEvent&&SEvent.addListener(m0.map,"update",resetHref);
		resetHref();
		updateLayout();
		return c0;
		
		
		function clip(d, x, y, w, h, fl, s) {
			var _t=this,l;
			var _i=0,_j=0,_k=0;
			var a = cd({"cls":"headclip"},d);
			tp(a,y);lf(a,x-w*s);
			this.mouseover = function() { 
				_t.play([{"arr":fl[2]},{"arr":fl[3],"repeat":-1}]); 
				if(_t.more) 
					_t.more.mouseover(arguments);
			};
			this.mouseout = function(){ 
				_d0.remove(_t); 
				if(_t.more) 
					_t.more.mouseout(arguments);
			};
			this.next = function() {
				if(_i==l.length) return;
				var i=l[_i],arr=i.arr;
				_k++;
				if(_k==arr.length) {_k=0;_j++;}
				if(_j==i.repeat) {_i++;_j=0;_k=i.start;}
				if(_i==l.length) {_d0.remove(_t);return;}
				lf(a, x-w*arr[_k]);
			};
			this.play = function(lin) {
				var t=toArr(lin);if(!t||t.length==0)return;
				_d0.add(_t);l=t;
				forArray(l,function(g){
					g.repeat=g.repeat||1;g.start=g.start||0;
				});
				_i=0;_j=0;_k=l[0].start;
				lf(a, x-w*_k);
			};
			this.reset = function() {
				lf(a, x-w*s);
			};
		}
		function driver(t){
			var _i, list = [];
			this.add = function(o) {
				var f = false;
				for (var i=0; i<list.length; i++) {
					if (list[i]===o) { f = true; break; }
				}
				if(!f) list.push(o);
				if (!_i) _i = setInterval(next, t);
			};
			this.remove = function(o) {
				for (var i=0; i<list.length; i++) {
					if (list[i]===o) {
						list.splice(i, 1); o.reset(); break;
					}
				}
				if (list.length==0&&_i) {
					clearInterval(_i);
					_i = null;
				}
			};
			function next() {
				for (var i=0; i<list.length; i++) {
					list[i].next();
				}
			}
		}
		function repeat(str, n) {
			var arr = str.split(","), l = [];
			forArray(arr,function(g, i){
				for (var j=0; j<n; j++) l.push(g);
			});
			return l;
		}
		function resetHref() {
			var cx = fnc&&fnc()||m0&&m0.map&&(m0.getCenterX()+","+m0.getCenterY()+","+m0.getLevelIndex())||"";
			var flag = false;
			forArray(alist,function(a,i){
				a.href = ahrefs[i].replace(/\[([^\]]*)(\?c)([^\]]*)\]/, cx? "$1"+cx+"$3": "").replace(/\[\?from\]/, f0||lrs);
			});
		}
		function updateLayout() {
			var wd=p0&&p0.offsetWidth||getWindowSize()||1024,l=(wd-s-L0-R0)/2;
			if(l<0)l=0;
			lf(h,l+L0);
		}
		function getWindowSize()
		{
			return w.self&&self.innerWidth||document.documentElement&&document.documentElement.clientWidth||document.body.clientWidth;
		}
	}
	function create2()
	{
		var a=_el("weather");
	}
	/*
	function create3(f,g,h,i)//(txt,left,top,width)
	{
		var a=_el("right"),b=ce("div"),c=ce("div"),d,e=ce("div"),j;
		ap(a,b);
		sz(b,19999);
		pa(b);
		lf(b,g);
		tp(b,h);
		ap(b,c);
		pa(c);
		lf(c,5);
		tp(c,5);
		wd(c,i);
		ht(c,25);
		c.style.backgroundColor="#000";
		sf30(c);
		c=ce("div")
		pa(c);
		lf(c,0);
		tp(c,0);
		wd(c,i);
		ht(c,25);
		ap(b,c);
		ap(c,e);
		ap(e,ct(f));
		d=c.style;
		d.border="1px solid #EEA204";
		d.backgroundColor="#ffc";
		d=e.style;
		d.margin="7px 38px 0 7px";
		e=ce("div");
		ap(c,e);
		pa(e);
		tp(e,5);
		ap(e,ct("关闭"));
		e.className="link"
		e.style.right="5px";
		e.onclick=function(){d0(b)}
		j=new ImageClip(G.path+"i/1.png",19,126,345,289).setStyle({width:12,height:7,left:62,top:-6});
		ap(b,j.getDiv());
		SEvent.addListener(G,"citymouseover",function(){d0(b)})
		return b
	}
	*/
	function main(a){
		if(inited) return;
		a=a||{};
		t0=a.t||"mapmore";
		p0=a.p&&_el(a.p);
		m0=a.m||w["_m"];
		c0=a.c||"";f0=a.f||"";
		L0=a.l||0;R0=a.r||0;
		s0=a.s||90;
		i0=a.gp||w.G&&G.path||"http://map.sogou.com/head/";
		fnc=a.fnc||u;
		if(create1()=="ROOT") {
			create2();
			//var tip=create3("可在此切换城市哦！",118,56,168);
			//w.setTimeout(d0,10000,tip);
		}
		inited=1;
	}
	return main;
})
// Same with tools/head.js end

})()
