/********************************************************
Copyright (C) 2000 Michael Heuser / Firmamentet A/S

Design and code by Michael Heuser
Testting is made with and by Firmamentet A/S

Date ->
	30/04	2000 - Layers up and running
	07/05	2000 - Scroll functions add
	24/11	2000 - Netscape 6 Support added
********************************************************/


//Layer class function
//
function objLayer(obj, nest) {
        nest=(!nest)? '':'document.' +nest +'.';
        this.obj=bw.dom? document.getElementById(obj):bw.ie4? document.all[obj]: bw.ns? eval(nest +'document.' +obj):0;
        this.css=bw.dom? this.obj.style:bw.ie4? document.all[obj].style: bw.ns? eval(nest+"document.layers." +obj):0;

        this.x	= parseInt(this.css.left);	// Get layer position
        this.y	= parseInt(this.css.top);

        //Original height is not change by the clip function.
		this.height_org		=bw.ie || bw.dom?this.obj.offsetHeight:this.css.clip.height;
		this.width_org		=bw.ie || bw.dom?this.obj.offsetWidth:this.css.clip.width;
		//Visual height and width is change by the clip function.
		this.height			= this.height_org;
		this.width 			= this.width_org;

		this.visible		= '?';		// Visible is set true/false by show/hide.

        this.name			= obj;
        this.scroll_x		= 0;
        this.scroll_y		= 0;
        this.scrolling		= false;	// In the scrolling process = true
        this.scrolling_x	= 0;		//
        this.scrolling_y	= 0;		//
        this.scroll_delay	= 10;		// Delay for autoscroll funktion
        this.scroll_step	= 1;		// Steps for autoscroll funktion

		// Functions...
		this.hide			= oLayerHide;
		this.show			= oLayerShow;
		this.zIndex			= oLayer_zIndex;
		this.move			= oLayerMove;
		this.move2center	= oLayerMove2Center
		this.clip			= oLayerClip;
		this.scrollx		= oLayerScrollX;
		this.scrolly		= oLayerScrollY;
		this.autoscroll		= oLayerAutoScroll;
		this.setheight		= oLayerHeight;
		this.setwidth		= oLayerWidth;
		this.write			= oLayerWrite;

        return this;
}

//Layer functions...
//Show layer.
function oLayerShow()    {this.css.visibility="visible"; this.visible=true}

//Layer functions...
//Hide layer.
function oLayerHide()    {this.css.visibility="hidden";  this.visible=false}

//Layer functions...
//Set index of layer.
function oLayer_zIndex(z) {this.css.zIndex=z;}

//Layer functions...
//Move layer.
function oLayerMove(x,y) {this.x=x; this.y=y; this.css.left=x -this.scroll_x; this.css.top=y -this.scroll_y}

//Layer functions...
//Set visible area on layer.
function oLayerClip(x1,y1,x2,y2) {
	if (bw.dom || bw.ie4) {
		this.css.clip="rect("+y1+","+x2+","+y2+","+x1+")";
	} else if(bw.ns4) {
		this.css.clip.left=x1;
		this.css.clip.top=y1;
		this.css.clip.right=x2;
		this.css.clip.bottom=y2;
	}
}

//Layer functions...
//Scroll visible area on layer.
function oLayerScrollY(i) {
	// Er i defineret ?
	if (typeof(i) != 'undefined') {
		// Sikre at indhold IKKE scrolles ud over rammerne paa laget. 
		if (i > (this.height_org -this.height)) { i = this.height_org -this.height; }
		if (i < 0) { i = 0 }

		// Scroll variabel opdateres
		this.scrolling_y = i;

		if (!this.scrolling) this.autoscroll();
	}
}

//Layer functions...
//Scroll visible area on layer.
function oLayerScrollX(i) {
	// Er i defineret ?
	if (typeof(i) != 'undefined') {
		// Sikre at indhold IKKE scrolles ud over rammerne paa laget. 
		if (i > (this.width_org -this.width)) { i = this.width_org -this.width; }
		if (i < 0) { i = 0 }

		// Scroll variabel opdateres
		this.scrolling_x = i;
		if (!this.scrolling) this.autoscroll();
	}
}

//Layer functions...
//Scroll visible area on layer.
function oLayerAutoScroll() {
	move = false;

	// Skal der fortsat scrolles ?
	if (this.scrolling_y != this.scroll_y) {
		// Opdater scroll variabel og sikre at den ikke bliver for stor/lille
		if (this.scrolling_y > this.scroll_y) {
			this.scroll_y += this.scroll_step;
			if (this.scrolling_y < this.scroll_y) this.scroll_y = this.scrolling_y;  //if to big.
		}
		if (this.scrolling_y < this.scroll_y) {
			this.scroll_y -= this.scroll_step;
			if (this.scrolling_y > this.scroll_y) this.scroll_y = this.scrolling_y;  //if to small.
		}
		move = true;
	}
	if (this.scrolling_x != this.scroll_x) {
		// Opdater scroll variabel og sikre at den ikke bliver for stor/lille
		if (this.scrolling_x > this.scroll_x) {
			this.scroll_x += this.scroll_step;
			if (this.scrolling_x < this.scroll_x) this.scroll_x = this.scrolling_x;  //if to big.
		}
		if (this.scrolling_x < this.scroll_x) {
			this.scroll_x -= this.scroll_step;
			if (this.scrolling_x > this.scroll_x) this.scroll_x = this.scrolling_x;  //if to small.
		}
		move = true;
	}

	if (move) {
		this.scrolling = true;	// Scroling in process.

		this.clip(this.scroll_x, this.scroll_y, this.width +this.scroll_x, this.height +this.scroll_y);
		this.move(this.x, this.y);
		
		// Hvis ikke dummy funktion er oprette saa opret den.
		// Bruges fordi "this" ikke kan bruges udenfor den udfoerte funktion og
		// setTimeout udfoeres foerst efter at funktionen er afsluttet.
		if (eval("window.dummy_" +this.name +"==null")) {
			eval("window.dummy_" +this.name +" = new Function");
			eval("window.dummy_" +this.name +" = this");
		}

		// Kald dummy funktion efter et delay fastsat af "scroll_delay"
		setTimeout("window.dummy_" +this.name +".autoscroll()", this.scroll_delay);
	} else {
		this.scrolling = false;	// Scroling not in process.
	}
}
//Layer functions...
//Scroll visible area on layer.
function oLayerWidth(width) {
	if (typeof(width) == 'undefined') this.width = this.width_org;
	else this.width = width;

	this.clip(0, this.scroll_y, this.width, this.height +this.scroll_y);
}

//Layer functions...
//Scroll visible area on layer.
function oLayerHeight(height) {
	if (typeof(height) == 'undefined') this.height = this.height_org;
	else this.height = height;

	this.clip(this.scroll_x, 0, this.width +this.scroll_x, this.height)
}

//Layer functions...
//Set contens of the layer.
function oLayerWrite(htmlText) {
	 if (bw.dom || bw.ie4) { // Internet Explorer 4+ & Netscape 6
		this.obj.innerHTML = htmlText;
	} else if (bw.ns) { // Netscape 4.x
		this.obj.document.open();
		this.obj.document.write(htmlText);
		this.obj.document.close();
	} 


	//Get the new Height & Width.
	this.height_org		=bw.ie || bw.dom?this.obj.offsetHeight:this.css.clip.height;
	this.width_org		=bw.ie || bw.dom?this.obj.offsetWidth:this.css.clip.width;

	this.height=this.height_org;
	this.width =this.width_org;
}

//Layer functions...
//Move the layer to the screen center.
function oLayerMove2Center() {
	pagewidth  = bw.ns? window.innerWidth:bw.ie? document.body.offsetWidth:1;
	pageheight = bw.ns? window.innerHeight:bw.ie? document.body.clientHeight:1;

	this.move((pagewidth/2) -(this.width/2), (pageheight/2) -(this.height/2));
}
