// JavaScript Document
var flag=new Object();
var fadein=false;
menusarray=new Array();
menuheightarray=new Array();
IE='\v'=='v';
(function() {
    var cache = {}
    window.nodeById = function(id) {
        return cache[id] ? cache[id] : cache[id] = document.getElementById(id);
    }
})()
var p,pp = null;
var sizestep=5;

function showhide(idone, idtwo){
	divone = nodeById(idone);
	divtwo = nodeById(idtwo);
	divone.style.display=(divone.style.display==''||divone.style.display=='')?'none':'';
	divtwo.style.display=(divtwo.style.display=='block'||divtwo.style.display=='')?'none':'';
}


function initmenu(menuid){
    menuobj=document.getElementById(menuid);
    for (var i=0; i < menuobj.children.length; i++){
        menuitem = menuobj.children[i]
        if (menuitem.children[1] !== undefined) {
                        
            if (menuitem.children[1].tagName=='UL') {
                obj=menuitem.children[1];
                id=menuitem.id;
                menuitem.onmouseover=function(){
                    window.clearTimeout(this.timer);
                    showsubmenu(this);
                };
                menuitem.onmouseout=function(){
                    window.clearTimeout(this.timer);
                    this.timer=window.setTimeout(function(obj){
                        hidesubmenu(obj)
                        },100,this);
                }
                menuitem.submenuheight=obj.clientHeight;
                obj.style.height='0';
                obj.style.display='none';
                menusarray[menusarray.length]=obj;
                menuitem.submenustatus='closed';
                obj.submenuaction='';
            }
        }
    }
}
function showsubmenu(menuitem){
    obj=menuitem.children[1];
    obj.submenuaction='open';
    startheight=obj.clientHeight;
    endheight = menuitem.submenuheight;
    resizeobj(obj,startheight,endheight);
}
                                
function hidesubmenu(menuitem){
    obj=menuitem.children[1];
    obj.submenuaction='close';
    startheight=obj.clientHeight;
    endheight = 0;
    resizeobj(obj,startheight,endheight);
}
function resizeobj(obj,startheight,endheight){
    //alert('stratheight='+startheight+' endheight= '+endheight);
    var time=20;
    if(obj.submenuaction=='open'){
        startheight=startheight+sizestep;
        if (startheight>=endheight) {
            obj.style.height=endheight+'px';
            obj.submenuaction=''
        }
        else {
            obj.style.display='block';
            obj.style.height=startheight+'px';
            if(obj.submenuaction=='open'){
                setTimeout (function(){
                    resizeobj(obj,startheight,endheight)
                    },time);
            }
        }
                        
    }
    if(obj.submenuaction=='close'){
        startheight=startheight-sizestep;
        if (startheight<=endheight) {
            obj.style.height=endheight+'px';
            obj.style.display='none';
            obj.submenuaction=''
        }
        else {
            obj.style.height=startheight+'px';
            if(obj.submenuaction=='close'){
                setTimeout (function(){
                    resizeobj(obj,startheight,endheight)
                    },time);
            }
        }
    }
    checkmax();
}
                
function checkmax(){
    x=0;
    for (var i=0; i<menusarray.length;i++){
        if (menusarray[i].clientHeight>x)x=menusarray[i].clientHeight;
                        
    }
    nodeById('control').style.height=x+'px';
}
/*
function hidesubmenus(classnam){
	divlist=document.getElementsByTagName('ul');
	for (var key in divlist){
//		divlist[key].style.display='none';
		if (divlist[key].className==classnam) {divlist[key].style.height='0';divlist[key].style.display='none';menusarray[menusarray.length]=divlist[key];}
	}
}
*/
function addtoclass(classnam, newclass){
    divlist=document.getElementsByTagName('div');
    for (var key in divlist){
        if (divlist[key].className==classnam) {
            divlist[key].className=divlist[key].className+' '+newclass;
        }
    }
}

function accord(obj){
    b=obj.parentNode;
    s=false;
    if(obj.className.indexOf(' checked') + 1) {
        s=true;
    }
    k='';
    for (var i=0; i < b.children.length; i++){
        b.children[i].className=b.children[i].className.replace(' checked','');
    }
    if(!s){
        obj.className+=' checked';
    }
}

function setchecked(obj){
    b=obj.parentNode;
    for (var i=0; i < b.children.length; i++){
        b.children[i].className=b.children[i].className.replace(' checked','');
    }
    obj.className+=' checked';
}
function setcheckedbyid(id){
    obj = document.getElementById(id);
    b=obj.parentNode;
    for (var i=0; i < b.children.length; i++){
        b.children[i].className=b.children[i].className.replace(' checked','');
    }
    obj.className+=' checked';
}
	
/*
function menuhover(obj){
	children=obj.childNodes;
	for (var key in children){
		if(children[key].className=='submenu'){
			var submenu = children[key];
			window.clearTimeout(p);
			if (submenu.style.height!='50px'){
				submenu.style.display='block';
				p=window.setTimeout(function(){fade(submenu,0,50,1,Math.random());},150);
			}
		}
	}
}

function menuout(divID){
	obj=nodeById(divID);
	children=obj.childNodes;
	for (var key in children){
		if(children[key].className=='submenu'){
			var submenu = children[key];
			window.clearTimeout(pp);
			pp=window.setTimeout (function(){fade(submenu,50,0,-1,Math.random());},10);
		}
	}
}
*/

/*
function fade(obj,startfade,endfade,key,rand){
	step=2;skey=obj.parentNode.id;
	if(!flag[skey])flag[skey]=false;
	if (flag[skey]==false||flag[skey]==rand){
		if (key==1)fadein=true;
		flag[skey]=rand;
		startfade=startfade+step*key;
		if (startfade*key>=endfade*key){
			obj.style.height=endfade+'px';flag[skey]=false; 
			checkmax();
			if(key==-1){obj.style.display='none';}
		} else {
			obj.style.height=startfade+'px';
			checkmax();
			setTimeout (function(){fade(obj,startfade,endfade,key,rand)},10);
		}		
	} else 	setTimeout (function(){fade(obj,startfade,endfade,key,rand)},10);
}
*/
ftime= new Object;
function hide (id){
    if(!(nodeById(id).className.indexOf(' hiddenchilds') + 1)){
        ftime[id]=window.setTimeout(function(){
            nodeById(id).className+=' hiddenchilds'
            },10);
    }
}

function showprj(id){
    window.clearTimeout(ftime[id]);
    var b=nodeById(id);
    b.className=b.className.replace(' hiddenchilds','');
}

function hideline(event){
    nodeById('line').style.display='none';
}
            
function getOffsetSum(elem) {
    var top=0, left=0
    while(elem) {
                            
        top = top + parseFloat(elem.offsetTop);
        left = left + parseFloat(elem.offsetLeft);
        elem = elem.offsetParent ;      
                
    }
    return Math.round(left)
}
var leftx = false;
var rightx = false;
function showline(event){
    var event = event || window.event;
    var tempx = 0;
    var div=nodeById('line');
    var datediv = nodeById('datepic');
    div.style.display='';
                               
    if ((event.clientX>=leftx)&(event.clientX<=rightx )) tempx =  event.clientX; // Координата x в пикселях
    if (event.clientX<leftx) tempx = leftx;
    if (event.clientX>rightx) tempx = rightx;
    div.style.left = tempx + 'px';
    tempx = tempx-72;
    datediv.style.left=tempx+'px';
//alert(tempx);
                               
                               
//  else div.style.display='none';
}
function datetextpic(datevalue,textvalue){
    var datediv = nodeById('datepic');
                
    var subimagediv = nodeById('subimage');
    datediv.innerHTML = datevalue;
    subimagediv.innerHTML = textvalue;
    datediv.style.display='';
    subimagediv.style.display='';
}
function overdatetextpic(){
    var datediv = nodeById('datepic');
    var subimagediv = nodeById('subimage');
    datediv.style.display='none';
    subimagediv.style.display='none';

}
function setleftx(){
    leftx= getOffsetSum(nodeById('digitsimage'));
    nodeById('line').style.left=leftx+'px';
    nodeById('line').style.display='';
    p = leftx-72;
    nodeById('datepic').style.left=p+'px';
    nodeById('datepic').style.display='';
    rightx= getOffsetSum(nodeById('digitsimage'))+nodeById('digitsimage').clientWidth-2;
     nodeById('leftmenu').onmousemove=function(e){
        showline(e)
    }
}

