/*******************************************************************************
	mt dhtml api (oo)

	v	:	1.71
	d	:	02/03
	b	:	win mac ie 5+, Moz, Netscape 6+, Opera 7+, 
	
*******************************************************************************
	notes:
		-	requires xhtml strict DTD
	updates:
		-	21/02/03	fixed clip bug 1.71
		-	03/02/03	removed version 4 browser suport 1.70
********************************************************************************/

document.dhtml = new Array()
var brow = ""
var dhtmlLoaded = false;

function browserCheck(){
	this.d 		= document;
	this.n 		= navigator;
	this.OStype = this.n.platform.toLowerCase();
	this.ua 	= this.n.userAgent;
	this.mac 	= (this.n.platform.indexOf('Mac') > -1);
	this.win 	= (this.OStype.indexOf("win") > -1);
	this.opera 	= /opera [56789]|opera\/[56789]/i.test(this.ua);
	this.ie 	= !this.opera && /MSIE/.test(this.ua);
	this.ns 	= (this.n.appName.indexOf('Netscape') > -1);
	this.ie5 	= /MSIE 5\.[01234]/.test(this.ua);
	this.ie55 	= /MSIE 5\.5/.test(this.ua);
	this.ie6 	= /MSIE [6789]/.test(this.ua);
	this.macie45 = (this.mac && this.ua.indexOf("msie 4.5") > -1);
	this.macie5 = (this.mac && this.ua.indexOf("msie 5") > -1);
	this.ns6 	= !this.opera && /netscape.*6\./i.test(this.ua);
	this.gecko 	= !this.opera && /gecko/i.test(this.ua);
	this.aol 	= this.ua.indexOf('aol') != -1;
	if(this.aol)	this.ie = 1;
	this.dom 	= (this.d.getElementById && this.d.createElement);
	this.css 	= (document.compatMode == "CSS1Compat");
	this.ieBox 	= document.all && (document.compatMode == null || document.compatMode != "CSS1Compat");
}brow = new browserCheck();

var proto = oDhtml.prototype

function oDhtml(sId, sNestId, bAttach){	
	this.id = sId;
	this.nested = sNestId || false;
	this.parent = false;
	this.children = [];
	this.attached = bAttach;
	this.createObject();
	return this;
}

function attachObject(sId, sNestId){
	return document.dhtml[sId] || new oDhtml(sId, sNestId, true);
}

proto.createObject  = function(){		
	if(this.nested && !this.attached){
		if(!document.dhtml[this.nested]) var temp = attachObject(this.nested);
		this.parent = document.dhtml[this.nested];
		this.parent.children[this.parent.children.length] = this;
		this.parent.children[this.id] = this;
	}
	if(!this.attached){
		var o = document.createElement("DIV");
		o.id = this.id;
		o.style.position = "absolute";
		o.style.visibility = "hidden";
		o.setAttribute('style', defaultAttributes);
		var target = (this.nested)? document.getElementById(this.nested):document.body;
		target.appendChild(o);
		o = null;
	}
	this.obj = document.getElementById(this.id)
	if(!this.obj){
		return alert(this.id + ' does not exist');
	}
	this.css = this.obj.style;
	this.index = document.dhtml.length;
	document.dhtml[this.index] = this;
	document.dhtml[this.id] = this;
	if(this.attached){
		this.getDimensions();
		this.html = this.obj.innerHTML;
	}
}

proto.moveTo = function(x, y){
	this.x = parseInt(x); this.y = parseInt(y);
	if(this.limitedMove){
		if(x < this.mLim[0]) this.x = this.mLim[0];
		if(y < this.mLim[1]) this.y = this.mLim[1];
		var xl = this.mLim[2] - parseInt(this.w);
		var yl = this.mLim[3] - parseInt(this.h);
		if(x > xl) this.x = xl;
		if(y > yl) this.y = yl;
	}
	document.getElementById(this.id).style.left = this.x + "px";
	document.getElementById(this.id).style.top = this.y + "px";
	return
	/* curious mac ie5 bug ??
	this.css.left = this.x + bPx
	this.css.top  = this.y + bPx
	*/
}
proto.moveBy = function(nDx, nDy){
	this.moveTo(parseInt(this.x) + nDx, parseInt(this.y) + nDy)
}

proto.write = function(sContent){
	this.html = sContent
	this.obj.innerHTML = this.html
	this.getDimensions()
}
proto.add = function(sContent){
	this.html += sContent
	this.write(this.html)
}
proto.setVisible = function(bVisible){
	this.css.visibility = (bVisible) ? "visible" : "hidden"
	this.visible = bVisible
}
proto.setDisplay = function(bBlock){
	this.css.display = (bBlock)? "" : "none"
}

proto.setZIndex = function(nZ){
	this.css.zIndex = nZ
	this.z = nZ
}
proto.setBackground = function(sBg){
	if(to.indexOf('.') != -1){
		this.css.backgroundImage = "url("+sBg+")";
	}else{
		this.css.backgroundColor = sBg;
	}
}
proto.clipTo = function(nTop, nRight, nBottom, nLeft){
	this.clip = [nTop,nRight,nBottom,nLeft]
	this.css.clip = 'rect('+parseInt(nTop)+'px,'+parseInt(nRight)+'px,'+parseInt(nBottom)+'px,'+parseInt(nLeft)+'px)'
}
proto.resizeTo = function(nWidth, nHeight){
	if(nWidth) this.setWidth(nWidth)
	if(nHeight) this.setHeight(nHeight)
}
proto.setWidth = function(nWidth){
	this.w = nWidth; this.r = parseInt(this.x) + nWidth 
	document.getElementById(this.id).style.width = this.w + "px"
}
proto.setHeight = function(nHeight){
	this.h = nHeight; this.b = parseInt(this.y) + nHeight
	document.getElementById(this.id).style.height = this.h + "px"
}
proto.getDimensions = function(){
	this.w = (brow.ie)? this.obj.clientWidth:this.obj.offsetWidth
	this.h = (brow.ie)? this.obj.clientHeight:this.obj.offsetHeight
	this.x = (brow.ie)? this.obj.offsetLeft:parseInt(this.css.left)
	this.y = (brow.ie)? this.obj.offsetTop: parseInt(this.css.top)
	this.r = this.x + this.w
	this.b = this.y + this.h
}
proto.setProperties = function(nX, nY, nW, nH, sVis, sBg, nZ){
	this.moveTo(nX, nY)
	this.resizeTo(nW, nH)
	if(sVis) this.setVisible((sVis=="visible") ? 1 : 0)
	if(sBg) this.setBackground(sBg)
	if(nZ) this.setZIndex(nZ)
}
proto.createImage = function(sSrc, sName, nW, nH) {
	var sDim = (nW ? ' width='+nW+ ' ' : '') + (nH ? ' height=' + nH + ' ' : '');
	var imgSrc = '<img ' + ((sName) ? 'name="' + sName + '"':'')
				+' src="' + sSrc + '" ' + sDim + ' border="0" align="top" />';
	this.write(imgSrc);
	if(sName){
		this.image = document.images[sName];
	}
}

proto.limitMovement = function(nX, nY, nR, nB){
	if(x == null) this.limitedMove = false
	else{
		this.mLim = [parseInt(nX),parseInt(nY),parseInt(nR),parseInt(nB)]
		this.limitedMove = true
	}
}
proto.slideTo = function(nX, nY, nTime, sStyle, sEndFunction){
	if(nTime < 40){ 
		return alert('nTime must be > 40');
	}
	this.tx = nX; this.ty = nY;
	this.stepX = (this.tx - parseInt(this.x))/(nTime/40);
	this.stepY = (this.ty - parseInt(this.y))/(nTime/40);
	this.slideStyle = (sStyle == "slower") ? 0.95 : (sStyle == "faster") ? 1.05 : 0;
	this.onSlideEnd = sEndFunction;
	if(this.timer) clearInterval(this.timer);
	this.timer = setInterval('document.dhtml["'+this.id+'"].__slideStep()', 40);
}
proto.slideBy = function(dx, dy, nTime, sStyle, sEndFunction){
	this.slideTo(parseInt(this.x)+dx, parseInt(this.y)+dy, nTime, sStyle, sEndFunction);
}
proto.__slideStep = function(){
	if((this.tx - parseInt(this.x))/this.stepX < 1 || (this.ty - parseInt(this.y))/this.stepY < 1){
		clearInterval(this.timer);
		this.moveTo(this.tx, this.ty);
		if(this.onSlideEnd) eval(this.onSlideEnd);
	}else 
		this.moveBy(this.stepX, this.stepY);
	if(this.slideStyle){
		this.stepX *= this.slideStyle;
		this.stepY *= this.slideStyle;
	}
}
proto.setClass = function(sClassName){
	document.getElementById(this.id).className = sClassName;
}
proto.setOpacity = 	function(nPercent) {
	this.opacity = nPercent;
	if(brow.ie) this.css.filter = 'alpha(opacity='+nPercent+')';
	else this.css.MozOpacity = nPercent/100;
}
proto.setAttribute = function(sAtt, aVal){
	document.getElementById(this.id).setAttribute(sAtt, sVal);
}
proto.getAttribute = function(sAtt){
	return document.getElementById(this.id).getAttribute(sAtt);
}

proto.containsMouse = function(){
	var elem = this;
	var elemX = parseInt(this.x);
	var elemY = parseInt(this.y);
	while(elem.parent){
		elem = elem.parent;
		elemX += parseInt(elem.x);
		elemY += parseInt(elem.y);
	}
	return elemX < mouseX && (elemX + parseInt(this.w)) > mouseX && elemY < mouseY && (elemY+parseInt(this.h)) > mouseY;
}

function getObject(id){
	return document.getElementById(id);
}
function documentProperties(){
	this.scrollX = getScrollX;
	this.scrollY = getScrollY;
	this.windowWidth = (brow.ie)? document.body.clientWidth:window.innerWidth;
	this.windowHeight  = (brow.ie)? document.body.clientHeight:window.innerHeight;
	this.bodyHeight = (brow.ie)? document.body.scrollHeight : (brow.dom) ? document.body.offsetHeight +"px" : "";
	this.screenWidth  = screen.width;
	this.screenHeight = screen.height;
	this.redraw = function(){if(brow.ns6 || brow.mac){window.resizeBy(0,1);window.resizeBy(0,-1)}}
	function getScrollX(){
		return (brow.ie)? document.body.scrollLeft:window.pageXOffset;
	}
	function getScrollY(){
		return (brow.ie)? document.body.scrollTop:window.pageYOffset;
	}
}

function getProperties(obj){
	var res = "";
	for(var i in obj){
		res += i +' \t-  ';
		if(typeof obj[i] == 'function')
			res += '[function]';
		else
			res += obj[i];
	}
	alert(res)
}

var mouseX = 0;
var mouseY = 0;

var aDhtmlMove 		= [];
var aDhtmlDown 		= [];
var aDhtmlUp 		= [];
var aDhtmlLoad 		= [];
var aDhtmlResize 	= [];
var aDhtmlKeyPress 	= [];

var dhtmlDragging = 0;
var doc = null;

document.onmousemove 	= dhtmlMouseMove;
document.onmousedown 	= dhtmlMouseDown;
document.onmouseup   	= dhtmlMouseUp;
document.onkeypress 	= dhtmlKeypress;
window.onload 			= dhtmlOnload;
window.onresize 		= dhtmlOnresize;
document.attachEvent = function(type, func){
	switch(type.toLowerCase()){
		case "onmousemove": aDhtmlMove[aDhtmlMove.length] = func; break;
		case "onmousedown": aDhtmlDown[aDhtmlDown.length] = func; break;
		case "onmouseup": aDhtmlUp[aDhtmlUp.length] = func; break;
		case "onkeypress": aDhtmlKeyPress[aDhtmlKeyPress.length] = func; break;
		case "onload": aDhtmlLoad[aDhtmlLoad.length] = func; break;
		case "onresize": aDhtmlResize[aDhtmlResize.length] = func; break;
		default: return; break
	}
}

function dhtmlMouseMove(e){
	mouseX = (brow.ie)? parseInt(event.x):e.pageX;
	mouseY = (brow.ie)? parseInt(event.y):e.pageY;
	execEventArray(aDhtmlMove);
	if(dhtmlDragging) return false;
}

function dhtmlMouseDown(e){
	execEventArray(aDhtmlDown);
}

function dhtmlMouseUp(e){
	execEventArray(aDhtmlUp);
}

function dhtmlKeypress(e){
	execEventArray(aDhtmlKeyPress);
}

function dhtmlOnresize(){
	doc = new documentProperties();
	execEventArray(aDhtmlResize);
}

function dhtmlOnload(){
	doc = new documentProperties();
	dhtmlLoaded = true;
	if(typeof init == 'function') init();
	execEventArray(aDhtmlLoad);
}

var activeObj = null;
proto.bEvents = false;
proto.attachEvent = function(type, func){
	if(!this.bEvents){
		this.bEvents = true;
		this.aOver = new Array(); this.aOut = new Array();
		this.aDown = new Array(); this.aUp = new Array();
		this.obj.onmouseover = dhtmlLayerMouseOver;
		this.obj.onmouseout = dhtmlLayerMouseOut;
		this.obj.tag = this.id;
		this.obj.onmousedown = dhtmlLayerMouseDown;
		this.obj.onmouseup = dhtmlLayerMouseUp;
	}
	switch(type.toLowerCase()){
		case "onmousedown": this.aDown[this.aDown.length] = func; break;
		case "onmouseup":   this.aUp[this.aUp.length] = func; break;
		case "onmouseover": this.aOver[this.aOver.length] = func; break;
		case "onmouseout":  this.aOut[this.aOut.length] = func; break;
		default:return;
	}
}

function dhtmlLayerMouseOver(){
	activeObj = document.dhtml[this.tag];
	execEventArray(activeObj.aOver);
}
function dhtmlLayerMouseOut(){
	if(!activeObj) return;
	execEventArray(activeObj.aOut);
	activeObj = null;
}
function dhtmlLayerMouseDown(e){
	if(!activeObj) return;
	activeObj.clickX = (window.event)? event.offsetX : e.layerX;
	activeObj.clickY = (window.event)? event.offsetY : e.layerY;
	execEventArray(activeObj.aDown);
}
function dhtmlLayerMouseUp(){
	if(!activeObj) return;
	execEventArray(activeObj.aUp);
}
function execEventArray(a){
	for(var i=0; i<a.length; i++){
		eval(a[i]);
	}
}

proto.drag = function(dragStyle){
	if(!docHasEvents){
		docHasEvents = true;
		document.attachEvent("onmousemove", "dhtmlHandleDrag()");
		document.attachEvent("onmouseup", "dhtmlStopDrag()");
	}
	function argContains(str){
		if(!dragStyle) return false;
		return (dragStyle.indexOf(str) > -1) ? 1 : 0;
	}
	this.isDraggable = true;
	this.dragParent = argContains('dragParent');
	this.dragHorz   = argContains('horizontal');
	this.dragVert   = argContains('vertical');
	this.toFront    = argContains('bringToFront');
	if(this.dragParent){
		this.parent.dragHorz = this.dragHorz;
		this.parent.dragVert = this.dragVert;
	}
	this.xAnch = 0;
	this.yAnch = 0;
	this.attachEvent("onmousedown", "dhtmlStartDrag()");
	this.attachEvent("onmouseup", "dhtmlStopDrag()");
}

proto.setDragAction  = function(sFunction){
	this.dragAction = sFunction;
}

proto.dragEnd = function(sFunction){
	this.onDragEnd = sFunction;
}

var dragObj = 0;
var docHasEvents = 0;
var toFrontZ = 500;

function dhtmlStartDrag(){
	dragObj = activeObj.dragParent? activeObj.parent:activeObj;
	dragObj.xAnch = mouseX - parseInt(dragObj.x);
	dragObj.yAnch = mouseY - parseInt(dragObj.y);
	if(activeObj.toFront) dragObj.setZIndex(toFrontZ++);
	dhtmlDragging = 1;
}

function dhtmlStopDrag(){
	dragObj.beingDragged = 0;
	if(dragObj.onDragEnd) 
		eval(dragObj.onDragEnd);
	dragObj = 0;
	dhtmlDragging = 0;
}

function dhtmlHandleDrag(){
	if(dragObj && dhtmlDragging){
		dragObj.beingDragged = 1;
		dragObj.dragToX = parseInt(dragObj.dragVert? dragObj.x:(mouseX - dragObj.xAnch));
		dragObj.dragToY = parseInt(dragObj.dragHorz? dragObj.y:(mouseY - dragObj.yAnch));
		if(dragObj.dragAction){
			eval(dragObj.dragAction);
		}
		with(dragObj){
			moveTo(dragToX, dragToY);
		}		
	}
}

var defaultAttributes = 'position:absolute;left:0px;top:0px;visibility:hidden;';

/*-----------------------------------------------*/

function getParentElement(oChild){
	var oParent = document;
	if (oChild == window) oParent = null;
	else if(oChild == document) oParent = window;
	else{
		if(oChild.offsetParent) oParent = oChild.offsetParent;
		else if(oChild.parentNode) oParent = oChild.parentNode;
		else if(oChild.parentElement) oParent = oChild.parentElement;
	}
	return oParent;
}