/**********************************************************************************   
WindowScript 
*   Copyright (C) 2001 <a href="/dhtmlcentral/thomas_brattli.asp">Thomas Brattli</a>
*   This script was released at DHTMLCentral.com
*   Visit for more great scripts!
*   This may be used and changed freely as long as this msg is intact!
*   We will also appreciate any links you could give us.
*
*   Made by <a href="/dhtmlcentral/thomas_brattli.asp">Thomas Brattli</a> 
*********************************************************************************/

/********************************************
* code Mettrofied by alistair@mettro.com.au	*
* all windows now expected to be relative positioning rather than abs
* also resizing/closing etc has been disabled & thus headers & buttons on windows
* 20050610

how to use now 

<script>scroller_start()</script>
some content in here .. can contain html etc etc
<script>var winnum = scroller_end()</script>
the rest of the doc goes here & then call at the end of doc (but before </body>
<script type="text/javascript" defer>
	scroller_init(winnum,0,0,250,300,"red","yellow");
</script>

*********************************************/

var oWin=new Array; oWin.zIndex=10; oWin.dragobj=-1; oWin.resizeobj=-1; oWin.zIndex=100
//Start Variables to set ******************************************************************

var scrollers = 0; // num to keep track of un-init't scrollers
var scroll_increment = 10;	// scroll amount each timeout
var scroll_interval = 30; // timeout
var no_scrollers = true;
var no_scrollers = false; // if no_scrollers then none will be launched .. good for CMS/editing

//oWin.bordercolor="#935591" //Remember that you have to change the images as well if you change this color
//oWin.bgcolor="red" //Default background color
//oWin.bgcoloron="blue"  //The "active" background color
//oWin.bgscroll="#333333" //The background-color for the scroll area"

//oWin.bordercolor="#FF00FF" //Remember that you have to change the images as well if you change this color
//oWin.bgcolor="#999999" //Default background color
//oWin.bgcoloron="blue"  //The "active" background color
//oWin.bgscroll="#FF3300"; // B3CFD4 //The background-color for the scroll area"
oWin.scroll_width = 20;
oWin.tab_height = 5;
oWin.tab_colour = "#FFFFFF";
oWin.tab_padding = 3; 

oWin.bottomh=0 //The height of the bottom "border"
oWin.headh=0 //The height of the head "border"
oWin.bordersize=0 //The left and right bordersize
oWin.scrollw=20 //The width of the scroll area
oWin.scrollimgh=20 //The width of the scroll images
oWin.buttonsw=39 //The width of the buttons image
oWin.resizeh=9 //The width of the resize img
oWin.resizew=13 //The height of the resize img
oWin.defwidth=200 //Default width for the windows if nothing is specified
oWin.defheight=200 //Default height for the windows if nothing is specified
oWin.keepinside=0 //VALUE: 1 || 0



function lib_bwcheck(){ //Browsercheck (needed)
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
	this.ie4=(document.all && !this.dom)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.opera5=this.agent.indexOf("Opera 5")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}
var bw=new lib_bwcheck(); 



function lib_doc_size(){ //Page positions - needed!

	this.x=0;this.x2=bw.ie && document.body.offsetWidth-20||innerWidth||0;
	if(bw.ns6) this.x2-=2
	this.y=0;this.y2=bw.ie && document.body.offsetHeight-5||innerHeight||0;
	if(bw.ns6) this.y2-=4
	if(!this.x2||!this.y2) return message('Document has no width or height') 
	this.x50=this.x2/2;     this.y50=this.y2/2;
	this.x10=(this.x2*10)/100;this.y10=(this.y2*10)/100
	this.ytop=140*100/this.y2
	this.avail=(this.y2*(100-this.ytop))/100
	this.origy=this.y2
	return this;
}
function lib_moveIt(x,y,to_val ){
	//y = Math.max(0, y);
	if (String(to_val).length > 0 && String(to_val)!="undefined"){
		//y = Math.min(to_val, y);
		if (y < to_val){
			y = to_val;	
		}
		if (y > 0){
			y = 0;
		}
	}	
	this.x=x;
	this.y=y; 
	this.css.left=x;
	this.css.top=y
}
function lib_moveBy(x,y, to_val){this.moveIt(this.x+x,this.y+y, to_val)}
function lib_showIt(){this.css.visibility="visible"}
function lib_hideIt(){this.css.visibility="hidden"}
function lib_bg(color){
	if(bw.opera5) this.css.background=color
	else if(bw.dom || bw.ie4) this.css.backgroundColor=color
	else if(bw.ns4) this.css.bgColor=color
}
function lib_clipTo(t,r,b,l,setwidth){ 

	if(t<0)t=0;if(r<0)r=0;if(b<0)b=0;if(b<0)b=0
	this.ct=t; this.cr=r; this.cb=b; this.cl=l
	if(bw.ns4){
		this.css.clip.top=t;this.css.clip.right=r
		this.css.clip.bottom=b;this.css.clip.left=l
	}else if(bw.opera5){this.css.pixelWidth=r; this.css.pixelHeight=b; this.w=r; this.h=b
	}else{
		this.css.clip="rect("+t+","+r+","+b+","+l+")";
		if(setwidth){this.css.width=r; this.css.height=b; this.w=r; this.h=b}
	}
}
function lib_writeIt(text,startHTML,endHTML){
	if(bw.ns4){
		if(!startHTML){startHTML=""; endHTML=""}
		this.ref.open("text/html"); this.ref.write(startHTML+text+endHTML); this.ref.close()
	}else this.evnt.innerHTML=text
}
//Default lib functions
function lib_obj(obj,nest,dnest,ddnest,num){
	if(!bw.bw) return lib_message('Old browser')
	if(!bw.ns4) this.evnt=bw.dom && document.getElementById(obj)||bw.ie4 && document.all[obj]
	else{
		if(ddnest){this.evnt=document[nest].document[dnest].document[ddnest].document[obj]?document[nest].document[dnest].document[ddnest].document[obj]:0;
		}else if(dnest){this.evnt=document[nest].document[dnest].document[obj]?document[nest].document[dnest].document[obj]:0;
		}else if(nest){this.evnt=document[nest].document[obj]?document[nest].document[obj]:0;
		}else{this.evnt=document.layers[obj]?document.layers[obj]:0;}	
	}
	if(!this.evnt) 
	{
		alert('The layer does not exist ('+obj+')');
		return lib_message('The layer does not exist ('+obj+') - Exiting script\n\nIf your using Netscape please check the nesting of your tags!');
	}
	this.css=bw.dom||bw.ie4?this.evnt.style:this.evnt;  
	this.ref=bw.dom||bw.ie4?document:this.css.document;   
	this.moveIt=lib_moveIt; this.moveBy=lib_moveBy; 
	this.showIt=lib_showIt; this.hideIt=lib_hideIt;
	this.bg=lib_bg; this.num=num; this.writeIt=lib_writeIt; 	
	this.clipTo=lib_clipTo;	this.obj = obj + "Object"; 	eval(this.obj + "=this")
	return this
}
/*****************************************************************************
Creating windows
*****************************************************************************/

/* not used anymore .... kept for legacy hacks - Alistair 
function xcreate_window(i,x,y,w,h,bg,bga){
	if(!w) w=oWin.defwidth; if(!h) h=oWin.defheight
	if(!bg) bg=oWin.bgcolor; if(!bga) bga=oWin.bgcoloron
	oWin[i]=new lib_obj('divWin'+i,"","","",i)
	oWin[i].oWindow=new lib_obj('divWindow'+i,'divWin'+i)

	oWin[i].oWindow.moveIt(oWin.bordersize,oWin.headh)
	oWin[i].oText=new lib_obj('divWinText'+i,'divWin'+i,'divWindow'+i)
	oWin[i].oHead=new lib_obj('divWinHead'+i,'divWin'+i)
	oWin[i].oButtons=new lib_obj('divWinButtons'+i,'divWin'+i)
	oWin[i].oResize=new lib_obj('divWinResize'+i,'divWin'+i)
	oWin[i].oHead.evnt.onmouseover=new Function("w_mmover("+i+")")
	oWin[i].oHead.evnt.onmouseout=new Function("w_mmout()")
	if(!bw.ns4) oWin[i].oHead.evnt.ondblclick=new Function("mdblclick(0,"+i+")")

	oWin[i].oResize.evnt.onmouseover=new Function("w_mmover("+i+",1)")
	oWin[i].oResize.evnt.onmouseout=new Function("w_mmout()")	
	if(!bw.ns4){
		oWin[i].oHead.css.cursor="move"; oWin[i].oResize.css.cursor="w-resize"
		oWin[i].oWindow.css.overflow="hidden"; oWin[i].css.overflow="hidden"
		oWin[i].oText.css.overflow="hidden"
	}		
	oWin[i].defbg=bg; oWin[i].defbga=bga	
	oWin[i].bg(oWin.bordercolor); oWin[i].oWindow.bg(oWin[i].defbg)
	oWin[i].oUp=new lib_obj('divWinUp'+i,'divWin'+i); oWin[i].oDown=new lib_obj('divWinDown'+i,'divWin'+i)
	oWin[i].oUp.bg(oWin.bgscroll); oWin[i].oDown.bg(oWin.bgscroll); 
	oWin[i].lastx=x;oWin[i].lasty=y;oWin[i].origw=w; oWin[i].origh=h
	oWin[i].resize=win_resize;	oWin[i].close=win_close; oWin[i].maximize=win_maximize;
	oWin[i].minimize=win_minimize;	oWin[i].regwin=win_regwin; oWin[i].checkscroll=win_checkscroll;
	oWin[i].up=win_up;	oWin[i].down=win_down;	oWin[i].addZ=win_addZ;	oWin[i].state="reg"
	oWin[i].moveIt(x,y); oWin[i].resize(w,h); oWin[i].checkscroll(); 
	if(bw.opera5) setTimeout("oWin["+i+"].resize("+w+","+h+"); oWin["+i+"].showIt()",10)
	else oWin[i].showIt()
}
*/

/*****************************************************************************
Window functions 
*****************************************************************************/
function win_regwin(){
	this.oResize.css.visibility="inherit"
	this.resize(this.origw,this.origh)
	this.moveIt(this.lastx,this.lasty)
	this.state="reg"; this.addZ()
	this.checkscroll()
}

function win_resize(w,h){
	
	if(this.oButtons)
	{
		this.oButtons.moveIt(w-oWin.buttonsw,0); this.oResize.moveIt(w-oWin.resizew,h-oWin.resizeh)
	}
	//this.oWindow.clipTo(0,w-oWin.bordersize*2,h-oWin.bottomh-oWin.headh,0,1);
	this.oWindow.clipTo(0,w,h,0,1);
	//this.oWindow.clipTo(0,w-oWin.bordersize*2,h-oWin.bottomh-oWin.headh,0,1);
	this.clipTo(0,w,h,0,1)
	//if(this.oHead)
	//{
		//this.oHead.clipTo(0,w,oWin.headh,0,1);
		//this.oText.moveIt(2,3)
		this.oText.moveIt(0,0)
	//}
	this.oUp.hideIt(); this.oDown.hideIt()
}
function win_checkscroll(w,h){
	this.oText.height=this.oText.evnt.offsetHeight||this.oText.css.pixelHeight||this.oText.ref.height||0
	w=this.cr; h=this.cb
	if(this.oText.height>h-oWin.bottomh-oWin.headh && this.state!="min"){
		this.oWindow.clipTo(0,w-oWin.scrollw-oWin.bordersize*2,h,0,1); 
		//this.oWindow.clipTo(0,w-oWin.scrollw-oWin.bordersize*2,h-oWin.bottomh-oWin.headh,0,1); 
		this.oUp.moveIt(w-oWin.scrollw,oWin.headh)
		this.oUp.clipTo(0,oWin.scrollw-oWin.bordersize,h-oWin.bottomh-oWin.scrollimgh-oWin.headh,0,1); 
		this.oDown.moveIt(w-oWin.scrollw,h-oWin.bottomh-oWin.scrollimgh)
		this.oDown.clipTo(0,oWin.scrollw-oWin.bordersize,oWin.scrollimgh,0,1); this.oUp.showIt()
		
		var offset_percentage =  this.oText.height
	
		this.oDown.showIt()
		// reset the height
		this.oText.height=this.oText.evnt.offsetHeight||this.oText.css.pixelHeight||this.oText.ref.height||0
	}else{
		this.oUp.hideIt(); this.oDown.hideIt()
		this.oTab.style.display = "none";	
	}
}
var sctim=100;
var winScroll;
function win_up(){

	clearTimeout(sctim);
	var scrollto = this.oWindow.cb-this.oText.height-10;
	if ( winScroll ){
		if(this.oText.y>scrollto ){
		//if(this.oText.y>=this.oWindow.cb-this.oText.height-10 && winScroll){
			this.oText.moveBy(0,-scroll_increment, scrollto); 
					
			setTimeout(this.obj+".up()",scroll_interval)
			var scroll_percentage =Math.abs(Math.round((this.oText.y / scrollto)*100));
			scroll_percentage = Math.max(0, Math.min(100, scroll_percentage));
			this.oTab.scroll_to(scroll_percentage)
			
		} else {
			this.oTab.scroll_to(100)
			this.oText.moveIt(0,scrollto);
		}
	}
	/*else{
		this.oText.moveBy(0,scrollto-this.oText.y);
		window.status='done';
	}*/
}
function win_down(){
	clearTimeout(sctim);
	if (winScroll){
		if(this.oText.y<0 ){
			var scrollto = this.oWindow.cb-this.oText.height-10;
			this.oText.moveBy(0,scroll_increment, scrollto)		
			setTimeout(this.obj+".down()",scroll_interval);
			var scroll_percentage =Math.abs(Math.round((this.oText.y / scrollto)*100));
			scroll_percentage = Math.max(0, Math.min(100, scroll_percentage));
			this.oTab.scroll_to(scroll_percentage);
		} else {
			this.oTab.scroll_to(0);
			this.oText.moveIt(0,0);
		}
	}
	/*else{
		this.oText.moveBy(0,0-this.oText.y)
	}
	window.status = this.oText.y;*/
}
function noScroll(){clearTimeout(sctim);winScroll=false}
function win_addZ(){oWin.zIndex++; this.css.zIndex=oWin.zIndex}

/*****************************************************************************
Adding window to winpage!
*****************************************************************************/
var lastx,lasty,lastw,lasth


function scroller_start()
{
	if(no_scrollers){return false};
	scrollers ++;
	num = scrollers;
	html = '<img id="divDot'+num+'" src="/images/blank-pixel.gif" width="1" height="1" ><div  id="absWin'+num+'" ><div id="divWin'+num+'" class="clWin" style="position:relative ; z-index:2; visibility:hidden; overflow:hidden;" >\n<div id="divWindow'+num+'" class="clWindow" style="position:absolute; overflow:hidden; z-index:15; width:200px ">\n<div id="divWinText'+num+'" class="clText" onClick="window.status=this.offsetHeight;" style="position:absolute; z-index:50;">';
	document.write(html);
	return num;
}

function scroller_end()
{
	if(no_scrollers){return false};
	num = scrollers;
	html = '</div>\n</div>\n<div id="divWinUp'+num+'" class="clUp" style="position:absolute; width:20px; height:9px; z-index:60;  cursor:finger; cursor:pointer;">';
	html = html + '<img style=/"vertical-align:top;/" src="/images/arrow_up.gif" alt="" border="0" onmouseover="winScroll=1; oWin['+num+'].down();"  onmouseout="noScroll()">\n';
	html = html + '</div>\n';
	html = html + '<div id="divTab' +num+'" width="'+String(this.oWin.scroll_width)+'" height="'+String(oWin.tab_height)+'" class="clTab" style="z-index:59; position:absolute; background-color:'+String(oWin.tab_colour )+'; width:'+String(this.oWin.scroll_width)+'px; height :'+String(oWin.tab_height)+'px;" ><img src="/images/blank-pixel.gif" width="'+String(this.oWin.scroll_width)+'" height="'+String(oWin.tab_height)+'" /></div>'
	html = html + '<div id="divWinDown'+num+'" class="clDown" style="position:absolute; width:20px; height:9px; z-index:60;  cursor:finger; cursor:pointer;">';
	html = html + '<img style=/"vertical-align:top;/" src="/images/arrow_down.gif" alt="" border="0" onmouseover="winScroll=1; oWin['+num+'].up();" onmouseout="noScroll()">\n';
	html = html + '</div>\n</div>\n</div>';
	document.write(html);
	return num;
}

function scroller_init(i,w,h){

	// a hack of create_window()
	if(no_scrollers){return false};
	x=y=0;
	if(!w) w=oWin.defwidth; if(!h) h=oWin.defheight
	//if(!bg) bg=oWin.bgcolor; if(!bga) bga=oWin.bgcoloron
	oWin[i]=new lib_obj('divWin'+i,"","","",i)
	oWin[i].oWindow=new lib_obj('divWindow'+i,'divWin'+i)
	
	oWin[i].oWindow.moveIt(oWin.bordersize ,oWin.headh)
	oWin[i].oText=new lib_obj('divWinText'+i,'divWin'+i,'divWindow'+i)
	// :::::::::::::::::::::::::::::: SCROLL TAB
	oWin[i].oTab = e('divTab'+i);
	oWin[i].oTab.scroll_pos = 0;
	oWin[i].oTab.scrollPos = 0
	oWin[i].oTab._width = oWin.scroll_width
	oWin[i].oTab._height = oWin.tab_height;
	oWin[i].oTab.move_to = function(x,y){
		this.style.top = String(y) + "px"; 
		this.style.left = String(x) + "px"; 
	}
	oWin[i].oTab.move_to_y = function(y){
		this.style.top = String(y) + "px"; 
	}
	
	oWin[i].oTab.scroll_to = function(percentage){
		var new_y = Math.round(this.top_y + ((this.y_range / 100) * percentage));
		this.move_to_y(new_y)
	}	
	// :::::::::::::::::::::::::::::
	oWin[i].oTab.top_y =  oWin.scroll_width + oWin.tab_padding;
	oWin[i].oTab.bottom_y =  h - oWin.scroll_width - oWin[i].oTab._height - oWin.tab_padding;
	oWin[i].oTab.y_range = oWin[i].oTab.bottom_y - oWin[i].oTab.top_y
	oWin[i].oTab._x = w-oWin[i].oTab._width;
	oWin[i].oTab.move_to( oWin[i].oTab._x, oWin[i].oTab.top_y);
	
	// :::::::::::::::::::::::::::::
	if(!bw.ns4){
		oWin[i].oWindow.css.overflow="hidden"; 
		oWin[i].css.overflow="hidden"
	}
			
	//oWin[i].defbg=bg; oWin[i].defbga=bga	
	if(oWin.bordercolor)
	{
		oWin[i].bg(oWin.bordercolor);
	}else{
		oWin[i].bg('transparent')
	}
	
	//oWin[i].oWindow.bg(oWin[i].defbg)
	oWin[i].oUp=new lib_obj('divWinUp'+i,'divWin'+i); oWin[i].oDown=new lib_obj('divWinDown'+i,'divWin'+i)
	//oWin[i].oUp.bg(oWin.bgscroll); oWin[i].oDown.bg(oWin.bgscroll); 
	oWin[i].lastx=x;oWin[i].lasty=y;oWin[i].origw=w; oWin[i].origh=h
	oWin[i].resize=win_resize;
	oWin[i].regwin=win_regwin; oWin[i].checkscroll=win_checkscroll;
	oWin[i].up=win_up;	oWin[i].down=win_down;	oWin[i].addZ=win_addZ;	oWin[i].state="reg"
	oWin[i].moveIt(x,y);
	oWin[i].resize(w,h); 
	oWin[i].checkscroll(); 

	// oWin[i].oResize.evnt.onmouseover=new Function("alert('hi thar')")
	// oWin[i].oResize.evnt.onmouseout=new Function("alert('thar hi')")	
	//if(!bw.ns4){
	//	oWin[i].oHead.css.cursor="move"; oWin[i].oResize.css.cursor="w-resize"
	//	oWin[i].oWindow.css.overflow="hidden"; oWin[i].css.overflow="hidden"
	//	oWin[i].oText.css.overflow="hidden"
	//}		
	//oWin[i].defbg=bg; oWin[i].defbga=bga	
	//oWin[i].bg(oWin.bordercolor); oWin[i].oWindow.bg(oWin[i].defbg)
	//oWin[i].oUp=new lib_obj('divWinUp'+i,'divWin'+i); oWin[i].oDown=new lib_obj('divWinDown'+i,'divWin'+i)
	//oWin[i].oUp.bg(oWin.bgscroll); oWin[i].oDown.bg(oWin.bgscroll); 
	//oWin[i].lastx=x;oWin[i].lasty=y;oWin[i].origw=w; oWin[i].origh=h
	//oWin[i].resize=win_resize;	oWin[i].close=win_close; oWin[i].maximize=win_maximize;
	//oWin[i].minimize=win_minimize;	oWin[i].regwin=win_regwin; oWin[i].checkscroll=win_checkscroll;
	//oWin[i].up=win_up;	oWin[i].down=win_down;	oWin[i].addZ=win_addZ;	oWin[i].state="reg"
	//oWin[i].moveIt(x,y); oWin[i].resize(w,h); oWin[i].checkscroll(); 
	//if(bw.opera5) setTimeout("oWin["+i+"].resize("+w+","+h+"); oWin["+i+"].showIt()",10)
	//else oWin[i].showIt()
	initAbsDiv(i);
	if(bw.opera5) {
		setTimeout("oWin["+i+"].resize("+w+","+h+"); oWin["+i+"].showIt()",10);
	} else {
		oWin[i].showIt();
	}
	
	}




function onWindowResized(){
	//	refresh vertical position of scroll windows.
	for (var  k = 1 ; k <oWin.length ; k++){

		var debug =  document.getElementById("celldebug" )?document.getElementById("celldebug"):false;
		var winobj = document.getElementById("divDot" + k )?document.getElementById("divDot" + k):false;
		var absWin = document.getElementById("absWin" + k )?document.getElementById("absWin" + k):false;
		if (winobj && oWin[k] && absWin  ){
			var pos = findPosition(winobj);
			var pos_y =  pos[1];
			absWin.style.top = pos_y + "px";
			
		}
	}
}	



	function findPosition( oLink ) {
	
	  if( oLink.offsetParent ) {
		for( var posX = 0, posY = 0; oLink.offsetParent; oLink = oLink.offsetParent ) {
		  posX += oLink.offsetLeft;
		  posY += oLink.offsetTop;
		}
		return [ posX, posY ];
	  } else {
		return [ oLink.x, oLink.y ];
	  }
	}

function initAbsDiv(k){

	if (this.bw.ie){
			var absWin = document.getElementById("absWin" + k )?document.getElementById("absWin" + k):false;
			if (absWin){
				absWin.style.position = "absolute";
			} 
	} 
	
	return;

// if(bw.ns4||bw.op5||bw.op6){
 //	setTimeout('window.onresize=new Function("onWindowResized()")',50)
 //}else{ 
// 	window.onresize=new Function("onWindowResized()")
 //}

 
}
function initWindowResizeWatcher(){
	if (this.bw.ie){
		window.onresize=new Function("onWindowResized()")
	}
}

initWindowResizeWatcher();

