////////////////////////////////////////////////////////////////////////////////////////////////
//
//		DHTML LIB 2001
//	
//		(C) 2001 Mart Karu <karu@metal.ee>
//
////////////////////////////////////////////////////////////////////////////////////////////////

var WIN = ( navigator.userAgent.indexOf("Win") >= 0 );
var MAC = ( navigator.userAgent.indexOf("Mac") >= 0 );

var BROWSER;
	if ( navigator.appName == "Netscape" ) BROWSER = "NS";
	else if ( navigator.appName == "Microsoft Internet Explorer" ) BROWSER = "IE";
	else BROWSER = navigator.appName;

var VERSION = navigator.appVersion;
var VERSION_INT = parseInt(VERSION);
var VERSION_FLOAT = parseFloat(VERSION);

var NS = 		( BROWSER == "NS" && VERSION_INT >= 4 );
var IE = 		( BROWSER == "IE" && VERSION_INT >= 4 );

var IE4 = 		( VERSION.indexOf( "MSIE 4" ) > 0 );
var IE45 = 		( VERSION.indexOf( "MSIE 4.5" ) > 0 );
var IE5 = 		( VERSION.indexOf( "MSIE 5" ) > 0 );
var NS4 = 		( BROWSER == "NS" && VERSION_INT == 4 );
var NS405 = 	( BROWSER == "NS" && ( (VERSION_FLOAT == 4.05 ) || ( VERSION_FLOAT == 4.06 ) ) );
var NS5 = 		( BROWSER == "NS" && VERSION_INT == 5 );

////////////////////////////////////////////////////////////////////////////////////////////////
//
//		BOX
//
////////////////////////////////////////////////////////////////////////////////////////////////

function box( name, inPath, x, y, objName ) {

	this.rectname = name;
	this.path = (inPath)?inPath:document;
	this.objName = objName;

	this.getLayer = getLayer;
	this.obj = this.getLayer();
	
	this.hide = hideRect;
	this.show  = showRect;
	this.move = moveRect;
	this.shift = shiftRect;
	this.stretch = stretchRect;
	this.stretchBy = stretchRectBy;
	this.getLeft = getLeft;
	this.getRight = getRight;
	this.getTop =	getTop;
	this.getBottom = getBottom;
	this.getWidth = getWidth;
	this.getHeight = getHeight;
	this.getZ = getZ;
	this.setZ = setZ;
	this.isVisible = isVisible;
	this.clipLayer = clipLayer;
	this.getClipLeft = getClipLeft;
	this.getClipTop = getClipTop;
	this.getClipRight = getClipRight;
	this.getClipBottom = getClipBottom;
	this.getClipWidth = getClipWidth;
	this.getClipHeight = getClipHeight;
	this.IEClip = IEClip;
	this.scrollLayerTo = scrollLayerTo;
	this.scrollLayerBy = scrollLayerBy;
	this.setBgColor = setBgColor;
	this.setBgImage = setBgImage;
	
	this.slideN = slideNorth;
	this.slideS = slideSouth;
	this.slideW = slideWest;
	this.slideE = slideEast;
	
	this.stretchV = stretchV;
	
	this.alpha = setAlpha;

	if( x && y ) this.move(x,y);
	
}

function getLayer( ) {
	if (NS) return findLayer(this.rectname, this.path);
	if (IE) return eval('document.all.' + this.rectname);
	return null;
}

function findLayer(name, doc) {
	var i, layer;
	for (i = 0; i < doc.layers.length; i++) {
		layer = doc.layers[i];
		if (layer.name == name) return layer;
		if (layer.document.layers.length > 0) {
			layer = findLayer(name, layer.document);
			if (layer != null) return layer;
		}
	}
	return null
}

function isVisible() {
	if (IE) return this.obj.style.visibility == "visible";
	if (NS) return this.obj.visibility == "show";
}

function hideRect() {
	if (IE) this.obj.style.visibility = "hidden";
	if (NS) this.obj.visibility = "hide";
}

function showRect() {
	if (IE) this.obj.style.visibility = "visible";
	if (NS) this.obj.visibility = "show";
}

function moveRect(x, y) {
	if (NS) this.obj.moveTo(x, y);
	if (IE) {
		this.obj.style.left = x;
		this.obj.style.top  = y;
	}
}

function shiftRect(x, y) {
	if (NS) this.obj.moveBy(x, y);
	if (IE) {
		this.obj.style.pixelLeft += x;
		this.obj.style.pixelTop += y;
	}
}

function stretchRect(x, y) {
	if (NS) this.obj.resizeTo(x,y);
	if (IE) {
		this.obj.style.pixelWidth = x;
		this.obj.style.pixelHeight = y;
		
	}
}

function stretchRectBy(dx, dy) {

	this.stretch(this.getWidth() + dx, this.getHeight() + dy);
}

function getLeft() {
	if (IE) return(this.obj.style.pixelLeft)
	if (NS) return(this.obj.left)
}

function getRight() {
	if (IE) return(this.obj.style.pixelLeft + this.getWidth())
	if (NS) return(this.obj.left + this.getWidth())
}

function getTop() {
	if (IE) return(this.obj.style.pixelTop)
	if (NS) return(this.obj.top)
}

function getBottom() {
	if (IE) return(this.obj.style.pixelTop + this.getHeight() )
	if (NS) return(this.obj.top + this.getHeight() )
}

function getWidth() {
	if (NS) {
		if (this.obj.document.width) return this.obj.document.width;
		else return(this.obj.clip.right - this.obj.clip.left);
	}
  	if (IE) {
		if (this.obj.style.pixelWidth) return(this.obj.style.pixelWidth);
		else return(this.obj.clientWidth);
	}
}

function getHeight() {
	if (NS) {
		if (this.obj.document.height) return (this.obj.document.height);
		else return(this.obj.clip.bottom - this.obj.clip.top);
	}
	if (IE) {
		if (this.obj.style.pixelHeight) return(this.obj.style.pixelHeight);
		else return(this.obj.clientHeight);
	}
}

function getZ() {
	if (NS) return(this.obj.zIndex);
	if (IE) return(this.obj.style.zIndex);
}

function setZ(z) {
	if (NS) this.obj.zIndex = z;
	if (IE) this.obj.style.zIndex = z;
}





// Clip
function clipLayer(clipl, clipt, clipr, clipb) {
	if (NS) {
		this.obj.clip.left   = clipl;
		this.obj.clip.top    = clipt;
		this.obj.clip.right  = clipr;
		this.obj.clip.bottom = clipb;
	}
	if (IE) this.obj.style.clip = 'rect(' + clipt + ' ' +  clipr + ' ' + clipb + ' ' + clipl +')';
}

function getClipLeft() {
	if (NS) return(this.obj.clip.left);
	if (IE) {
		if (!this.obj.style.clip) return(0);
		var c = IEClip(this.obj.style.clip);
		return(c[3]);
	}
}

function getClipTop() {
	if (NS) return(this.obj.clip.top);
	if (IE) {
		if (!this.obj.style.clip) return(0);
		c = IEClip(this.obj.style.clip);
		return(c[0]);
	}
}

function getClipRight() {
	if (NS) return(this.obj.clip.right);
	if (IE) {
		if (!this.obj.style.clip) return(this.obj.style.pixelWidth);
		c = IEClip(this.obj.style.clip);
		return(c[1]);
	}
}

function getClipBottom() {
	if (NS) return(this.obj.clip.bottom);
	if (IE) {
		if (!this.obj.style.clip) return(this.obj.style.pixelHeight);
		c = IEClip(this.obj.style.clip);
		return(c[2]);
	}
}

function getClipWidth() {
	if (NS) return(this.obj.clip.right);
	if (IE) {
		if (!this.obj.style.clip) return(this.obj.style.pixelWidth);
		c = IEClip(this.obj.style.clip);
		return(c[1] - c[3]);
	}
}

function getClipHeight() {
	if (NS) return(this.obj.clip.bottom);
	if (IE) {
		if (!this.obj.style.clip) return(this.obj.style.pixelHeight);
		c = IEClip(this.obj.style.clip);
		return(c[2] - c[0]);
	}
}

function IEClip(str) {
	var c = new Array();
	var i; 
	i = str.indexOf("(");        c[0] = parseInt(str.substring(i + 1, str.length), 10);
	i = str.indexOf(" ", i + 1); c[1] = parseInt(str.substring(i + 1, str.length), 10);
	i = str.indexOf(" ", i + 1); c[2] = parseInt(str.substring(i + 1, str.length), 10);
	i = str.indexOf(" ", i + 1); c[3] = parseInt(str.substring(i + 1, str.length), 10);
	return(c);
}

// Scroll
function scrollLayerTo(x, y, bound) {

	var dx = this.getClipLeft() - x;
	var dy = this.getClipTop() - y;
	this.scrollLayerBy(-dx, -dy, bound);
}

function scrollLayerBy(dx, dy, bound) {
	var cl = this.getClipLeft();
	var ct = this.getClipTop();
	var cr = this.getClipRight();
	var cb = this.getClipBottom();
	if (bound) {
		if (cl + dx < 0) dx = -cl;
		else if (cr + dx > this.getWidth()) dx = this.getWidth() - cr;
		if (ct + dy < 0) dy = -ct;
		else if (cb + dy > this.getHeight()) dy = this.getHeight() - cb;
	}
  this.clipLayer(cl + dx, ct + dy, cr + dx, cb + dy);
  this.shift(-dx, -dy);
}

function setBgColor(color) {
	if (NS) this.obj.bgColor = color;
	if (IE) this.obj.style.backgroundColor = color;
}

function setBgImage(src) {
	if (NS) this.obj.background.src = src;
	if (IE) this.obj.style.backgroundImage = "url(" + src + ")";
}


function slideNorth(toY, step, timeOut) {

	var i;

	
	if (this.getTop() > toY)
	{
		if (this.getTop() -step < toY) step = this.getTop() - toY
		this.shift(0, -step);
		setTimeout(this.objName + ".slideN("+toY+","+step+","+timeOut+")", timeOut);
	}
	
}

function slideSouth(toY, step, timeOut) {

	var i;

	if (this.getTop() < toY)
	{
		if (this.getTop()  + step > toY) step = toY -  this.getTop()
		this.shift(0, step);
		setTimeout(this.objName + ".slideS("+toY+","+step+","+timeOut+")", timeOut);
	}
	
}


function slideWest(toX, step, timeOut) {

	var i;

	if (this.getLeft() > toX)
	{
		if (this.getLeft() -step < toX) step = this.getLeft() - toX
		this.shift(-step, 0);
		setTimeout(this.objName + ".slideW("+toX+","+step+","+timeOut+")", timeOut);
	}	
	
}

function slideEast(toX, step, timeOut) {

	var i;

	if (this.getLeft() < toX)
	{
		if (this.getLeft() +step > toX) step = toX - this.getLeft();
		this.shift(step, 0);
		setTimeout(this.objName + ".slideE("+toX+","+step+","+timeOut+")", timeOut);
	}	
	
}

function stretchV(toSize, step, timeOut)
{
	var i;

	if (this.getHeight() < toSize)
	{
		if (this.getHeight() +step > toSize) step = toSize - this.getHeight();
		this.stretchBy(0,step);
		setTimeout(this.objName + ".stretchV("+toSize+","+step+","+timeOut+")", timeOut);
	}	
	
}

function setAlpha(num)
{
	if(IE) this.obj.style.filter = "alpha(opacity=" + num + ")";
}




////////////////////////////////////////////////////////////////////////////////////////////////
//
//		WINDOW OBJECT
//
////////////////////////////////////////////////////////////////////////////////////////////////

	
function myWin() {
	this.getWinWidth = getWinWidth;
	this.getWinHeight = getWinHeight;
	this.getPageWidth = getPageWidth;
	this.getPageHeight = getPageHeight;
	this.getScrollX = getScrollX;
	this.getScrollY = getScrollY;
}

function getWinWidth() {
	if (NS) return(window.innerWidth);
	if (IE) return(document.body.offsetWidth);
}

function getWinHeight() {
	if (NS) return(window.innerHeight);
	if (IE) return(document.body.offsetHeight);
}

function getPageWidth() {
	//if (NS) return(document.width);
	//if (IE) return(document.body.scrollWidth);
	if (NS) return(window.innerWidth);
	if (IE) return(document.body.clientWidth);
}

function getPageHeight() {
	//if (NS) return(document.height);
	//if (IE) return(document.body.scrollHeight);
	if (NS) return(window.innerHeight);
	if (IE) return(document.body.clientHeight);
}

function getScrollX() {
	if (NS) return(window.pageXOffset);
	if (IE) return(document.body.scrollLeft);
}

function getScrollY() {
	if (NS) return(window.pageYOffset);
	if (IE) return(document.body.scrollTop);
}

var win = new myWin();


////////////////////////////////////////////////////////////////////////////////////////////////
//
//		IMAGE OBJECT
//
////////////////////////////////////////////////////////////////////////////////////////////////

function img( name, inPath ) {

	this.path = (inPath)?inPath:document;

	this.getImage = getImage;
	this.left = getImagePageLeft;
	this.top = getImagePageTop;
	this.swap = swapImage;

	this.obj = this.getImage( name );

}

function getImage( name ) {
	if (NS) return findImage(name, this.path );
	if (IE) return eval('document.all.' + name);
	return null;
}

function findImage(name, doc) {

	var i, img;
	
	for (i = 0; i < doc.images.length; i++)
		if (doc.images[i].name == name)
			return doc.images[i];
	
	for (i = 0; i < doc.layers.length; i++)
		if ((img = findImage(name, doc.layers[i].document)) != null) {
			img.container = doc.layers[i];
			return img;
		}
}

function getImagePageLeft() {

  var x, obj;

  if (NS) {
    if (this.obj.container != null)
      return this.obj.container.pageX + img.x;
    else
      return this.obj.x;
  }
  if (IE) {
    x = 0;
    obj = this.obj;
    while (obj.offsetParent != null) {
      x += obj.offsetLeft;
      obj = obj.offsetParent;
    }
    x += obj.offsetLeft;
    return x;
  }
  return -1;
}

function getImagePageTop(img) {

  var y, obj;

  if (NS) {
    if (this.obj.container != null)
      return this.obj.container.pageY + img.y;
    else
      return this.obj.y;
  }
  if (IE) {
    y = 0;
    obj = this.obj;
    while (obj.offsetParent != null) {
      y += obj.offsetTop;
      obj = obj.offsetParent;
    }
    y += obj.offsetTop;
    return y;
  }
  return -1;
}

function swapImage(objN) {

	if (objN && this.obj)
	this.obj.src = objN.src

}

////////////////////////////////////////////////////////////////////////////////////////////////
//
//		PRELOAD OBJECT
//
////////////////////////////////////////////////////////////////////////////////////////////////


function preload() {

	this.imgs = new Array();
	
	this.load = preloadAddImage;

}

function preloadAddImage( src ) {
	
	var newIndex = this.imgs.length;

	this.imgs[newIndex] = new Image();
	this.imgs[newIndex].src = src;

}


////////////////////////////////////////////////////////////////////////////////////////////////
//
//		MISC STUFF
//
////////////////////////////////////////////////////////////////////////////////////////////////

function doNothing() {}

function blurIE(){
	if(IE){	
		for(i=0;i<document.links.length;i++){
			if(document.links[i].focus) document.links[i].onfocus = document.links[i].blur 
		}
	}
}

