

var _currentDropdown=false;
var _currentBar=false;
var _onbar=false,_onitem=false;
var DropdownMenu=Class.create();
function ddmWatch(){
	if(!_onbar && !_onitem){
	if(_currentDropdown)
	_currentDropdown.style.display='none';	
	if(_currentBar) _currentBar.className='bar';
}
setTimeout('ddmWatch()',300);
}

DropdownMenu.prototype={
    initialize:function(menuId,containerId,basePath,defaultBar,struct){
	var ddm_conf=struct;
        this.container=document.getElementById(containerId);
        this.basePath=basePath;
        var _div=document.createElement('div');
        _div.className='ddmenu';
        this.container.appendChild(_div);
        this._ph=_div;
        for(var i=0;i<ddm_conf.length;i++){
            if(i>0){
                var _sep=document.createElement('img');
                _sep.className='sep';
                _sep.src=this.basePath+'menu/css/img/marg.gif';
                _div.appendChild(_sep);
            }
        
            var div=document.createElement('div');
            div.className='bar';
            div.unselectable='on';
            if(!ddm_conf[i].TextMode){
                var img=document.createElement('img');
                img.src=basePath+'menu/img/'+ddm_conf[i].ImageNormal;
                //img.style.align='absmiddle';
                img.style.marginTop='5px';
                div.appendChild(img);
            }else{
                var span=document.createElement('span');
                span.appendChild(document.createTextNode(ddm_conf[i].ItemText));
                div.appendChild(span);
            }
            div.ItemLink=ddm_conf[i].ItemLink;
            div.Children=ddm_conf[i].Children;
		_div.appendChild(div);
            var me=this;
            Event.observe(div,'mouseover',function(e){_onbar=true;me.barOver(e);Event.stop(e)});
            div.onmouseout=function(e){_onbar=false;}
                    div.onclick=function(e){
                        var _url=this.ItemLink;
                        if(_url){
if(_url.indexOf('http://')>=0) window.location.href=_url;
else window.location.href=me.basePath+_url;
}
                    }

        }
		setTimeout('ddmWatch()',300);
    },
    barOver:function(e){
        var src=e.srcElement || e.target;
        while(src.tagName!='DIV') src=src.parentNode;
        this._createDropdown(src);
	if(_currentBar) _currentBar.className='bar';
	_currentBar=src;
	src.className='baron';
        if(_currentDropdown) _currentDropdown.style.display='none';
        if(src.Dropdown){            
            src.Dropdown.style.display='';
            _currentDropdown=src.Dropdown;
        }

    },
    _createDropdown:function(src){
        var _children=src.Children;
		var me=this;
        if(_children && _children.length>0){
            var _position=Position.cumulativeOffset(src);
            if(!src.Dropdown){
                var _dropdown=document.createElement('div');
                _dropdown.className='dropdown';
                _dropdown.unselectable='on';
                this.container.appendChild(_dropdown);
                for(var i=0;i<_children.length;i++){
                    var _item=document.createElement('div');
                    _item.className='menuitem';
                    _item.onmouseover=function(e){this.className='menuitemOn';}
                    _item.onmouseout=function(e){this.className='menuitem';}
                    var _span=document.createElement('span');
                    _span.appendChild(document.createTextNode(_children[i].ItemText));
                    _item.appendChild(_span);
                    _dropdown.appendChild(_item);
                    _item.Link=_children[i].ItemLink;
                    _item.onclick=function(e){
                        var _url=this.Link;
                        if(_url){
if(_url.indexOf('https://')>=0 || _url.indexOf('http://')>=0) window.open(_url);
else window.location.href=me.basePath+_url;
}
                    }
                }
                src.Dropdown=_dropdown;
        		Event.observe(_dropdown,'mouseout',function(e){me.mouseout(e,_dropdown);});
			_dropdown.onmouseover=function(){_onitem=true;}

            }
            src.Dropdown.style.left=_position[0]-3+'px';
            src.Dropdown.style.top=_position[1]+26+'px';
        }        
    },   
    mouseout:function(e,target){
        var checkTarget=Event.isMouseLeaveOrEnter(e,target);
        if(checkTarget){
		_onitem=false;
        }
    },
 
    _ph:false,
    basePath:false
}
