Shapka = function(){}

Shapka.noSound=true; //по умолчанию нет звука.
Shapka.firstSound=true;

//sound init
if(typeof(soundManager) != 'undefined'){
    soundManager.url = '/rfcommon/js/sound_manager/swf/';
    soundManager.debugMode = false;
    soundManager.onready(function(oStatus){
      if (oStatus.success) {
            Shapka.sound = soundManager.createSound({
                            id:'ding',
                            url:'/rfcommon/sound/gudok.mp3'
            }); 
      }
    });
}
Shapka.ding = function()
{
    if(typeof(soundManager) == 'undefined') return;

    if (this.firstSound)
    {
        this.firstSound=false;        
    }
    else
    {
        if (this.sound!=null)
        {
            this.sound.play();
        }   
    }    
} 
//sound end


Shapka.last_checksum = 0;
Shapka.checkForNewNotifications = function(){
    $.getJSON("/.include/notifications.php?last_checksum="+Shapka.last_checksum+"&rand="+Math.random(), function(data){
        setTimeout("Shapka.checkForNewNotifications()", 30000); //время обновления блока уведомлений
        if(data == "not modified") return;
        if (!Shapka.noSound)
        {
            Shapka.ding();
        }
        $("#notis_block").html(data['notis_block']);
        Shapka.last_checksum = data['checksum'];
        
    });
}

Shapka.clearAllNotifications = function(){   
    $.get("/.include/notifications.php?Act=clearAll&rand="+Math.random(), function(data){
        location.reload();
    });
}

MenuBehavior = function(){}
MenuBehavior.showed_blocks = []; 
MenuBehavior.bindMenu = function(link_id, div_id){
    var linkJq = $("#"+link_id);
    var divJq = $("#"+div_id);
    if(linkJq.length == 0 || divJq.length == 0) {
    	return false;
    }
    
    MenuBehavior.showed_blocks[div_id] = {is_mouse_over:false, timer_id:null};
    
    linkJq.bind("mouseover", function(e){
        MenuBehavior.showed_blocks[div_id].is_mouse_over = true;
        divJq.css("left", $(e.target).position().left);
        divJq.css("top", $(e.target).position().top + 18);
        divJq.show();
        return false;
    });
    
    divJq.bind("mouseover", function(e){
        MenuBehavior.showed_blocks[div_id].is_mouse_over = true;
    });
    
    var out = function(e){
        MenuBehavior.showed_blocks[div_id].is_mouse_over = false;
        clearTimeout(MenuBehavior.showed_blocks[div_id].timer_id);
        var timer_id = setTimeout("MenuBehavior.hideDiv('"+div_id+"')", 500);
        MenuBehavior.showed_blocks[div_id].timer_id = timer_id;
    };
    
    linkJq.bind("mouseout", out);
    divJq.bind("mouseout", out);
}
MenuBehavior.hideDiv = function(div_id){
    if(!MenuBehavior.showed_blocks[div_id].is_mouse_over)
        $("#"+div_id).hide();
}

