// JScript 文件
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;}

	//  获取文档信息
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?document.documentElement.scrollTop:document.body.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;
}

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;
}

function getEventSrcElement(){
    return getEvent().srcElement||getEvent().target;
}

	//遮罩层的创建
function createMask(zindex){
	removeMask();
	var mask=document.createElement("div");
	var windowWidth = document.body.scrollWidth+20;
	var windowHeight = Math.max(document.body.scrollHeight,document.documentElement.clientHeight)+20;
	mask.setAttribute("id","layerMask");
	mask.style.cssText="position:absolute;left:0px; top:0px;z-index:"+zindex+";background:#333; width:"+windowWidth+"px;height:"+windowHeight+"px;filter:alpha(opacity=35); -moz-opacity:0.35; opacity:0.35;";
	//mask.innerHTML = "<iframe id='coverFrame' src='javascript:false;' scrolling='no' frameborder='0' style='z-index:-1;position:absolute;background-color:#000;filter:alpha(Opacity=35);opacity: 0.05; top:0px; left:0px;width:100%;height:"+windowHeight+"px;'></iframe>";
	document.body.appendChild(mask);
	//
	window.onresize=function(){
		var windowWidth = document.body.scrollWidth ;
		var windowHeight = document.documentElement.scrollHeight;
		var lm=ge("layerMask");
		if(lm){
			lm.style.width=windowWidth+20+"px";
			lm.style.height=windowHeight+20+"px";
		}
	}
}
	//遮罩层的移除
function removeMask(){
	var lm=ge("layerMask");
	if(lm!=null) lm.parentNode.removeChild(lm);
}

function showMsg(divId){createMask();var o=ge(divId);o.style.display="";vertical(o);}

function closeMsg(divId){removeMask();ge(divId).style.display="none";}

function vertical(o){
    var wh = Get.winHeight(),
        st = Get.scrollTop(),
        dh = Get.docHeight();
    o.style.top = (wh-o.offsetHeight)/2+st;        
}








//Index商品说明显示
var layout_shopBox;
function IndexShop(name,type,price,remark){
	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;	    
	}
	var HTML = "<p class='tag'>"+name+"</p><p><a class='tit'>类型:</a>"+type+"</p><p><a class='tit'>价格:</a>"+price+"点数</p><p><a class='tit'>道具简介:</a>"+remark+"</p>";
	gE(layout_shopBox,"div")[0].innerHTML = HTML;
	TP.show(_e,HTML,0,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";
	}
}