
/* DHTML_Library_Code */
/****************************************************************************   
DHTML library from DHTMLCentral.com
*   Copyright (C) 2001 Thomas Brattli 2001
*   This script was released at DHTMLCentral.com
*   Visit for more great scripts!
*   This may be used and changed freely as long as this msg is intact!
*   We will also appreciate any links you could give us.
*
*   Made by Thomas Brattli 2001
***************************************************************************/
//Browsercheck (needed) ***************
function lib_bwcheck(){ 
  this.ver = navigator.appVersion;
  this.agent = navigator.userAgent;
  this.dom = document.getElementById?1:0;
  this.opera5 = this.agent.indexOf("Opera 5")>-1;
  this.ie4 = (window.ActiveXObject && !document.getElementById)?1:0;
  this.ie5 = (window.ActiveXObject && document.getElementById && !document.compatMode)?1:0; 
  this.ie6 = (window.ActiveXObject && document.compatMode)?1:0;
  //this.ie7 = (window.ActiveXObject && window.XMLHttpRequest)?1:0;
  this.ie = this.ie4||this.ie5||this.ie6;
  this.mac = this.agent.indexOf("Mac")>-1;
  this.ns6 = (this.dom && parseInt(this.ver) >= 5) ?1:0; 
  this.ns4 = (document.layers && !this.dom)?1:0;
  this.bw = (this.ie6||this.ie5||this.ie4||this.ns4||this.ns6||this.opera5);
  return this;
}

/* old version
function lib_bwcheck(){ 
  this.ver=navigator.appVersion
  this.agent=navigator.userAgent
  this.dom=document.getElementById?1:0
  this.opera5=this.agent.indexOf("Opera 5")>-1
  this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
  this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
  this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
  this.ie=this.ie4||this.ie5||this.ie6
  this.mac=this.agent.indexOf("Mac")>-1
  this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
  this.ns4=(document.layers && !this.dom)?1:0;
  this.bw=(this.ie6||this.ie5||this.ie4||this.ns4||this.ns6||this.opera5)
  return this
}
*/
bw=new lib_bwcheck(); //Browsercheck object

//Debug function ******************
function lib_message(txt){alert(txt); return false}

//Lib objects  ********************
function lib_obj(obj,nest){ 
  if(!bw.bw) return lib_message('Old browser')
  nest=(!nest) ? "":'document.'+nest+'.'
  this.evnt=bw.dom? document.getElementById(obj):
    bw.ie4?document.all[obj]:bw.ns4?eval(nest+"document.layers." +obj):0;	
  if(!this.evnt) return lib_message('The layer does not exist ('+obj+')' 
    +'- \nIf your using Netscape please check the nesting of your tags!')
  this.css=bw.dom||bw.ie4?this.evnt.style:this.evnt; 
  this.ref=bw.dom||bw.ie4?document:this.css.document;
  this.x=parseInt(this.css.left)||this.css.pixelLeft||this.evnt.offsetLeft||0;
  this.y=parseInt(this.css.top)||this.css.pixelTop||this.evnt.offsetTop||0
  this.w=this.evnt.offsetWidth||this.css.clip.width||
    this.ref.width||this.css.pixelWidth||0; 
  this.h=this.evnt.offsetHeight||this.css.clip.height||
    this.ref.height||this.css.pixelHeight||0
  this.c=0 //Clip values
  if((bw.dom || bw.ie4) && this.css.clip) {
  this.c=this.css.clip; this.c=this.c.slice(5,this.c.length-1); 
  this.c=this.c.split(' ');
  for(var i=0;i<4;i++){this.c[i]=parseInt(this.c[i])}
  }
  this.ct=this.css.clip.top||this.c[0]||0; 
  this.cr=this.css.clip.right||this.c[1]||this.w||0
  this.cb=this.css.clip.bottom||this.c[2]||this.h||0; 
  this.cl=this.css.clip.left||this.c[3]||0
  this.obj = obj + "Object"; eval(this.obj + "=this")
  return this
}

//Moving object to **************
lib_obj.prototype.moveIt = function(x,y){
    if (!document.layers)
    {
        this.x=x;this.y=y; this.css.left=x+'px';this.css.top=y+'px'
    }
    else
    {
        this.x=x;this.y=y; this.css.left=x;this.css.top=y
    }
}

lib_obj.prototype.up=goUp;
lib_obj.prototype.down=goDown;
lib_obj.prototype.scroll = scroll;
lib_obj.prototype.noScroll = noScroll;


//Makes the object go up
function goDown(move){
	if(this.y>-this.h+this.max){
		this.moveIt(this.x,this.y-move);
		if(this.loop)
			this.timer =  setTimeout(this.obj+".down("+move+")",this.speed);
	}
}
//Makes the object go down
function goUp(move){
	if(this.y<0){
		this.moveIt(this.x,this.y+move);
		if(this.loop)
			this.timer = setTimeout(this.obj+".up("+move+")",this.speed);
	}
}

//Calls the scrolling functions. Also checks whether the page is loaded or not.
function scroll(speed){
	if(this.loaded){
		this.speed = Math.abs(speed);
		this.loop=true;
		if(speed>0) this.down(speed);
		else this.up(-speed);
	}
	
	return false;
}

//Stops the scrolling (called on mouseout)
function noScroll(){
	this.speed = 0;
	this.loop=false;
	if(this.timer)
	{
		clearTimeout(this.timer);
		this.timer = null;
	}

	return false;
}

// from : http://www.faqts.com/knowledge_base/view.phtml/aid/13653/fid/128
function getImagePosition (img) 
{
	if (document.layers)
		return {x: img.x, y: img.y };
	else {
		var coords = {x: 0, y: 0 };
		// there's some bug in this function in ie mac
		// but this code doesn't work on every case...
		/*
		if(bw.agent.indexOf('Mac') != -1)
		{
			coords.y = document.body.topMargin;
			coords.x = document.body.leftMargin;
			alert('top='+coords.y+',left='+coords.x);
		}
		*/
		var r = "";
		var b = "";
		var l = null;
		var ll = null;
		while (img) {
			var c = {x: img.offsetLeft, y: img.offsetTop};
			r += 'top='+c.y+',left='+c.x+"\n";
			coords.x += c.x;
			coords.y += c.y;
			// there's somethings to coorect with border too
			if(img.border && img.border > 0 && false)
				b += 'border='+img.border+"\n";

			// keep track of two previous coord
			ll = l;
			l  = c;
			img = img.offsetParent;
		}
		if(false) alert(b);
		if(false) alert(r);
		if(false) alert("ll.y="+ll.y+",ll.x="+ll.x);

		// it seems i need to patch the calculated coord for ie mac, but it's
		// only for our table layout design
        if (!window.showModelessDialog && window.ActiveXObject && document.getElementById)
		{
			coords.x -= ll.x;
			coords.y -= ll.y;
		}

		return coords;
	}
}
/* DHTML_Library_Code */
