/*

bravomedialayer.js
Javascript Source for a object oriented approach to cross-browser
dhtml scripting

Developed by Daniel Croona for Bravo Media, 	2002-10-24

*/

ns4 = document.layers?true:false;
ns5 = (document.getElementById && !document.all)?true:false;
ie5 = document.all?true:false;
ie4 = (!document.getElementById && document.all)?true:false;

function bmlayer( layerName ) {

	//Create an object reference
	if (document.getElementById)	
		{
		this.styleRef = document.getElementById(layerName).style ;
		this.layRef = document.getElementById(layerName);
		}
	else if (document.layers)
		{
		this.styleRef = document.layers[layerName];
		this.layRef = this.styleRef;
		}
	else if (document.all)
		{
		this.styleRef = document.all[layerName].style ;	
		this.layRef = document.all[layerName];
		}
	// setting variables
	this.objLayName=layerName;
	
	
	
	//this object has a few functions, that is used internally
	//they are mapped here
	this.setTop = setTop;
	this.getTop = getTop;
	this.setLeft= setLeft;
	this.getLeft= getLeft;
	this.getRight=getRight;
	this.getWidth=getWidth;
	this.setWidth=setWidth;
	this.getHeight=getHeight;
	this.setHeight=setHeight;
	this.getBottom=getBottom;
	this.moveTo = moveTo;
	this.moveBy	= moveBy;
	this.hide = hide;
	this.show = show;
   	this.setVisibility= setVisibility;
   	this.isVisible= isVisible;
   	this.write=write;
   	this.setZIndex = setZIndex;
	this.getZIndex = getZIndex;

}


function setTop(t)	{
	this.styleRef.top = t;
}

function getTop() {
	return parseInt(this.styleRef.top);
}

function setLeft(l)	{
	this.styleRef.left = l;
}

function getLeft() {
	return parseInt(this.styleRef.left);
}

function getRight()	{
	return getLeft() + getWidth();
}

function getWidth()	{

	if (document.layers) {
		if (this.styleRef.document.width)
			return(this.styleRef.document.width);
		else
			return(this.styleRef.clip.right - this.styleRef.clip.left);
	}
	else if (document.all) {
		if (this.styleRef.pixelWidth)
			return(this.styleRef.pixelWidth);
		else
			return(document.all[this.objLayName].clientWidth);
	}	
	else if (document.getElementById) {
      return parseInt(this.layRef.offsetWidth);
	}
	else
		return false;

}

function setWidth(wi) {

	if (document.layers) {
		this.styleRef.resizeTo(wi,this.getHeight());
	}
	else if (document.all) {
      this.layRef.offsetWidth= wi;
      //this.styleRef.width = wi;
    }	
	else if (document.getElementById) {
		this.styleRef.width = wi;
	}
	else
		return false; 

}


function getHeight() {

	if (document.layers) {
		if (this.styleRef.document.height)
			return(this.styleRef.document.height);
		else
			return(this.styleRef.clip.bottom - this.styleRef.clip.top);
	}
	else if (document.all) {
		if (false && this.styleRef.pixelHeight)
			return(this.styleRef.pixelHeight);
		else
			return(document.all[this.objLayName].clientHeight);
	}
	else if (document.getElementById) {
		return(parseInt(this.layRef.offsetHeight));
	}
	else
		return false;
}


function setHeight( h ) {

	if (document.layers) {
		if (this.styleRef.document.height)
			this.styleRef.document.height = h;
		else
			this.styleRef.clip.bottom = (this.styleRef.clip.top + h);
	}
	else if (document.all) {
		if (false && this.styleRef.pixelHeight)
			this.styleRef.pixelHeight = h;
		else
			document.all[this.objLayName].clientHeight = h;
	}
	else if (document.getElementById) {
		this.layRef.offsetHeight = h;
	}
	else
		return false;
}



function getBottom() {
	return getTop()+getHeight();
}

function moveTo(l,t)
	{
	if(document.layers)
		this.styleRef.moveTo(l,t);
	else
		{
		this.styleRef.left = l;
		this.styleRef.top = t;
		}
	}

function moveBy(l,t)
	{
	if(document.layers)
		this.styleRef.moveBy(l,t);
	else
		{
		this.styleRef.left += l;
		this.styleRef.top += t;
		}
	}

function setVisibility(v) {	

   if(v=="hidden" || v=="hide") {
		NSvis="hide";
		IEvis="hidden";
	}
	else {
		NSvis="show";
		IEvis="visible";
	}

	if (document.getElementById)	
		this.styleRef.visibility = IEvis;
	
	else if (document.layers)
		this.styleRef.visibility = NSvis ;

	else if (document.all)
		this.styleRef.visibility = IEvis;	
	else
		return false;

}

function isVisible() {

	if (document.getElementById) {
		if(this.styleRef.visibility == "hidden")
			return false;
		else 
			return true;
	}
	else if (document.layers) {
		if(this.styleRef.visibility == "hide")
			return false;
		else 
			return true;
	}
	else if (document.all) {
		if(this.styleRef.visibility == "hidden")
			return false;
		else 
			return true;
	}

}

function hide()	{
	this.setVisibility("hidden");
}

function show()	{
	this.setVisibility("visible");
}

function write(theText) {

	if (document.layers)
		{
		this.styleRef.document.write(theText);
		this.styleRef.document.close();
		}
	else if (document.all)
		document.all[this.objLayName].innerHTML =theText;
	else if(document.getElementById)
		document.getElementById(this.objLayName).innerHTML =theText;
	else
		return false;

}

function getZIndex() {
	return this.styleRef.zIndex;
}

function setZIndex(z) {
	this.styleRef.zIndex=z;
}


function getViewportWidth() {
  var width = 0;
  if( document.documentElement &&  document.documentElement.clientWidth ) {
    width = document.documentElement.clientWidth;
  }
  else if( document.body && document.body.clientWidth ) {
    width = document.body.clientWidth;
  }
  else if( window.innerWidth ) {
    width = window.innerWidth - 18;
  }
  return width;
}

function getViewportHeight() {
  var height = 0;
  if( document.documentElement &&  document.documentElement.clientHeight ) {
    height = document.documentElement.clientHeight;
  }
  else if( document.body && document.body.clientHeight ) {
    height = document.body.clientHeight;
  }
  else if( window.innerHeight ) {
    height = window.innerHeight - 18;
  }
  return height;
}
