CMMC=function(){
  this.c={waitTime:2000};
	  this.init=function(tree,aActiveIDX){
				this.bWork=true;
				document.onmousedown=function() { window.CMM.hideMenu(); }
			    this.aActiveIDX=aActiveIDX;
			    this.tree=tree;//alert(this.tree.length);    
		    };
		    this.start=function(){
		    this.e=new CMA();
		    this.setup(this.tree,[]);
		    var em=new CME('cm-cont');
			if(!em.ua.ie){
				em.r.style.position='relative'
			}
		    }
	  //call by html element
	  this.sl=function(aIds){
				if(!this.bWork)return;
		    //hide levels greater than current level
		    if(this.showedLevel)this.hhl(aIds.length-1);
		    this.rt();
		    this.showedLevel=[];
		    for(var i=0;i<(aIds.length);i++){
			    this.showedLevel[i]=aIds[i];
			    };//alert(aIds+' '+this.showedLevel)
		    //recursive by levels
		    var i,j,cs,l;
		    cs=this.ids2set(aIds);
		    //alert(cs);
		    //by set
		    l=aIds.length;
		    for(j=0;j<cs.length;j++){
			    aIds[l]=cs[j];//alert(aIds)
			    this.showElement(aIds);//@todo ,i*100
			    };
		    };
	  this.showElement=function(aIds,to){
						    
		    var hasSibling=false;//alert(typeof(aIds));
		    var aPar=[];
		    for(var i=0;i<(aIds.length-1);i++){//valid copy construct - break refrence
			    aPar[i]=aIds[i];
			    };//alert(aIds+' '+aPar)
		    //alert(this.vConf+' '+(aIds.length-1))
		    //alert(this.idForA(aPar))
		    var parent=new CME(this.idForA(aPar));
		    var elId=this.idForA(aIds)
		    var element=new CME(elId);		
		    //have prev. sibling
		    if(aIds[aIds.length-1]>0){//alert()
			    hasSibling=true;
			    var sIds=[];
			    for(var i=0;i<aIds.length;i++){
				    sIds[i]=aIds[i];
				    };
			    sIds[sIds.length-1]-=1;
			    prevSibling=new CME(this.idForA(sIds));
			    var y=prevSibling.getY()+prevSibling.getHeight();//alert(prevSibling.getOffsetY()+' '+prevSibling.getHeight()+' '+this.vConf[aIds.length-1].y_spacing)
			   //if(top.cDebug)cDeb.println('cmm,  ps '+prevSibling.getY());
			   //logDebug('prev. sibling '+sIds+' '+y) 
						}else if(aIds.length==2){//fl
			    			var y=20//parent.getOffsetY()+parent.getHeight()+this.vConf[aIds.length-1].y_offset;
			    }
		    else{
							    var y=parent.getOffsetY();//alert(parent.getOffsetY()+' '+parent.getHeight()+' '+this.vConf[aIds.length-1].y_offset)

			}
		    //first level
		    if(aIds.length==2){
				var offsets={l0:0,l1:100,l3:312}
			    var x=offsets["l"+aIds[0]]
				
			    }
		    else{
			    //var x=parent.getOffsetX()+parent.getWidth()+this.vConf[aIds.length-1].x_offset;//alert(parent.getX()+' '+parent.getWidth()+' '+this.vConf[aIds.length-1].x_offset);
		    }
			//alert(x+' '+y)
		    element.setX(x);
		    
		    element.setY(y);//logDebug(element.getY()+' '+element.getOffsetY());
		    if(typeof(to)=='number'){
		    setTimeout('CMM.showElLater("'+elId+'")',to);//Cant wark - no hide if quickly
		    }
		    else{
		    //if(top.cDebug)cDeb.println(element.ua.opera);
		    //if(element.ua.opera)element.setVisible(true);
		    }
		    };
		    this.showElLater=function(elId){
		    var element=new CME(elId);
		    element.setVisible(true);
		    }
	  this.hideElement=function(aIds){//alert(this.idForA(aIds))
		    var e=new CME(this.idForA(aIds));
		    //e.setVisible(false);
		    e.setX(-2000)
		    };
	  this.hideLevel=function(ids){//alert(ids)
		    var set=this.ids2set(ids);
		    var l=ids.length;
		    for(i=0;i<set.length;i++){
			    ids[l]=set[i];
			    this.hideElement(ids);
			    };
		    };
	  this.hideMenu=function(limit){//alert('hideMenu')
				if(!this.bWork)return;
		    if(!this.showedLevel)return;
		    //alert(this.showedLevel)
		    var downLimit=typeof(limit)=='undefined'?0:limit;
		    for(j=this.showedLevel.length-1;j>=downLimit;j--){//from leaf
			    var cIds=[];
			    for(i=0;i<=j;i++){
				    cIds[i]=this.showedLevel[i];//@todo maybe in soft transition reverse queue
				    };//alert(cIds)
			    this.hideLevel(cIds);
			    };
		    };
	  this.st=function(){//return//@todo undefined
				if(!this.bWork)return;
		    this.tId=setTimeout('CMM.hideMenu()',this.c.waitTime);
		    };
	  this.rt=function(){
		    clearTimeout(this.tId);
		    this.tId=null;
		    };
	  this.idForA=function(aIds){//alert(typeof(aIds))
		    return 'cm-'+aIds.join('-');
		    };
	  /**
	  *ids array to set
	  *have aray of positions in tree
	  *trans. this to set for this leaf
	  */
	  this.ids2set=function(aIds){
		    var cs=this.tree[aIds[0]];//alert(cs.length);
		    for(i=1;i<aIds.length;i++){
			    cs=cs[aIds[i]];//alert(aIds[i])
			    };
		    var ret=[];
		    for(i=0;i<cs.length;i++){
			    ret[i]=i;
			    };
		    return ret;
		    };
	  this.positions=[];
			
	  /**
	  *Setup html elements
	  *@param a array
	  *@param p array
	  */
	  this.setup=function(a1,p1){//alert(a1+' '+p1);
		    var a=[];for(var i=0;i<a1.length;i++){a[i]=a1[i];};
		    var p=[];for(var i=0;i<p1.length;i++){p[i]=p1[i];};
		    var l=p.length;//alert(a.length);
						var tw;
		    for(i=0;i<a.length;i++){
			    p[l]=i;//alert('p in '+p);
			    //active?
			    var bActive=true;
			    for(var j=0;j<p.length;j++){
				    if(p[j]!==this.aActiveIDX[j]){
					    bActive=false;
					    break;
					    }
				    }
			    var idStr=p.join('-');//alert(idStr);
			    var idsA=p.join(',');
								var ov=!bActive?";window.CMM.ov(this,"+(p.length-1)+")":'';//alert(idsA+' '+ov);
								var ou=!bActive?";window.CMM.ou(this,"+(p.length-1)+")":'';
			    var aEl=document.getElementById('cm-a-'+idStr);
			    //numery oferty
					/*		var reNr=/^([\d\-]*) /ig;
			    var res=reNr.exec(aEl.innerHTML)
			    if(res!=null){
			    if(bActive)
			    aEl.innerHTML='<span style="color:#d92727" class="active-nr">'+RegExp.$1+'</span> '+aEl.innerHTML.substr(res.lastIndex)
			    else
			    aEl.innerHTML='<span style="color:#d92727" class="no-active-nr">'+RegExp.$1+'</span> '+aEl.innerHTML.substr(res.lastIndex)
			    }*/
			    /*if(bActive)
			    aEl.class=aEl.class+'-active';*/
			    if(bActive){
			    //alert(aEl.className)
			    aEl.className=aEl.className+'-active';
			    
			    //alert(aEl.className)//aEl.outerHTML='<div class="cm-div-e-active">'+aEl.outerHTML+'</div>'
			    //alert(aEl.outerHTML)
			    }

						//if(top.cDebug)cDeb.println(aEl.innerHTML+' '+tw+ ' '+maxW);
			    //if(idStr=='1-1-7'){alert(aEl.innerHTML)}
			    aEl.onmouseout=new Function("window.CMM.st()"+ou);
			    aEl.onmousedown=new Function("e","try{window.event.cancelBubble=true}catch(er){try{e.stopPropagation()}catch(er2){}}");
							if(typeof(a[i])=='object'){//have child //alert(p);
								aEl.onmouseover=new Function("window.CMM.sl(["+idsA+"])"+ov);
				   // var p2=[];for(var j=0;j<p.length;j++){p2[j]=p[j];};
				    this.setup(a[i],p);
							}else{
				    aEl.onmouseover=new Function("window.CMM.hhl("+(p.length-1)+")"+ov);
								aEl.onclick=new Function("window.CMM.de()");
							}
			    };

		    };
	  /**
	  *@param level above that hide descendant
	  */
	  this.hhl=function(level){//alert(level)
				if(!this.bWork)return;
		    //	if(this.showedLevel.length>level)this.hideLevel(this.showedLevel);
		    this.hideMenu(level);
		    this.rt();
		    };
	  this.ov=function(rA,l){//@todo check how level
		    //this.aActiveIDX
		    //this.e.ov(rA,l);
		    };
	  this.ou=function(rA,l){//@todo check how level
		    //this.e.ou(rA,l);
		    };
						this.de=function(){
							this.bWork=false;
						};
	  };


