// dynamic layer constructor, written 2003 by Jan Budar <jan@budar.de>
// Version 1.3
/*
*******************************************************************
*
// build the single objects in the BODY onLoad-Handler with an init-function
// constructor: new dynLayer(id[,properties])
// example:
// function dynLayerInit() {
//    layer1 = new dynLayer('layer1Div','showHide,fill');
// }
//
// id - the div-tags name
// config [optional] - a list of properties (separated by comma) you would like to add to the layer object
// possible properties:
// - showHide - adds the functions .show() and .hide()
// - place - adds the function .place(xPos,yPos) - if one is 'stay' it stays unchanged
// - fill - adds a function .fill(fillstring) for filling the layer
// - imgref - adds an object .imgref reffering to all images within the layer (by .imgref.images)
// - clip - adds a function .clipTo(t,r,b,l) for cliping the layer
// - preload - preloads the active pics !!!only works when preload.js was included before!!!
*/

// detecting the browser
var ie = document.all ? 1 : 0;                              // IE
var ie4 = document.all && !document.getElementById ? 1 : 0; // IE4
var ie5 = document.all && document.getElementById ? 1 : 0;  // IE5+
var ns4 = document.layers ? 1 : 0;                          // NS4
var ns6 = document.getElementById && !document.all ? 1 : 0; // NS6+
var dom = document.getElementById ? 1 : 0;                  // IE5+, NS6+

// constructor for the layer objects
function dynLayer(id)
{
	// basic object items
	if (dom) {
		this.css = document.getElementById(id).style;
		this.obj = document.getElementById(id);
	} else if (ie4) {
		this.css = document.all[id].style;
		this.obj = document.all[id];
	} else if (ns4) {
		this.css = document.layers[id];
		this.obj = document.layers[id];
	} else {
		return false;
	}
	
	// check configuration parameters
	if (dynLayer.arguments.length > 1) {
		config = dynLayer.arguments[1];
	} else {
		config = '';
	}
	if (config == '') return;
	
	// build own method according to configuration parameters
	if (config.indexOf("showHide") > -1) {
		this.show = dynLayerShow;
		this.hide = dynLayerHide;
	}
	if (config.indexOf("place") > -1) {
		this.place = dynLayerPlace;
	}
	if (config.indexOf("fill") > -1) {
		if (dom) { this.conref = document.getElementById(id); }
		else if (ie4) { this.conref = document.all[id]; }
		else if (ns4) { this.conref = document.layers[id].document; }
		this.fill = dynLayerFill;
	}
	if (config.indexOf("imgref") > -1 || config.indexOf("preload") > -1) {
		this.imgref = (ns4) ? document.layers[id].document : document;
	}
	if (config.indexOf("clip") > -1) {
		this.clipTo = dynLayerClipTo;
	}
	if (config.indexOf("preload") > -1) {
		if (ns4) { preloadPics(this.imgref); }
	}
}

function dynLayerShow()
{
	this.css.visibility = (ns4) ? "show" : "visible";
}

function dynLayerHide()
{
	this.css.visibility = (ns4) ? "hide" : "hidden";
}

function dynLayerPlace(xPos,yPos)
{
	if (xPos != 'stay') this.css.left = xPos;
	if (yPos != 'stay') this.css.top = yPos;
}

function dynLayerFill(inhalt)
{
	if (ns4) {
		with(this.conref) {
			open();
			write(inhalt);
			close();
		}
	} else {
		this.conref.innerHTML = "";
		this.conref.innerHTML = "\n" + inhalt + "\n";
	}
}

function dynLayerClipTo(t,r,b,l)
{
	if (ns4) {
		this.css.clip.top = t;
		this.css.clip.right = r;
		this.css.clip.bottom = b;
		this.css.clip.left = l;
	} else {
		this.css.clip = "rect("+t+" "+r+" "+b+" "+l+")";
	}
}
