﻿
var CreateResizeableArea=function(resizeableareaid,splitterid,leftid,rightid,TOCWidthCookieName,TOCIsCollapsedCookieName,IE6Offset){
	this.ResizeableAreaselector="#"+resizeableareaid;
	this.ResizeableArea=jQuery(this.ResizeableAreaselector).get(0);
	this.leftselector="#"+leftid;
	this.leftSection=jQuery(this.leftselector).get(0);
	this.splitterselector="#"+splitterid;
	this.splitter=jQuery(this.splitterselector).get(0);
	this.rightselector="#"+rightid;
	this.rightSection=jQuery(this.rightselector).get(0);
	this.CollapsedCookieName=TOCIsCollapsedCookieName;
	this.WidthCookieName=TOCWidthCookieName;
	this.ie6Offset=IE6Offset;
	this.useParentOffsetHeight=!(this.ResizeableArea.parentNode.offsetHeight==document.documentElement.clientHeight);
	this.minWidth=30;
	this.rightSectionMinWidth=200;
	this.dragging=false;
	this.ToggleEvent=function(iscurrentlyCollapsed){
		if(iscurrentlyCollapsed&&this.leftSection.style.display=="block"||!iscurrentlyCollapsed&&this.leftSection.style.display=="none")
			if(this.ClientCollapseEvents)
				this.ClientCollapseEvents(!iscurrentlyCollapsed)
	};
	this.Redraw=function(width){
		var date=new Date;date.setYear(date.getFullYear()+1);
		if(width<=this.minWidth){
			this.leftSection.style.display="none";
			document.cookie=this.CollapsedCookieName+"=true; expires="+date.toGMTString();+"; path=/";
			this.splitter.style.left="0px"
		}else{
			this.leftSection.style.display="block";
			this.splitter.style.left=width+"px";
			this.leftSection.style.width=width+"px";
			document.cookie=this.CollapsedCookieName+"=false; expires="+date.toGMTString();+"; path=/";
			document.cookie=this.WidthCookieName+"="+width+"; expires="+date.toGMTString();+"; path=/"
		}
		if(jQuery.browser.msie){
			var ver=parseInt(jQuery.browser.version);
			if(ver!=NaN&&ver==6)
				jQuery(window).trigger("resize",this)
		}
	};
	
	this.isCurrentlyCollapsed=function(){
		return jQuery(this.leftselector).css("display")=="none"
	};
	
	this.OpenCollapse=function(open){
		var currentCollapseState=this.isCurrentlyCollapsed();
		if(open!=undefined&&open!=currentCollapseState)
			return;
		if(this.leftSection.style.display=="none")
			this.Redraw(parseInt(jQuery(this.leftselector).width()));
		else 
			this.Redraw(0);
		this.ToggleEvent(currentCollapseState)
	};
	
	this.OnDoubleClick=function(e){e.data.OpenCollapse()};
	
	this.OnKeyPress=function(e){
		if(e.which==116&&e.target.tagName.toLowerCase()!="input"&&e.target.tagName.toLowerCase()!="textarea")
			e.data.OpenCollapse();
			e.cancelBubble=true
	};
	
	this.resizeStart=function(e){
		e.data.dragging=true;
		var i=e.data.GetX(e.data.splitter.parentNode)+e.clientX-e.data.GetX(e.data.splitter);
		e.data.splitter.parentOffsetX=i;
		jQuery(document).bind("mousemove",e.data,e.data.mouseMove);
		jQuery(document).bind("mouseup",e.data,e.data.resizeStop);
		jQuery(document.getElementById("raLeftFrame").contentWindow.document).bind("mousemove",e.data,e.data.mouseMove);
		jQuery(document.getElementById("raLeftFrame").contentWindow.document).bind("mouseup",e.data,e.data.resizeStop);
		jQuery(document.getElementById("raRightFrame").contentWindow.document).bind("mousemove",e.data,e.data.mouseMove);
		jQuery(document.getElementById("raRightFrame").contentWindow.document).bind("mouseup",e.data,e.data.resizeStop);

		document.body.ondrag=function(){
			return !e.data.dragging
		};
		document.body.onselectstart=function(){
			return !e.data.dragging
		};
		return false
	};
	
	this.isInFrame=function(e){
		var d, f;
		if(jQuery.browser.msie){
			d=e.target.document;
		}else{
			d=e.target.ownerDocument;
		}
		f=document.getElementById("raLeftFrame");
		if (d==f.contentWindow.document){
			return f;
		}
		f=document.getElementById("raRightFrame");
		if (d==f.contentWindow.document){
			return f;
		}
		return null;
	};

	this.resizeStop=function(e){
		jQuery(document).unbind("mousemove",e.data.mouseMove);
		jQuery(document).unbind(e);
		jQuery(document.getElementById("raLeftFrame").contentWindow.document).unbind("mousemove",e.data.mouseMove);
		jQuery(document.getElementById("raLeftFrame").contentWindow.document).unbind(e);
		jQuery(document.getElementById("raRightFrame").contentWindow.document).unbind("mousemove",e.data.mouseMove);
		jQuery(document.getElementById("raRightFrame").contentWindow.document).unbind(e);

		var iscurrentlyCollapsed=e.data.leftSection.style.display=="none";
		e.data.Redraw(e.data.splitter.offsetLeft);
		e.data.dragging=false;
		e.data.ToggleEvent(iscurrentlyCollapsed)
	};
	
	this.GetX=function(oElement){
		var x=0;
		while(oElement!=null){
			x+=oElement.offsetLeft;
			oElement=oElement.offsetParent
		}
		return x
	};
	this.mouseMove=function(e){
		var x=0;
		var f=e.data.isInFrame(e);
		if (f){
			x+=e.data.GetX(f);
		}

		x+=e.clientX-e.data.splitter.parentOffsetX;
		if(x<=e.data.minWidth)
			x=0;
		else if(x>=e.data.splitter.parentNode.offsetWidth-e.data.splitter.offsetWidth-e.data.rightSectionMinWidth)
			x=e.data.splitter.parentNode.offsetWidth-e.data.splitter.offsetWidth-e.data.rightSectionMinWidth;
			e.data.splitter.style.left=x+"px";
			return false
	};
	this.IE6Only=function(e){
		while(e.data.rightSection.offsetWidth!=e.data.ResizeableArea.offsetWidth-e.data.splitter.offsetWidth-e.data.leftSection.offsetWidth-6)
			e.data.rightSection.style.width=e.data.ResizeableArea.offsetWidth-e.data.splitter.offsetWidth-e.data.leftSection.offsetWidth-6+"px";
			e.data.ResizeableArea.style.height=document.documentElement.clientHeight-e.data.ie6Offset
	};
	this.IE7Only=function(e){
		if(e.data.useParentOffsetHeight)
			e.data.ResizeableArea.style.height=e.data.ResizeableArea.parentNode.offsetHeight;
		else
			e.data.ResizeableArea.style.height=document.documentElement.clientHeight
	};
	this.InitDisplay=function(){
		this.rightSection.style.width=document.body.clientWidth-4-this.leftSection.offsetWidth-4+"px"
	};

	this.addFrameQuickKey=function(d){
		jQuery(d).bind("keypress",this,this.OnKeyPress);
	}

	jQuery(this.splitterselector).bind("mousedown",this,this.resizeStart);
	jQuery(document).bind("keypress",this,this.OnKeyPress);
	//jQuery(document.getElementById("raLeftFrame").contentWindow.document).bind("keypress",this,this.OnKeyPress);
	//jQuery(document.getElementById("headerFrame").contentWindow.document).bind("keypress",this,this.OnKeyPress);
	jQuery(this.splitterselector).bind("dblclick",this,this.OnDoubleClick);
	if(jQuery.browser.msie){
		var ver=parseInt(jQuery.browser.version);
		if(ver!=NaN&&ver>7)
			return;
		if(ver!=NaN&&ver==6){
			//jQuery(window).bind("resize",this,this.IE6Only);
			//this.InitDisplay()
		}else if(ver!=NaN&&ver>=7)
			jQuery(window).bind("resize",this,this.IE7Only);
		
		jQuery(window).trigger("resize",this)
	}
	return this
}



var myParam = (function(){
	var URLParams = new Object();
	var aParams = document.location.search.substr(1).split("&");
	for (i=0; i<aParams.length; i++){
		var aParam = aParams[i].split("=");
		URLParams[aParam[0]] = aParam[1];
	}

	var _GetPValue = function(s_Key, s_Default){
		return (URLParams[s_Key]) ? URLParams[s_Key] : s_Default;
	}

	return {
		Page : _GetPValue("page", "")
	};

})();


window.onload=function(){
	if (myParam.Page){
		document.getElementById("raRightFrame").contentWindow.location.href=myParam.Page;
	}
}

