/*******************************************************************
	Browser-Independent Layer Handler Version 2.13
	
	©2004-9 A+R Media Studio
	http://www.AandRmediastudio.com
	
	written by Rudy Dominguez (rudy@AandRmediastudio.com)
	
	These scripts are free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
	
*******************************************************************/

var bilh = new BILH();

function BILH(){
	this.ver = navigator.appVersion
	this.dom = (document.getElementById)? 1 : 0
	
	this.ie5 = ((this.ver.indexOf("MSIE 5") >= 0) && this.dom)? 1 : 0;
	this.ie4 = (document.all && !this.dom)? 1 : 0;
    this.ns6 = (this.dom && parseInt(this.ver) >= 6)? 1 : 0;
	this.ns5 = (this.dom && parseInt(this.ver) >= 5)? 1 : 0;
	this.ns4 = (document.layers && !this.dom)? 1 : 0;
		
	this.refs = new Object();
	
	this.useMenu = true;
	this.current = "";
	this.timerID = null;
	this.navImgID = "";
	this.defaultMenu = "";
}

BILH.prototype.register = function() {
	var layerID, i;
	
	if (arguments.length > 0) 
		for (i=0; i < arguments.length; i++) {
			if (typeof (arguments[i]) == "string") {
				layerID = arguments[i];
				this.refs[layerID] = new Object();
				
				this.refs[layerID].name = layerID;
				this.refs[layerID].layer = (this.dom)? document.getElementById(layerID) : (this.ie4)? document.all[layerID] : (this.ns4)?  document[layerID] : 0;
				this.refs[layerID].style = (this.dom)? document.getElementById(layerID).style : (this.ie4)? document.all[layerID].style : (this.ns4)?  document[layerID] : 0;
			}
		}
		
	return;
}

BILH.prototype.isVisible = function(layerID) {
	var flag = false;
	
	if (typeof(this.refs[layerID]) != "undefined") {
		flag = ((this.refs[layerID].style.visibility == ((this.ns4)? "show" : "visible")) && (this.refs[layerID].style.display != "none"));
	}
	
	return flag;
}

BILH.prototype.show = function(layerID, nodisplay) {
	this.ensureRegistration(layerID);
	if (typeof(this.refs[layerID]) != "undefined") {
		this.refs[layerID].style.visibility = (this.ns4)? "show" : "visible";

		if (!nodisplay) this.refs[layerID].style.display = "inline";
		if (this.useMenu) this.current = layerID;
	}
	
	return;
}

BILH.prototype.hide = function(layerID, nodisplay) {
	this.ensureRegistration(layerID);

	if (typeof(this.refs[layerID]) != "undefined") {
		this.refs[layerID].style.visibility = (this.ns4)? "hide" : "hidden";
		if (!nodisplay)  this.refs[layerID].style.display = "none";		
	}
	
	return;
}

BILH.prototype.hideMenu = function(layerID, hideDefault) {
	if (this.useMenu) {
		this.timerID = setTimeout("bilh.hideMenuAll(" + hideDefault + ");", 250);
	}
	
	return;
}

BILH.prototype.hideMenuAll = function(hideDefault) {
	var item;
	
	if (re && (this.navImgID != "")) re.setOff(this.navImgID);
	
	if (this.useMenu) {
		if (typeof(swap) != "undefined") stuntSwap(0); 
		
		for (item in this.refs) {
			//alert(item);
			this.hide(this.refs[item].name);
		}

		if ((this.defaultMenu != "") && !hideDefault) this.show(this.defaultMenu);
	}
	
	return;
}

BILH.prototype.showMenu = function(layerID, navImgID) {
	if (this.useMenu) {
		clearTimeout(this.timerID);
		
		this.hideMenuAll(true);
		if (typeof(swap) != "undefined") stuntSwap(1); 
		
		if ((layerID != "") && (typeof(this.refs[layerID]) != "undefined")) this.show(layerID);
		
		if (re && re.useOnState && (typeof(navImgID) != "undefined")) {
			re.setOn(navImgID);
			this.navImgID = navImgID;
		}

		if (re && re.useOverState && (typeof(navImgID) != "undefined")) {
			re.setOver(navImgID);
			this.navImgID = navImgID;
		}
	}
	
	return;
}

BILH.prototype.getContent = function(layerID) {	
	return (this.refs[layerID].layer.innerHTML)? this.refs[layerID].layer.innerHTML : "";
}

BILH.prototype.setContent = function(layerID, str) {	
	this.ensureRegistration(layerID);
	
	if(document.all) {
		this.refs[layerID].layer.innerHTML = str;
		//eval(this.alias + ".innerHTML = str;");
	} else {	// even if NS 4, store the text as innerHTML for
		// later retrieval by getContent()	
		this.refs[layerID].layer.innerHTML = str;

		if(document.layers) {
			with(this.refs[layerID].layer.document) {
				open();
				write(str);
				close();
			}
		}
	}
}

BILH.prototype.ensureRegistration = function(layerID) {
	if ((typeof(this.refs[layerID]) == "undefined") && (typeof(layerID) == "string")) {
		this.register(layerID);	
	}
}


/* DRAG_N_DROP FUNCTIONALITY 1.0*/
BILH.prototype.layerCount = function() {
	var i = 0;
	
	for (var o in this.refs) {
		i++;	
	}
	
	return i;
}
BILH.prototype.initDrag = function(baseObj) {
	this.bxo = baseObj.offsetLeft;
	this.byo = baseObj.offsetTop;
	var p = baseObj.offsetParent;
	
	while(p) {
		this.bxo += p.offsetLeft;
		this.byo += p.offsetTop;	
		p = p.offsetParent;
	}
}

BILH.prototype.setDragLayer = function(e, baseObj) {
	e = (typeof(event) != "undefined")? event : e;
	
	var mx = e.clientX - this.bxo + ((document.documentElement.scrollLeft)? document.documentElement.scrollLeft : document.body.scrollLeft);
	var my = e.clientY - this.byo + ((document.documentElement.scrollTop)? document.documentElement.scrollTop : document.body.scrollTop);
	var count = 0;// + baseObj.offsetTop
	
	window.status =  document.documentElement.scrollTop + "; mouse: " + mx + ", " + my + "; ";
	
	for (var i in this.refs) {
		count++;
		var xx = parseInt(this.refs[i].layer.offsetLeft);
		var yy = parseInt(this.refs[i].layer.offsetTop);
		
		p = this.refs[i].layer.offsetParent;
		
		while (p && p != baseObj) {
			xx += 	p.offsetLeft;
			yy += 	p.offsetTop;	
			p = p.offsetParent;
		}
	

		//var xx = baseObj.offsetLeft + parseInt(this.refs[i].layer.offsetLeft);
		//var yy = baseObj.offsetTop + parseInt(this.refs[i].layer.offsetTop);
		//window.status += ">: " + + "; ";
		window.status += "layer: " +  xx + "-" + (xx + parseInt(this.refs[i].style.width) + ", " + yy) + "-" + (yy + parseInt(this.refs[i].style.height)) + "; ";	
		if ( (mx > xx) && (mx < xx + parseInt(this.refs[i].style.width)) && (my > yy) && (my < yy + parseInt(this.refs[i].style.height)) ) {
			this.dragLayer = this.refs[i];
			this.dragLayer.style.zIndex = 100;
			this.dragLayer.onSelectStart = function() {
				return false;
			}
			this.dragStart = {x: mx, y: my};
	
			return;
		}

	}
}

BILH.prototype.clearDragLayer = function() {
	if (this.dragLayer != null) {
		this.dragLayer.style.zIndex = 1;
	}
	this.dragLayer = null;
	this.dragging = false;
}

BILH.prototype.moveDragLayer = function(e, baseObj, yOnly) {
	e = (typeof(event) != "undefined")? event : e;
	
	var mx = e.clientX - this.bxo + ((document.documentElement.scrollLeft)? document.documentElement.scrollLeft : document.body.scrollLeft)
	var my = e.clientY - this.byo + ((document.documentElement.scrollTop)? document.documentElement.scrollTop : document.body.scrollTop);
//	window.status = "mouse: " + mx + ", " + my + ";";
	
	if (this.dragLayer != null) {	
		if (!yOnly) {
			var x = mx - this.dragStart.x;
			this.dragLayer.style.left = x;//(x > 0)? x : 0;
		}
		var y = my - this.dragStart.y;
		this.dragLayer.style.top = y;//(y > 0)? y : 0;
		
		this.dragging = true;
		
		window.status = "mouse: " + mx + ", " + my + "; layer: " + this.dragStart.x  + ", " + this.dragStart.y + "; ";	
	} 
}