﻿
function Start(){
	
	if($('D_navStyleCtl')){$('D_navStyleCtl').onclick=SwitchPage}
	window.onresize = BodyAutoHeight;
	BindSlide();
	BodyAutoHeight();
}
function SwitchPage(){
    if($('D_navStyleCtl'))
    {
//	    $('D_navStyleCtl').onclick=function()
//	    {
		    var cel=$('DOM_mainTable').rows[0].cells;
		    if(cel[0].swapNode)
		    cel[0].swapNode(cel[2]);
		    if(this.innerText)
		    this.innerText=(this.innerText.indexOf('右')>0?'导航在左':'导航在右');
		    else
		    this.innerHTML=(this.innerHTML.indexOf('右')>0?'导航在左':'导航在右');
//	    }
    }
}

function BindSlide(){
	var n=500,dragok=false,y,x,d,dy,dx,shadowTimer;
	function move(e){
		e=window.event||e;
		if (dragok){
			var mainstyle=$('main').style;
			try{
				var left=dx+e.clientX-x;
				if (left<160||left>750){
					mainstyle.border='1px dashed #D0D8D9';
					return
				}else{
					mainstyle.border=''
				}
				mainstyle.left=left;
				mainstyle.position="absolute";
				$('chead').style.display='none';
				return false
			}catch(e){}
		}
	}
	function down(e){
		e=window.event||e;
		var obj=e.srcElement||e.target;
		if (obj.nodeName.toLowerCase()!="html"|"body" && obj.className!="dragclass"){obj=obj.parentNode}
		if(obj.nodeName.toLowerCase()=="tr"){
			obj=obj.parentNode;
			obj=obj.parentNode;
			obj=obj.parentNode;
		}
		if (obj.className=="dragclass"){
			dragok=true;
			obj.style.zIndex=n;
			d=obj;
			dx=_getoffset(obj)[1];
			dy=_getoffset(obj)[0];
			x=e.clientX;
			document.onmousemove=move;
			shadowTimer=window.setTimeout(function(){$('DOM_shadow').style.zIndex=100},150);
			return false
		}
	}
	function up(){
		var main=$('main'),chead=$('chead'),lefttd=$('DOM_leftTD'),leftcont=$('DOM_LContent');
		if (dragok){
			window.clearTimeout(shadowTimer);
			$('DOM_shadow').style.zIndex=-10;
			chead.style.display='';
			main.style.height="100%";
			main.style.border='';
			main.style.position="static";
			if (lefttd.style.display=="none"){
				lefttd.style.display="";
				chead.childNodes[0].style.backgroundPositionX='right'
			}
		}
		try{
			lefttd.style.width=leftcont.style.width=parseInt(main.style.left)+"px";
			var banner=window["D_banner1"].document.getElementById('D_banner1');
			if (banner.style.display==""){
				banner.style.left=parseInt($('D_banner1').clientWidth)-20+"px"
			}
		}catch(e){}
		dragok=false;
		document.onmousemove=null;
	}        
	document.onmousedown=down;
	document.onmouseup=up;

	function _getoffset(e){ 
		var t=e.offsetTop,l=e.offsetLeft;
		while(e=e.offsetParent){ 
			t+=e.offsetTop;
			l+=e.offsetLeft 
		}
		return [t,l]
	}
}

function BodyAutoHeight(){
	var ch=document.body.clientHeight;
	$('DOM_LContent').style.height=ch-130;
	$('DOM_mainTable').style.height=ch-60;
}

function ToFresh(){	
    var retUrl = document.frames['LeftFrame'].location.href.replace("#", "");
    document.frames['LeftFrame'].location.href = retUrl;
}


function GetOffset(a){
	if(a.style.display!="none"){
        return {
            'width':a.offsetWidth,
            'height':a.offsetHeight
        }
	}
	var b=a.style,c=b.visibility,d=b.position;
	b.visibility="hidden";
	b.position="absolute";
	b.display="";
	var f=a.offsetWidth,e=a.offsetHeight;
	b.display="none";
	b.position=d;
	b.visibility=c;
	return {
        "width:":f,
        "height:":e
    }
}
function GetPositionOnPage(a){
	var b=GetOwnerDocument(a),c={x:0,y:0},d=GetDocumentElement(b),f=null,e;
	if(a==d){return c}
	if(a.getBoundingClientRect){
		e=a.getBoundingClientRect();
		c.x=e.left+d.scrollLeft;
		c.y=e.top+d.scrollTop
	}
	else{
		c.x=a.offsetLeft;
		c.y=a.offsetTop;
		f=a.offsetParent;
		if(f!=a){
			while(f){
				c.x+=f.offsetLeft;
				c.y+=f.offsetTop;
				f=f.offsetParent
			}
		}
	}
	return c
}
function go(){
	var lefttd=$('DOM_leftTD'),isShow=(lefttd.style.display=="");
	lefttd.style.display=isShow?"none":"";
	$('chead').childNodes[0].style.backgroundPosition=isShow?"left":"right";
}
Start();