// Cristian Deschamps cristian.deschamps@nurun.com crisd@sympatico.ca
// (c) Nurun 2003 

// DHTML DOM1 Library: IE, Netscape and Gecko 
// PC and Mac
last = 0
windowwidth = 0;
windowheight = 0;
isgecko = (document.getElementById && !document.all) ? 1 : 0;
ismac = (navigator.appVersion.indexOf("Mac") != -1);
isie = (document.all) ? 1 : 0;
isns4 = (document.layers) ? 1 : 0;


function initlayers()
	{
	if(isie) 		return ie_initlayers();
	else if(isns4)	return ns4_initlayers();
	else if(isgecko)	return gecko_initlayers();
	}
	
function ie_initlayers()
	{
	LA = document.all.tags("DIV");
	for(x=0;x<LA.length;x++)
		{
		LA[x].init = mapping_ie;
		LA[x].init();
		}
	windowwidth = document.body.clientWidth;
	windowheight = document.body.clientHeight;
	return LA.length;
	}

function gecko_initlayers()
	{
	LA = document.getElementsByTagName("DIV");
	for(x=0;x<LA.length;x++)
		{
		if (LA[x].id) {
			eval(LA[x].id + " = LA[x]");
			LA[x].init = mapping_gecko;
			LA[x].init();
		}
		}
	windowwidth = window.innerWidth;
	windowheight = window.innerHeight;
	return LA.length;
	}

layercount = 0;
function ns4_initlayers()
	{
	var x = 0;
	var LA = "";
	if(arguments.length)
		LA = arguments[0];
	else
		LA = document.layers;
	for(x=0;x<LA.length;x++)
		{
		eval(LA[x].name + " = LA[x]");
		LA[x].init = mapping_ns4;
		LA[x].init();
		layercount++;
		if(LA[x].document.layers.length)
		ns4_initlayers(LA[x].document.layers)
		}
	windowwidth = window.innerWidth;
	windowheight = window.innerHeight;
	return layercount;
	}
		
function mapping_ns4()
	{
	this.setx = 			sx_ns4;
	this.setz =				sz_ns4;
	this.sety =				sy_ns4;
	this.setxy = 			sxy_ns4;
	this.getx = 			gx_ns4;
	this.gety = 			gy_ns4;
	this.show = 			sh_ns4;
	this.hide = 			hi_ns4;
	this.setbgcolor = 		sbc_ns4;
	this.getbgcolor = 		gbc_ns4;
	this.setbg = 			sbi_ns4;
	this.getbg = 			gbi_ns4;
	this.getclipleft = 		gcl_ns4;
	this.getclipright = 	gcr_ns4;
	this.getcliptop = 		gct_ns4;
	this.getclipbottom =	gcb_ns4;
	this.setclipleft = 		scl_ns4;
	this.setclipright = 	scr_ns4;
	this.setcliptop = 		sct_ns4;
	this.setclipbottom = 	scb_ns4;
	this.html = 			ht_ns4;
	this.getheight = 		gh_ns4;
	this.getwidth = 		gw_ns4;
	this.setheight = 		sht_ns4;
	this.setwidth = 		swt_ns4;	
	this.childrens =		"";
	if(this.document.layers)
		this.childrens =	this.document.layers;
	}

function mapping_gecko()
	{
	this.setx = 			sx_w3c;
	this.setz =				sz_w3c;
	this.sety =				sy_w3c;
	this.setxy = 			sxy_w3c;
	this.getx = 			gx_ns6;
	this.gety = 			gy_ns6;
	this.show = 			sh_ns6;
	this.hide = 			hi_ns6;
	this.setbgcolor = 		sbc_w3c;
	this.getbgcolor = 		gbc_ns6;
	this.setbg = 			sbi_w3c;
	this.getbg = 			gbi_ns6;
	this.getclipleft = 		gcl_w3c;
	this.getclipright = 	gcr_w3c;
	this.getcliptop = 		gct_w3c;
	this.getclipbottom = 	gcb_w3c;
	this.setclipleft = 		scl_ns6;
	this.setclipright = 	scr_ns6;
	this.setcliptop = 		sct_ns6;
	this.setclipbottom = 	scb_ns6;
	this.getheight = 		gh_ns6;
	this.getwidth = 		gw_ns6;
	this.setheight = 		sht_w3c;
	this.setwidth = 		swt_w3c;	
	this.html = 			ht_ns6ie;
	this.style.clip = 		"rect(auto auto auto auto)"
	this.patch =			patch_ns6;
	this.childrens =		new Array();
	c = 0; nodeList = this.childNodes;
	for(n=0;n<nodeList.length;n++) 
		if(nodeList.item(n).nodeName=="DIV") this.childrens[c++] = nodeList.item(n);
	}

function mapping_ie()
	{
	this.setx = 			sx_w3c;
	this.setz =				sz_w3c;
	this.sety =				sy_w3c;
	this.setxy = 			sxy_w3c;
	this.getx = 			gx_w3c;
	this.gety = 			gy_w3c;
	this.show = 			sh_w3c;
	this.hide = 			hi_w3c;
	this.setbgcolor = 		sbc_w3c;
	this.getbgcolor = 		gbc_w3c;
	this.setbg = 			sbi_w3c;
	this.getbg = 			gbi_w3c;
	this.getclipleft = 		gcl_w3c;
	this.getclipright = 	gcr_w3c;
	this.getcliptop = 		gct_w3c;
	this.getclipbottom = 	gcb_w3c;
	this.setclipleft = 		scl_w3c;
	this.setclipright = 	scr_w3c;
	this.setcliptop = 		sct_w3c;
	this.setclipbottom = 	scb_w3c;
	this.html = 			ht_ns6ie;
	this.getheight = 		gh_ie;
	this.getwidth = 		gw_ie;
	this.setheight = 		sht_w3c;
	this.setwidth = 		swt_w3c;	
	this.style.clip = 		"rect(auto auto auto auto)"
	this.childrens =		new Array();
	c = 0; nodeList = this.all.tags("DIV");
	for(n=0;n<nodeList.length;n++) this.childrens[c++] = nodeList[n];
	}

// Netscape4-only functions ///////////////////////////////////////////////

function sx_ns4(x){
	this.left = x;}
function sy_ns4(y){
	this.top = y;}
function sz_ns4(z){
	this.zIndex = z;}
function sxy_ns4(x,y){
	this.moveTo(x,y);
	if(arguments.length>2) this.zIndex = arguments[2];}

function gx_ns4(){
	return this.left;}
function gy_ns4(){
	return(this.top);}
function getz_ns4(){
	return(this.zIndex);}

function sh_ns4(){
	this.visibility="inherit";}
function hi_ns4(){
	this.visibility="hidden";}

function gh_ns4(){
	return this.document.height;}
function gw_ns4(){
	return this.document.width;}

function ht_ns4(h){
	this.document.open();
	this.document.write(h);
	this.document.close();}

function location_ns4(x){
	this.src = x;}

function sbc_ns4(color){
	this.bgColor = color;}
function sbi_ns4(image){
	this.background.src = image;}

function gbc_ns4(){
	return this.bgColor;}
function gbi_ns4(){
	return this.background.src;}

function sht_ns4(h){
	this.clip.height=parseInt(h);
	//this.clip.height=parseInt(this.clip.height+1);
	//this.clip.height=parseInt(this.clip.height-1);
	}

function swt_ns4(w){
	this.clip.width = parseInt(w);}	
	
function gcl_ns4(){
	return this.clip.left;}
function gcr_ns4(){
	return this.clip.right;}
function gct_ns4(){
	return this.clip.top;}
function gcb_ns4(){
	return this.clip.bottom;}

function scl_ns4(x){
	this.clip.left = x;}
function scr_ns4(x){
	this.clip.right = x;}
function sct_ns4(x){
	this.clip.top = x;}
function scb_ns4(x){
	this.clip.bottom = x;}

// Netscape6-only functions ///////////////////////////////////////////////
function scl_ns6(x){
	setclip(this,0,x);
	this.patch();}
function scr_ns6(r){
	setclip(this,1,r);
	this.patch();}
function sct_ns6(y){
	setclip(this,3,y);
	this.patch();}
function scb_ns6(b){
	setclip(this,2,b);
	this.patch();}

function sh_ns6(){
	this.style.visibility="visible";
	this.patch();}
function hi_ns6(){
	this.style.visibility="hidden";
	this.patch();
	}

function patch_ns6(){
	this.style.left=parseInt(this.style.left)-1;
	this.style.left=parseInt(this.style.left)+1;}

function gh_ns6(){
	st = document.defaultView.getComputedStyle(this,'');
	return (parseInt(st.getPropertyValue("height")));}

function gw_ns6(){
	st = document.defaultView.getComputedStyle(this,'');
	return (parseInt(st.getPropertyValue("width")));}

function gx_ns6(){
	st = document.defaultView.getComputedStyle(this,'');
	return (parseInt(st.getPropertyValue("left")));}
	
function gy_ns6()	{
	st = document.defaultView.getComputedStyle(this,'');
	return (parseInt(st.getPropertyValue("top")));}
	
function getz_ns6()	{
	st = document.defaultView.getComputedStyle(this,'');
	return (parseInt(st.getPropertyValue("zIndex")));}	

function gbc_ns6(){
	st = document.defaultView.getComputedStyle(this,'');
	return st.getPropertyValue("backgroundColor");}

function gbi_ns6(image){
	st = document.defaultView.getComputedStyle(this,'');
	return st.getPropertyValue("backgroundImage");}
	
// W3C compliant functions ////////////////////////////////////////////////

function sx_w3c(x){
	this.style.left = x + "px";}
function sy_w3c(y){
	this.style.top = y + "px";}
function sz_w3c(z){
	this.style.zIndex = z;}
function sxy_w3c(x,y){
	this.style.left = x + "px";
	this.style.top = y + "px";
	if(arguments.length>2) this.style.zIndex = arguments[2];}
	
function gx_w3c(){
	return (parseInt(this.style.left));}
function gy_w3c()	{
	return(parseInt(this.style.top));}
function getz_w3c()	{
	return(parseInt(this.style.zIndex));}

function sh_w3c(){
	this.style.visibility="inherit";}
function hi_w3c(){
	this.style.visibility="hidden";}

function sbc_w3c(c){
	this.style.backgroundColor = c;}
function sbi_w3c(i){
	this.style.backgroundImage = "url(" + i + ")";}

function sht_w3c(h){
	this.style.height = h;}

function swt_w3c(w){
	this.style.width = w;}		
	
function gbc_w3c(){
	return this.style.backgroundColor;}
function gbi_w3c(image){
	return this.style.backgroundImage;}

function gct_w3c(){
	clips = this.style.clip.substring(5,this.style.clip.length-1).split(" ");
	return parseInt(clips[0]);}
function gcr_w3c(){
	clips = this.style.clip.substring(5,this.style.clip.length-1).split(" ");
	return (clips[1]);}
function gcb_w3c(){
	clips = this.style.clip.substring(5,this.style.clip.length-1).split(" ");
	return parseInt(clips[2]);}
function gcl_w3c(){
	clips = this.style.clip.substring(5,this.style.clip.length-1).split(" ");
	return parseInt(clips[3]);}

function scl_w3c(x){
	setclip(this,0,x);}
function scr_w3c(r){
	setclip(this,1,r);}
function sct_w3c(y){
	setclip(this,3,y);}
function scb_w3c(b){
	setclip(this,2,b);}

function setclip(div,side,value)
	{
	if(!div.style.clip) div.style.clip = "rect(auto auto auto auto)"
	clips = div.style.clip.substring(5,div.style.clip.length-1).split(" ");
	clipstr = "";
	for(c=0;c<4;c++){
		if(side!=c)	clipstr += clips[c] + " ";
		else 		clipstr += value + " " ;}
	div.style.clip = "rect(" + clipstr + ")";
	}

// IE-specific functions //////////////////////////////////////////////////
	
function gh_ie(){
	if(ismac) return this.offsetHeight;
	else return this.scrollHeight;}
function gw_ie(){
	if(ismac) return this.offsetWidth;
	else return this.scrollWidth;}

// IE and NS6 specific functions //////////////////////////////////////////////////

function ht_ns6ie(content){
	this.innerHTML = content+"\n";}

// /////////////////////////////////////////////////////////////////////////
window.onresize = window_onresize;
//Initialise the variables for the resize timer.
var ResizeTimerID = 0;
var ResizeTimeout = 500;     //Seconds

function window_onresize() {
	if (ResizeTimerID > 0)	clearTimeout(ResizeTimerID);
	ResizeTimerID = setTimeout('window_resized();',ResizeTimeout);
    }

function window_resized() {
	ResizeTimerID = 0;
	main();
    }
