/* * * * * * * * * * * * * * * * * * * * * * * * *\
*               KLayers 3.00 alpha                *
* DHTML Library for Internet Explorer 4.* - 6.*,  *
* Netscape 7.*, Mozilla 1.*, Opera 5.* - 7.*      *
\* * * * * * * * * * * * * * * * * * * * * * * * */

function initKLayers(){
	isDOM=document.getElementById ? true : false
	isOpera=isOpera5=window.opera && isDOM
	isOpera6=window.print && isOpera
	isOpera7=isOpera6 && document.readyState
	isMSIE=document.all && document.all.item && !isOpera6
	isMozilla=navigator.appName=="Netscape" && isDOM
	isStrict=document.compatMode=='CSS1Compat'

	if(!isMozilla && !isMSIE && !isOpera){
		KLayers=false
		return false
	}

	pageLeft=0
	pageTop=0

	KL_imgCount=0
	KL_imgArray=new Array()

	return KLayers=true
}

initKLayers()

// document and window functions:

function KL_getBody(w){
	if(!w) w=window
	if(isStrict){
		return w.document.documentElement
	}else{
		return w.document.body
	}
}

function getWindowLeft(w){
	if(!w) w=window
	if(isMSIE || isOpera7) return w.screenLeft
	if(isMozilla || isOpera6) return w.screenX
}

function getWindowTop(w){
	if(!w) w=window
	if(isMSIE || isOpera7) return w.screenTop
	if(isMozilla || isOpera6) return w.screenY
}

function getWindowWidth(w){
	if(!w) w=window
	if(isMSIE) return KL_getBody(w).clientWidth
	if(isMozilla || isOpera) return w.innerWidth
}

function getWindowHeight(w){
	if(!w) w=window
	if(isMSIE) return KL_getBody(w).clientHeight
	if(isMozilla || isOpera) return w.innerHeight
}

function getDocumentWidth(w){
	if(!w) w=window
	if(isMSIE || isOpera7) return KL_getBody(w).scrollWidth
	if(isMozilla) return w.document.width
	if(isOpera) return w.document.body.style.pixelWidth
}

function getDocumentHeight(w){
	if(!w) w=window
	if(isMSIE || isOpera7) return KL_getBody(w).scrollHeight
	if(isMozilla) return w.document.height
	if(isOpera6) return w.document.body.style.pixelHeight
}

function getScrollX(w){
	if(!w) w=window
	if(isMSIE || isOpera7) return KL_getBody(w).scrollLeft
	if(isMozilla || isOpera6) return w.pageXOffset
}

function getScrollY(w){
	if(!w) w=window
	if(isMSIE || isOpera7) return KL_getBody(w).scrollTop
	if(isMozilla || isOpera6) return w.pageYOffset
}

function preloadImage(imageFile){
	KL_imgArray[KL_imgCount]=new Image()
	KL_imgArray[KL_imgCount++].src=imageFile
}

function layer(name, from){
	var l=new KLayer(name,from)
	if(l.object) return l
	return null
}

// class "KLayer":

function KLayer(name, parent){
	var d
	if(parent && parent.document){
		d=parent.document
	}else{
		d=document
	}
	this.object=d.getElementById(name)
	if(this.object)	{
		this.style=this.css=this.object.style
/*		this.shiftX=0
		this.shiftY=0


		if(this.style.position=="absolute"){ // TEMPORARY!!!
			if(!this.style.left){
				this.style.left="0px"
			}
			if(!this.style.top){
				this.style.top="0px"
			}
			this.shiftX=(this.getLeft()-parseInt(this.style.left))
			this.shiftY=(this.getTop()-parseInt(this.style.top))
			
			
			//alert(name+":"+this.getLeft()+"-"+parseInt(this.style.left))
		}
*/
	}
}


KLP=KLayer.prototype

KLP.isExist=function(){
	return (this.object)?true:false
}

function KL_getPageOffset(o){ 
	var KL_left=0
	var KL_top=0
	do{
		KL_left+=o.offsetLeft
		KL_top+=o.offsetTop
	}while(o=o.offsetParent)
	return [KL_left, KL_top]
}

KLP.getLeft=function(){
	return KL_getPageOffset(this.object)[0]-pageLeft
}

KLP.getTop=function(){
	return KL_getPageOffset(this.object)[1]-pageTop
}

KLP.getWidth=function(){ // DEPRECATED
	var o=this.object
	if(isMSIE || isMozilla || isOpera7) return o.offsetWidth
	if(isOpera6) return this.style.pixelWidth
}

KLP.getHeight=function(){ // DEPRECATED
	var o=this.object
	if(isMSIE || isMozilla || isOpera7) return o.offsetHeight
	if(isOpera6) return this.style.pixelHeight
}

KLP.setLeft=KLP.moveX=function(x){
	x+=pageLeft
	if(isOpera6){
		this.style.pixelLeft=x
	}else{
		this.style.left=x+"px"
	}
}

KLP.setTop=KLP.moveY=function(y){
	y+=pageTop
	if(isOpera6){
		this.style.pixelTop=y
	}else{
		this.style.top=y+"px"
	}
}

KLP.moveTo=KLP.move=function(x,y){
	this.setLeft(x)
	this.setTop(y)
}

KLP.moveBy=function(x,y){
	this.moveTo(this.getLeft()+x,this.getTop()+y)
}

KLP.setZIndex=KLP.moveZ=function(z){ //deprecated
	this.style.zIndex=z
}

KLP.setVisibility=function(v){
	this.style.visibility=v?"visible":"hidden"
}

KLP.show=function(){
	this.setVisibility(true)
}

KLP.hide=function(){
	this.setVisibility(false)
}

KLP.isVisible=KLP.getVisibility=function(){
	return (this.style.visibility.toLowerCase().charAt(0)=='h')?false:true
}

KLP.setBgColor=function(c){
	if(isMSIE || isMozilla || isOpera7){
		this.style.backgroundColor=c
	}else if(isOpera6){
		this.style.background=c
	}
}

KLP.write=function(str){ // DEPRECATED, надо учесть strict
	this.object.innerHTML=str
}

KLP.add=function(str){ // DEPRECATED
	this.object.innerHTML+=str
}