/*
DynamicLayer Object Library
Revised to support Netscape4, IE4, IE5, and Netscape6 (M16+)
Michael Masumoto
michael@michaelmasumoto.com
On the web at: http://www.michaelmasumoto.com/
   

This is a simplified version of the JavaScript Client Sniffer code 
found at http://developer.nextscape.com/docs/examples/javascript/browser_type.html
*/
function Is() {

    var agt=navigator.userAgent.toLowerCase();
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);

    this.nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1));
    this.nav3 = (this.nav && (this.major == 3));
    this.nav4 = (this.nav && (this.major == 4));
    this.nav4up = (this.nav && (this.major >= 4));
    this.navonly  = (this.nav && ((agt.indexOf(";nav") != -1) || (agt.indexOf("; nav") != -1)));
    this.nav5 = (this.nav && (this.major == 5));
    this.nav5up = (this.nav && (this.major >= 5));

    this.ie   = (agt.indexOf("msie") != -1);
    this.ie3  = (this.ie && (this.major < 4));
    this.ie4  = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.0")==-1) );
    this.ie4up  = (this.ie  && (this.major >= 4));
    this.ie5  = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    this.ie5up  = (this.ie  && !this.ie3 && !this.ie4);

    this.aol   = (agt.indexOf("aol") != -1);
    this.aol3  = (this.aol && this.ie3);
    this.aol4  = (this.aol && this.ie4);

    this.opera = (agt.indexOf("opera") != -1);
    this.webtv = (agt.indexOf("webtv") != -1);

    // *** PLATFORM ***
    this.win = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
    this.mac = (agt.indexOf("mac")!=-1);
};

var is;
var isIE3Mac = false;

if ((navigator.appVersion.indexOf("Mac")!=-1) && (navigator.userAgent.indexOf("MSIE")!=-1) && (parseInt(navigator.appVersion)==3)) {
	isIE3Mac = true;
} else {
	is = new Is();
};

function DynamicLayer() {

	this.css = 0;
	this.ref = 0;
	this.x = 0;
	this.y = 0;
	this.home_x = 0;
	this.home_y = 0;
		
	this.layerID = "";
	this.obj = "";
	this.defaultZindex = 0;
	this.isVisible = false;
	this.initialize = initDynamicLayer;
	this.setZindex = setZindex;
	this.resetZindex = resetZindex;
	this.hide = hideLayer;
	this.show = showLayer;
	this.switchImage = switchImage;
};

DynamicLayer.prototype.moveTo = moveTo;
DynamicLayer.prototype.moveBy = moveBy;
DynamicLayer.prototype.slideTo = dynLayerSlideTo;
DynamicLayer.prototype.slideBy = dynLayerSlideBy;
DynamicLayer.prototype.slide = dynLayerSlide;
DynamicLayer.prototype.write = writeLayer;
 

function initDynamicLayer(xpos, ypos, zpos, myVisible) {
	if (is.nav4) {
	 
		var value = "";
		for (var x=4;x<arguments.length;x++) {
			value += "document." + arguments[x];
			if (x!=arguments.length-1) {
				value += "."; 
			};
		};

		this.css = eval(value);
		this.ref = eval(value);
	
	} else if (is.nav5up) {
		
		this.css = document.getElementById(arguments[arguments.length-1]).style;
		this.ref = document.getElementById(arguments[arguments.length-1]);
	
	} else if (is.ie4up) {
		var cssValue = "document.all." + arguments[arguments.length-1] + ".style";
		var refValue = "document.all." + arguments[arguments.length-1];
		
		this.css = eval(cssValue);	
		this.ref = eval(refValue);
	};
	
	this.css.left = xpos;
	this.x = xpos;
	this.css.top = ypos;
	this.y = ypos;
	this.home_x = xpos;
	this.home_y = ypos;
	
	this.layerID = arguments[arguments.length-1];
	this.obj = this.layerID + "Object";
	eval(this.obj + "=this");
	
	this.css.zIndex = zpos;
	this.defaultZindex = zpos;
	
	if (myVisible) {
		if (is.nav4) {
			this.css.visibility = "show";
		} else {
			this.css.visibility = "visible";
		};
	} else {
		if (is.nav4) {
			this.css.visibility = "hide";
		} else {
			this.css.visibility = "hidden";
		};
	};
	this.isVisible = myVisible;
	
};

function setZindex(zpos) {

	this.css.zIndex = zpos;
};

function resetZindex() {

	this.css.zIndex = this.defaultZindex;
};

function hideLayer() {

	if (is.nav4) {
		this.css.visibility = "hide";
	} else if (is.nav5up || is.ie4up) {
		this.css.visibility = "hidden";
	};
	
	this.isVisible = false;
};

function showLayer() {

	if (is.nav4) {
		this.css.visibility = "show";
	} else if (is.nav5up || is.ie4up) {
		this.css.visibility = "visible";
	};
	
	this.isVisible = true;
};


function moveTo(x,y) {

	this.x = x;
	this.css.left = this.x;
	this.y = y;
	this.css.top = this.y;
};

function moveBy(x,y) {

	this.x += x;
	this.css.left = this.x;
	this.y += y;
	this.css.top = this.y;
};

function dynLayerSlideBy(distx,disty,inc,speed,fn) {
	if (!this.slideActive) {
		var endx = this.x + distx;
		var endy = this.y + disty;
		var num = Math.sqrt(Math.pow(distx,2) + Math.pow(disty,2))/inc;
		var dx = distx/num;
		var dy = disty/num;
		this.slideActive = 1;
		this.slide(dx,dy,endx,endy,speed,fn);
	};
};

function dynLayerSlideTo(endx,endy,inc,speed,fn) {
	if (!this.slideActive) {
		var distx = endx - this.x;
		var disty = endy - this.y;
		var num = Math.sqrt(Math.pow(distx,2) + Math.pow(disty,2))/inc;
		var dx = distx/num;
		var dy = disty/num;
		this.slideActive = 1;
		this.slide(dx,dy,endx,endy,speed,fn);
	};
};

function dynLayerSlide(dx,dy,endx,endy,speed,fn) {
	if (!fn) fn = null;
	if (this.slideActive && (Math.floor(Math.abs(dx))<Math.floor(Math.abs(endx-this.x)) || Math.floor(Math.abs(dy))<Math.floor(Math.abs(endy-this.y)))) {
		this.moveBy(dx,dy);
		setTimeout(this.obj+".slide("+dx+","+dy+","+endx+","+endy+","+speed+",\""+fn+"\")",speed);
	} else {
		this.slideActive = 0;
		this.moveTo(endx,endy);
		eval(fn);
	};
};

function writeLayer(myText) {

	if (is.nav4) {
		this.ref.document.write(myText);
		this.ref.document.close();
	} else if (is.nav5up || is.ie4up) {
		this.ref.innerHTML = myText;
	};
};

function switchImage(myImgName, myImgObj2Switch2) {

	var myIMG = "";
	
	if (is.nav4) {
		myIMG = eval("this.ref.document." + myImgName);
	} else if (is.nav5up) {
		myIMG = document.getElementById(myImgName);
	} else if (is.ie4up) {
		myIMG = eval("document.all." + myImgName);
	};
	
	myIMG.src = myImgObj2Switch2.src;
};
  
  