/* * * * * * * * * * * * * * * * * * * * * * * * *\
*               KLayers 3.00 alpha  b 7_12_2003   *
* DHTML Library for Internet Explorer 4.* - 6.*,  *
* Netscape 7.*, Mozilla 1.*, Opera 6.* - 7.*      *
* Copyright by Kruglov S.A. (www.kruglov.ru) 2003 *
\* * * * * * * * * * * * * * * * * * * * * * * * */

// NO FURTHER SUPPORT FOR Netscape 4. SORRY :))
// NO FURTHER SUPPORT FOR Opera 5. SORRY :))
// NO FURTHER SUPPORT FOR Opera 6 (???). SORRY :))

// THIS IS EXPERIMENTAL PRE-ALPHA VERSION !

/***  See for description and latest version  ***\
\***  http://www.kruglov.ru/klayers/          ***/

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
	}
	if(document.all)
		this.object=document.all[name]
	else
		this.object=d.getElementById(name)

	if(this.object)	{
		this.style=this.css=this.object.style
	}
}


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)
}

// new, experimental

KLP.setWidth=function(w){
	if(w<=0){
		this.style.display="none"
	}else{
		this.style.width=w+"px"
		this.style.display=""
	}
}

KLP.setHeight=function(h){
	if(h<=0){
		this.style.display="none"
	}else{
		this.style.height=h+"px"
		this.style.display=""
	}
}

KLP.setSize=function(w,h){
	this.setWidth(w)
	this.setHeight(h)
}

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
	}
}

//


// MENU PROTOTYPE
// (c) Kruglov S.A. 2003
// www.kruglov.ru

// string functions /////////////////////////////////////////////////////////////////////////////////////

function isspace(c){
	if(c==' ' || c=="\t" || c=="\n" || c=="\r") return true
	return false
}

function isquote(c){
	if(c=='\'' || c=="\"") return true
	return false
}

function phpstring(c){ // undefined to ''
	if(!c) return ''
	return c
}

function phpnumber(c){ // undefined to 0
	if(!c) return 0
	return 1*c
}

// parsing attributes from:  var='zaza' xxx=oops super="yeah"
// to variables

function parseAttributes(str, to, ignoreSpacesInName){

	if(!to){
		attr=[]
	}

	r_a_name=false
	r_a_eq=false
	r_a_value=false
	r_complete=false

	a_name=[]
	a_eq=[]
	a_value=[]
	a_value_quote=""

	s=(str+" ").split('')

	l=s.length
	for(i=0;i<l;i++){
		c=s[i]
		if(!r_a_name && !r_a_eq && !r_a_value){
			if(isquote(c) || c=="="){
				break
			}
			if(!isspace(c)){
				r_a_name=true
				a_name[a_name.length]=c
			}
		}else
		if(r_a_name){
			if(isquote(c)){
				break
			}
			if(isspace(c) || c=="="){
				r_a_name=false
				r_a_eq=true
				a_eq[a_eq.length]=c
			}else{
				a_name[a_name.length]=c
			}
		}else
		if(r_a_eq){
			if(isspace(c) || c=="="){
				array_push(a_eq,c)
			}else{
				t=a_eq.join('').replace(/(^\s*)|(\s*$)/,"") // trim
				if(t!="="){
					if(t!=""){
						break
					}
					i-- // ungetc()
					r_complete=true
				}else{
					if(isquote(c)){
						a_value_quote=c
					}else{
						a_value[a_value.length]=c
					}
					r_a_value=true
					r_a_eq=false
				}
			}
		}else

		if(r_a_value){
			if((a_value_quote=="" && isspace(c))
				||
				(a_value_quote==c)){
					r_complete=true
			}else{
				a_value[a_value.length]=c
			}
		}

		if(r_complete){
			r_a_name=false
			r_a_eq=false
			r_a_value=false
			a_value_quote=""

			a_name=a_name.join('')

			if(ignoreSpacesInName){
				a_name=a_name.replace(/_/g,"")
			}

			a_value=a_value.join('')

			if(to){
				to[a_name]=a_value
			}else{
				attr[a_name]=a_value
			}

			a_name=[]
			a_eq=[]
			a_value=[]
			r_complete=false
		}
	}

	if(!to){
		return attr
	}
}

// class kmenu /////////////////////////////////////////////////////////////////////////////////////

k_counter=1 // global counter

function kmenu(argv,inheriter){
	this.number=k_counter++
	this.inheriter=inheriter

	if(!self.kmenus){
		kmenus=[]
	}

	kmenus[this.number]=this.inheriter

	this.attr=[]
	this.level=1

	this.parent=-1

	parseAttributes(argv,this.attr,true)

	this.items=[]
	this.id_to_items=[]

	this.add=function(argv){
		var i=new kmenuitem(argv)

		if(!i.level){
			i.level=this.level
		}else{
			this.level=i.level
		}

		var its=this.items;

		var l=its.length;
		if(l>0 && its[l-1].level<i.level){
			its[l-1].haschildren=true
		}
		if(!i.id) i.id=l
		this.id_to_items[i.id]=l
		its[l]=i

		var plevel=i.level
		if(i.current){
			for(j=l-1;j>=0;j--){
				if(its[j].level<plevel){
					its[j].currentsection=true
					plevel=its[j].level
				}
				if(its[l].level==1) break
			}
		}
	}

	this.level_plus=function(){
		this.level++
	}
	this.level_minus=function(){
		this.level--
	}

	this.inheriter.attr=this.attr
	this.inheriter.items=this.items
	this.inheriter.id_to_items=this.id_to_items
	this.inheriter.number=this.number

	this.inheriter.add=function(argv){
		this.kr_menu.add(argv)
	}

	this.inheriter.level_plus=function(){
		this.kr_menu.level_plus()
	}

	this.inheriter.level_minus=function(){
		this.kr_menu.level_minus()
	}

	// otladka
	this.trace=function(start){
		if(!start) start=0
		var level=this.items[start].level
		var i
		document.write("<ul>")
		for(i=start; i < this.items.length; i++){
			var it=this.items[i]
			if(it.level>level){
				i=this.trace(i)
			}else if(it.level<level){
				break;
			}else{
				document.write("<li><a href='"+it.href+"'>"+it.title+"</a>"+(it.current?" *":"")+(it.currentsection?" +":""))
			}
		}
		document.write("</ul>")
		return i-1
	}
}

// class kmenuitem ////////////////////////////////////////////////////////////////////////////////

function kmenuitem(argv){
	parseAttributes(argv,this,true)
}

// Array patch

if(![].push){
	Array.prototype.push=function(item){
		this[this.length]=item
	}
}



// KSLIDE MENU ///////////////////////////////////////////////////////////////////////////////////////


// SLIDING MENU
// (c) Kruglov S.A. 2003, 2004
// www.kruglov.ru

// requires kkr_menu.js, klayers.js

// class kslide //////////////////////////////////////////////////////////////////////

function kslide(argv){
	this.kr_menu=new kmenu(argv, this)

	var buffer=[]
	this.show=function(start){
		if(!start) start=0
		var level=this.items[start].level
		var i
		var preloaderbuffer=[]
		var parent=-1
		var menuN=this.number
		if(start==0){
			buffer=[]
			preloaderbuffer=[]
			document.write("<div id='k_menu_preloader_"+menuN+"' style='position:absolute;top:0px;left:0px;width:1px;height:1px;overflow:hidden;visibility:visible'>PRELOADING!!!...</div>")

			var d_c="cursor:pointer;cursor:hand;" // default cursor

			this.menu_styles=[]
			this.item_styles=[]
			this.max_menu_style_level=0
			this.max_item_style_level=0

			var sep=["style","item"]
			var a,b
			for(a in this.attr){
				for(b in sep){
					if(a.indexOf('style')>0 && a.indexOf('level')==0 && (a.indexOf(sep[b])==6||a.indexOf(sep[b])==7)){
						var lvl=1*(a.charAt(5)+(!isNaN(a.charAt(6))?a.charAt(6):''))
						if(sep[b]=="item"){
							this.item_styles[lvl]=true
							if(lvl>this.max_item_style_level) this.max_item_style_level=lvl
						}else{
							this.menu_styles[lvl]=true
							if(lvl>this.max_menu_style_level) this.max_menu_style_level=lvl
						}

					}
				}
			}
			//menuitems styles
			var j
			var last=0
			var i_s=""
			var i_hc_s=""
			var i_h_s=""
			var i_hc_o_s=""
			var i_hc_h_s=""
			var i_hc_o_h_s=""
			var i_c_s=""
			var i_c_hc_s=""
			var i_cs_s=""

			for(j=1;j<=this.max_item_style_level;j++){
				if(this.item_styles[j]){
					last=j
				}
				i_s+=		phpstring(this.attr["level"+last+"itemstyle"])+";"
				i_h_s=		phpstring(this.attr["level"+last+"itemhoverstyle"])+";"
				i_hc_s=	phpstring(this.attr["level"+last+"itemhaschildrenstyle"])+";"
				i_hc_o_s=	phpstring(this.attr["level"+last+"itemhaschildrenopenstyle"])+";"
				i_hc_h_s=	phpstring(this.attr["level"+last+"itemhaschildrenhoverstyle"])+";"
				i_hc_o_h_s=phpstring(this.attr["level"+last+"itemhaschildrenopenhoverstyle"])+";"
				i_c_s=		phpstring(this.attr["level"+last+"itemcurrentstyle"])+";"

				buffer.push("<style>.level"+j+ "_item_"+this.number+"{"+d_c+i_s+"}</style>")
				buffer.push("<style>.level"+j+ "_item_current_"+this.number+"{"+d_c+i_s+i_c_s+"}</style>")
				buffer.push("<style>.level"+j+ "_item_haschildren_"+this.number+"{"+d_c+i_s+i_hc_s+"}</style>")
				buffer.push("<style>.level"+j+ "_item_haschildren_open_"+this.number+"{"+d_c+i_s+i_hc_s+i_hc_o_s+"}</style>")
				buffer.push("<style>.level"+j+ "_item_hover_"+this.number+"{"+d_c+i_s+i_h_s+"}</style>")
				buffer.push("<style>.level"+j+ "_item_haschildren_hover_"+this.number+"{"+d_c+i_s+i_hc_s+i_h_s+i_hc_h_s+"}</style>")
				buffer.push("<style>.level"+j+ "_item_haschildren_open_hover_"+this.number+"{"+d_c+i_s+i_hc_s+i_h_s+i_hc_h_s+i_hc_o_h_s+"}</style>")

				preloaderbuffer.push("<div class=level"+j+"_item_"+this.number+">&nbsp;</div>")
				preloaderbuffer.push("<div class=level"+j+"_item_current_"+this.number+">&nbsp;</div>")
				preloaderbuffer.push("<div class=level"+j+"_item_haschildren_"+this.number+">&nbsp;</div>")
				preloaderbuffer.push("<div class=level"+j+"_item_haschildren_open_"+this.number+">&nbsp;</div>")
				preloaderbuffer.push("<div class=level"+j+"_item_hover_"+this.number+">&nbsp;</div>")
				preloaderbuffer.push("<div class=level"+j+"_item_haschildren_hover_"+this.number+">&nbsp;</div>")
				preloaderbuffer.push("<div class=level"+j+"_item_haschildren_open_hover_"+this.number+">&nbsp;</div>")

				if(isDOM) layer('k_menu_preloader_'+menuN).object.innerHTML=preloaderbuffer.join('')
			}
			//submenus styles
			last=0
			for(j=2;j<=this.max_menu_style_level;j++){
				if(this.menu_styles[j]){
					last=j
				}
				buffer.push("<style>.level"+j+"_"+this.number+"{"+phpstring(this.attr["level"+last+"style"])+"}</style>")
			}
			buffer.push("<div class=menu style='"+this.attr.menustyle+"'>")
		}

		if(level>1){
			parent=start-1
			buffer.push("<div class='k_slidemenu_submenu' "+((this.items[start-1].opened || this.attr.opencurrent && this.items[start-1].currentsection)?(isMSIE?"style='height:0px'":""):"style='display:none'")+" id='k_submenu_"+this.number+"_"+parent+"'><table style='width:100%' cellspacing=0 cellpadding=0 border=0 id='k_submenu_"+this.number+"_"+parent+"_content'><tr><td><div class='level"+((level>this.max_menu_style_level)?this.max_menu_style_level:level)+"_"+this.number+"'>")

		}

		for(i=start; i < this.items.length; i++){
			var it=this.items[i]
			it.open=this.attr.opencurrent && it.currentsection || it.opened
			if(it.level>level){
				i=this.show(i)
			}else if(it.level<level){
				break;
			}else{
				it.parent=parent

				it.closing=null
				it.opening=null

				buffer.push("<div id='kmenuitem_"+this.number+"_"+i+"' class='"+this.getclassname_item(i)+"' ")

				if(!it.current || !this.attr.linkfromcurrent){
					buffer.push("onmouseover='kmenus["+this.number+"].mouseover_item(\""+it.id+"\")' ")
					buffer.push("onmouseout='kmenus["+this.number+"].mouseout_item(\""+it.id+"\")' ")
				}

				buffer.push("onclick='kmenus["+this.number+"].click_item(\""+it.id+"\");return false' ")
				buffer.push("onselectstart='return false'>")

				buffer.push(phpstring((level==1)?this.attr.menuitembefore:this.attr.submenuitembefore)+ it.title+phpstring((level==1)?this.attr.menuitemafter:this.attr.submenuitemafter))

				buffer.push("</div>")

				buffer.push(phpstring((level==1)?this.attr.menumedium:this.attr.submenumedium))
			}
		}

		if(level>1) buffer.push("</div></td></tr></table></div>")

		if(start==0){
			document.write(buffer.join('\n')+"</div>")

		}
		return i-1;
	}

	this.getclassname_item=function(n){
		var it=this.items[n]
		var level=it.level
		return "level"+((level>this.max_item_style_level)?this.max_item_style_level:level)+"_item_"+(it.current?"current_":"")+(it.haschildren?"haschildren_":"")+((it.open && it.haschildren)?"open_":"")+((it.hover)?"hover_":"")+this.number
	}

	this.updatestyle_item=function(n){
		layer("kmenuitem_"+this.number+"_"+n).object.className=this.getclassname_item(n)
	}

	this.mouseover_item=function(n){
		n=this.id_to_items[n]
		var it=this.items[n]
		it.hover=true
		this.updatestyle_item(n)
		window.status=phpstring(it.href)
	}

	this.mouseout_item=function(n){
		n=this.id_to_items[n]
		var it=this.items[n]
		it.hover=false
		this.updatestyle_item(n)
		window.status=""
	}


	this.click_item=function(n){
		n=this.id_to_items[n]
		var it=this.items[n]
		if(!it.haschildren){
			var target=this.attr.target
			if(it.target && it.target.toLowerCase()!="_self"){
				target=it.target
			}else{
				target=''
			}
			if(!this.attr.linkfromcurrent || !it.current){
				if(target){
					if(top.frames && top.frames[target]){
						top.frames[target].location.href=this.items[n].href
					}else{
						window.open(it.href, target)
					}
				}else{
					window.location.href=it.href
				}
			}
		}else{
			if(it.open){
				this.close_submenu(n)
			}else{
				this.open_submenu(n)
			}
		}
	}

	this.open_submenu=function(n,y){
		var it=this.items[n]

		if(!it.haschildren) return
		it.open=true
		this.updatestyle_item(n)
//alert(n)
		var l=layer("k_submenu_"+this.number+"_"+n)
		var ll=layer("k_submenu_"+this.number+"_"+n+"_content")

		if(!y || y<=0){
			l.setHeight(y=1)
			l.style.overflow='hidden'
			l.style.display=''

			if(this.attr.onlyone){ // если держать открытым одну линию пунктов
				// close open menuitem

				for(i=0;i<this.items.length;i++){
					if(i!=n && this.items[i].open && this.items[i].level>=this.items[n].level){
						this.close_submenu(i)
						//break
					}
				}
			}
		}else{
			if(y>ll.getHeight()){
				// кончили ползать.
				l.style.overflow='visible'
				if(isMozilla) l.style.height='' // Mozilla sux

				return
			}
			l.setHeight(y)
		}
		setTimeout("kmenus["+this.number+"].open_submenu("+n+","+(y+phpnumber(this.attr.step))+")",this.attr.delay);
	}

	this.close_submenu=function(n,y){
		var it=this.items[n]
		if(it.opened) return
		if(!it.haschildren) return
		it.open=false
		this.updatestyle_item(n)

		var l=layer("k_submenu_"+this.number+"_"+n)
		var ll=layer("k_submenu_"+this.number+"_"+n+"_content")

		if(''+y=='undefined'){
			l.setHeight(y=ll.getHeight())
			l.style.overflow='hidden'
		}

		if(y<=0){
			l.style.display='none'
			if(this.attr.onlyone){ // если держать открытым одну линию пунктов
				for(i=n+1;i<this.items.length && this.items[i].level>this.items[n].level;i++){
					this.close_submenu(i)
				}
			}
		}else{
			l.setHeight(y)
			setTimeout("kmenus["+this.number+"].close_submenu("+n+","+(y-this.attr.step)+")",this.attr.delay);
		}
	}
}





