/* Script by http://dxSoft.ru/ */

// главное меню
// список элементов меню
var dxtopmenu_elemslist = Array();


// один главный элемент меню (sub_id - панель с подменю)
var dxtop_menu_elem = function(menuelem_id, sub_id, is_selected)
{
    this.Init(menuelem_id,sub_id,is_selected);
}

dxtop_menu_elem.prototype=
{
    Init:function(menuelem_id,sub_id,is_selected)
    {                
        this.is_selected = is_selected
        this.transparence = 100;
        // как долго будет висеть, пока не начнет затухать
        this.fading_pause = 500;
        // для таймера
        this.fading_interval = 10;
        this.fading_speed = 5;
        this.timer = null;
        this.menuelem = dxsoft_library.GetElement(menuelem_id);
        this.subdiv = dxsoft_library.GetElement(sub_id);        
        dxsoft_library.DoTask(this.menuelem,dxsoft_library.CreateMethod(this,this.OnMenuOver),"mouseover");
        dxsoft_library.DoTask(this.menuelem,dxsoft_library.CreateMethod(this,this.OnMenuClick),"click");
        dxsoft_library.DoTask(this.menuelem,dxsoft_library.CreateMethod(this,this.OnMenuOut),"mouseout");
        // подменю может и не быть       
        if(this.subdiv)
        {            
            dxsoft_library.DoTask(this.subdiv,dxsoft_library.CreateMethod(this,this.OnMenuOver),"mouseover");
            dxsoft_library.DoTask(this.subdiv,dxsoft_library.CreateMethod(this,this.OnMenuOut),"mouseout");
        }
    },
    // показываем подменю
    OnMenuOver:function(ev)
    {   
        if(this.timer)
            clearTimeout(this.timer);
        this.transparence = 100;     
        if(this.menuelem.className!='mn_sel')
            this.menuelem.className = 'mn_sel';
        /*if(this.subdiv)      
        {
            this.subdiv.style.display = 'inline';               
            dxsoft_library.SetOpacity(this.subdiv,100);
        }*/
    },
    OnMenuClick:function(ev)
    {
        for(var i=0;i<dxtopmenu_elemslist.length;++i)
            if(dxtopmenu_elemslist[i]!=this)
                dxtopmenu_elemslist[i].Stop();
        if(this.subdiv)      
        {
            this.subdiv.style.display = 'inline';               
            dxsoft_library.SetOpacity(this.subdiv,100);
        }
        
    },
    OnMenuOut:function(ev)
    {   
        if(this.timer)
            clearTimeout(this.timer);
        this.timer = setTimeout(dxsoft_library.CreateMethod(this,this.OnStartFading),this.fading_pause);
    },
    // начинаем убирать подменю
    OnStartFading:function()
    {
        if(!this.is_selected)
        {
            this.menuelem.className = 'mn_unsel';
            if(this.subdiv )
                this.timer = setTimeout(dxsoft_library.CreateMethod(this,this.OnFading),this.fading_interval);
            else
                this.ShowSelected();
        }
    },
    // убираем полностью
    OnFading:function()
    {
        dxsoft_library.SetOpacity(this.subdiv,this.transparence);        
        this.transparence-=this.fading_speed;
        if(this.transparence>0)
            this.timer=setTimeout(dxsoft_library.CreateMethod(this,this.OnFading),this.fading_interval);
        else
        {
            this.subdiv.style.display = 'none';        
            this.timer = null;  
            this.ShowSelected();
        }
    },
    // резко убираем подменю (без затухания)
    Stop:function()
    {
        if(this.timer)
            clearTimeout(this.timer);
        this.menuelem.className = 'mn_unsel';
        if(this.subdiv)
            this.subdiv.style.display = 'none'; 
        this.timer = null;
    },
    ShowSelected:function()
    {
        for(var i=0;i<dxtopmenu_elemslist.length;++i)            
            if(dxtopmenu_elemslist[i].is_selected)
            {     
                dxtopmenu_elemslist[i].menuelem.className="mn_sel";
                if(dxtopmenu_elemslist[i].subdiv)
                {
                    dxtopmenu_elemslist[i].subdiv.style.display = 'inline';               
                    dxsoft_library.SetOpacity(dxtopmenu_elemslist[i].subdiv,100);
                }
                break;
            }
    }
}

// контрол для выбора языка
var dxlang_selecter = function(selecter_id,lang_list_id)
{
    this.Init(selecter_id,lang_list_id);
}

dxlang_selecter.prototype = {
    Init:function(selecter_id,lang_list_id)
    {        
        this.selecter = dxsoft_library.GetElement(selecter_id);
        this.lang_list = dxsoft_library.GetElement(lang_list_id);
        this.transparence = 0;
        this.fading_interval = 10;
        this.show_speed = 5;
        dxsoft_library.SetOpacity(this.lang_list,0);
        dxsoft_library.DoTask(this.selecter,dxsoft_library.CreateMethod(this,this.OnLangOver),"mouseover");
        dxsoft_library.DoTask(this.selecter,dxsoft_library.CreateMethod(this,this.OnLangOut),"mouseout");
        dxsoft_library.DoTask(this.lang_list,dxsoft_library.CreateMethod(this,this.OnLangOver),"mouseover");
        dxsoft_library.DoTask(this.lang_list,dxsoft_library.CreateMethod(this,this.OnLangOut),"mouseout");
    },
    OnLangOver:function()
    {                
        if(this.timer)
            clearTimeout(this.timer);
        if(this.transparence<100)
        {
            this.transparence = 100;
            dxsoft_library.SetOpacity(this.lang_list,100);  
            this.lang_list.style.display = 'block';
        }
    },
    OnLangOut:function()
    {
        if(this.timer)
            clearTimeout(this.timer);    
        if(this.transparence>0)
        {
            this.show_speed = -5;        
            this.timer=setTimeout(dxsoft_library.CreateMethod(this,this.OnFading),this.fading_interval);
        }   
    } ,
    OnFading:function()
    {
        this.transparence+=this.show_speed;
        this.timer = null;        
        if(this.transparence<=0)
        {
            this.transparence = 0;
            dxsoft_library.SetOpacity(this.lang_list,0);
            this.lang_list.style.display = 'none';            
        }
        else
        {
            dxsoft_library.SetOpacity(this.lang_list,this.transparence);
            this.timer=setTimeout(dxsoft_library.CreateMethod(this,this.OnFading),this.fading_interval);
        }
    }
}
