﻿//function
function ge(z){return document.getElementById(z)}
function gE(z,y){return z.getElementsByTagName(y)}
function ce(z){return document.createElement(z)}
function de(z){z.parentNode.removeChild(z)}
function ct(z){return document.createTextNode(z)}
function rf(){return false}
function tb(){this.blur()}
function ac(z){var a=0,b=0;while(z){a+=z.offsetLeft;b+=z.offsetTop;z=z.offsetParent} return [a,b]}
function gp(o,z){o=o.parentNode;while(o.nodeName!=z){o=o.parentNode;} return o;}

function getEvent(){     //同时兼容ie和ff的写法　　取得操作对像
	 if(document.all)    return window.event;        
	 func=getEvent.caller;            
	 while(func!=null){    
		 var arg0=func.arguments[0];
		 if(arg0){
			 if((arg0.constructor==Event || arg0.constructor ==MouseEvent)
				 || (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation)){    
				 return arg0;
			 }
		 }
		 func=func.caller;
	 }
	 return null;
}
	//  获取文档信息
var Get = {
	winWidth  :function(){ return document.documentElement.clientWidth;},
	winHeight :function(){ return document.documentElement.clientHeight;},
	docWidth  :function(){ return document.documentElement.scrollWidth;},
	docHeight :function(){ return document.body.scrollHeight;},
	scrollTop :function(){ return document.documentElement.scrollTop},
	scrollLeft:function(){ return document.documentElement.scrollLeft} 
}

//取得对象的儿子节点
function getSon(o,el){
	var lia = gE(o,el)
		geta = new Array;
	for(i=0; i< lia.length; i++){
		if(lia[i].parentNode == o)
			geta.push(lia[i]);
	}
	return geta;
}

//顶部导航
var _navigateCurrent;
function createNavigate(){
	var _nav = ge("navigate"),
		_li = getSon(_nav,"LI");
	for(i=0; i<_li.length; i++){
		var a = gE(_li[i],"a")[0];
		a.onmouseover = function(){
			if(_navigateCurrent != null)
				_navigateCurrent.className = "" ;
			this.parentNode.className = "active";
			_navigateCurrent = this.parentNode;
		}
	}
}
//首页新闻
var _indexNewsCurrent;
function createIndexNews(){
	var _nts = gE(ge("_nt"),"a"),
		_nls = gE(ge("_nl"),"ul");
	for(i=0; i<_nts.length; i++){
		_indexNewsCurrent = _nts[i].parentNode.className == "active"?_nts[i]:_nts[0];
		_nts[i].id = i;
		_nts[i].onmouseover = function(){
			if(_indexNewsCurrent != this){
				this.parentNode.className = "active";
				_nls[this.id].style.display = "";				
				_indexNewsCurrent.parentNode.className = "";
				_nls[_indexNewsCurrent.id].style.display = "none";
				_indexNewsCurrent = this;
			}
		}
	}
	
}

//活动月份
var _currentShowMonth;
function createMonthList(n){
	var o = ge("monthList"),
		olis = gE(o,"li");	
	for(i = 0; i< 12; i++){
		olis[i].id = i;
		olis[i].style.backgroundPosition = -i*30 + "px 0";
		olis[i].onmouseover = function(){
			this.style.backgroundPosition = -this.id*30 + "px -29px";
		}
		olis[i].onmouseout = function(){
			if(_currentShowMonth != this)
				this.style.backgroundPosition = -this.id*30 + "px 0px";
		}
	}
	_currentShowMonth = olis[n];
	olis[n].style.backgroundPosition = -n*30 + "px -29px";
}

//下拉框
var rootSelect;
function SelectDrop(m){	    //0:节点 1:连接
	var _evt=getEvent(),
	_e=_evt.srcElement || _evt.target;	
	//显示/隐藏
	var _mlist=_e.parentNode;
	var ul=_mlist.getElementsByTagName("ul")[0];	
	if(rootSelect!=null) rootSelect.style.visibility =  "hidden";
	rootSelect = ul;
	if(ul!=null){
		ul.style.visibility = ul.style.visibility=="hidden"?"visible":"hidden";
	}
	//节点添加与事件
	if(!m){
	    ul.innerHTML = gE(ge("m4"),"ul")[0].innerHTML;
	    var ta = gE(ul,"a");
	    for(i=0;i<ta.length;i++){
	        ta[i].onclick = function(){	            
	            var _ot = ge("selectStyle");
	            if(gE(this.parentNode,"ul")[0] != null){
	                gE(_ot,"ul")[0].innerHTML = gE(this.parentNode,"ul")[0].innerHTML;
	                gE(_ot,"h1")[0].innerHTML =  gE(_ot,"a")[0].innerHTML;
	                var tma = gE(_ot,"a");
	                for(j=0;j<tma.length;j++){
	                    tma[j].target = "_blank";
	                }
	                _e.innerHTML = this.innerHTML;
	                return false;
	            }
	        }
	    }	    
	}
	//点击文档隐藏
	document.onclick = function(){
		var _dt=getEvent(),
		_t=_dt.srcElement || _dt.target;		
		if(_t != _e){
			rootSelect.style.visibility = "hidden";
		}
	}
	
}

//Index商品说明显示
var shopData = new Array();
shopData[0] = "<p class='tag'>蚩尤魔血</p><p>血量低于30%自动使用</p>";
shopData[1] = "<p class='tag'>女娲神泪</p><p>精力低于30%自动使用</p>";
shopData[2] = "<p class='tag'>守护天神</p><p>可以代替人物死亡一次</p>";
shopData[3] = "<p class='tag'>英勇药水</p><p>一小时内获得双倍荣誉值</p>";
var layout_shopBox;
function IndexShop(n){
	var _evt=getEvent(),
	_e=_evt.srcElement || _evt.target;
	//创建
	if(layout_shopBox == null){
	    var d = ce('div'),d2 = ce("div");
	    d.className = 'indexShop';
	    d2.className = "is_top";	    
	    d.appendChild(d2);
	    document.body.appendChild(d);
	    layout_shopBox = d;	    
	}
	gE(layout_shopBox,"div")[0].innerHTML = shopData[n];
	TP.show(_e,shopData[n],1,layout_shopBox);
}

//层提示显示
TP = {
	create: function(htmltext){
		var img = new Image();
		img.src = "../images/layout_bg.gif";
		
		var d = ce('div'), t = ce('table'), tb = ce('tbody'), tr1 = ce('tr'), tr2 = ce('tr'), td = ce('td'), th1 = ce('th'), th2 = ce('th'), th3 = ce('th');
		
		d.className = 'interface';
		th1.style.backgroundPosition = 'top right';
		th2.style.backgroundPosition = 'bottom left';
		th3.style.backgroundPosition = 'bottom right';
		if(htmltext) td.innerHTML = htmltext;
		td.id = "tpText";
		tr1.appendChild(td);
		tr1.appendChild(th1);
		tb.appendChild(tr1);
		tr2.appendChild(th2);
		tr2.appendChild(th3);
		tb.appendChild(tr2);
		t.appendChild(tb);
		d.appendChild(t);
		document.body.appendChild(d);
		return d;
	},
	show: function(_this,htmltext,mode,target){    		//mode:定位类型  0:固定  1:移动 target:是否有另外目标
		var _;
		
		if(target == null){     //没有目标对象，自动创建并填入htmltext
		    if(!TP.tp){
			    _ = TP.create();			
			    TP.tp	=_;
			    TP.table = gE(_, 'table')[0];
			    TP.td    = gE(_, 'td')[0];			
		    }		
		    _ = TP.tp;
		    _.style.width = "600px";
		    TP.table.style.width = "auto";
		    _.style.left = _.style.top = "-2000px";
    		
		    TP.td.innerHTML = htmltext;		
		    TP.fix(_,0);
		}else{
		    _ = target;
		    TP.tp = _;
		    //TP.tp.style.visibility = "visible";
		}
		if(mode){
			TP.move(_this, _);
		}else{
			var c = ac(_this),
				left = c[0], top = c[1];
			TP.afreshPos(_,left,top,_this.offsetWidth,_this.offsetHeight);
			_this.onmouseout = TP.hide;
		}
	},
	innert: function(htmltext){
	    TP.td.innerHTML = htmltext;
	},
	hide: function(){
		TP.tp.style.visibility = "hidden";
		TP.tp.style.left = TP.tp.style.top = "-2000px";
	},
	fix: function(tp , visible){
		var w;
		if( TP.table.offsetWidth < 160 ){			
			w = Math.max ( TP.table.offsetWidth , 130 );	
		}else{
			w = Math.min(TP.table.offsetWidth , 210);
		}	
		tp.style.width = w + 20 + "px";
		TP.table.style.width = "100%";
		if(visible)
			TP.tp.style.visibility = "visible";
			
	},
	move: function(_this,tp){
		var d=document, l, t;
		tp.style.visibility = "visible";
		if(tp.setCapture)
			tp.setCapture();
		else if(window.captureEvents)
			window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
		var evt=getEvent();
		if(document.all){
			l = Get.scrollLeft() + evt.clientX;
			t = Get.scrollTop() + evt.clientY;
		}
		else if(window.captureEvents){
			l = evt.pageX;
			t = evt.pageY;
		}
		TP.afreshPos(tp,l,t,12,12);
		d.onmousemove = function(){
			var evt=getEvent();
    		var _e=evt.srcElement || evt.target;
			if(_e == _this){
				if(document.all){
					l = Get.scrollLeft() + evt.clientX;
					t = Get.scrollTop() + evt.clientY;
				}
				else if(window.captureEvents){
					l = evt.pageX;
					t = evt.pageY;
				}
				TP.afreshPos(tp,l,t,12,12);
			}else{
				if(document.all)
					tp.releaseCapture();
				else if(window.captureEvents)
					window.releaseEvents(Event.MOUSEMOVE|Event.MOUSEUP);
				d.onmousemove = null; 
				TP.hide();
			}
		} // End Document.move
	},
	afreshPos: function(tp,left,top,dw,dh){
		var minx = 0 , miny = 0,
			tow = tp.offsetWidth, toh = tp.offsetHeight,
			bcw = Get.winWidth() , bch = Get.winHeight(),
			bsl = Get.scrollLeft() , bst = Get.scrollTop();
			
		if(left + dw + tow > bcw)
			left = Math.max(left - tow -5, minx);
		else
			left += dw;

		if(left < minx)
			left = minx;
		else if(left + tow > bsl + bcw)
			left = bsl + bcw - tow;	
		
		if(top + toh + dh > bst + bch)
			top -= toh + dh ;
		else
			top += dh;
		
		if(top < miny)
			top = miny;
		else if(top < bst)
			top = bst + miny;
			
		
		tp.style.left = left + "px";
		tp.style.top = top + "px";
		tp.style.visibility = "visible";
	}
}