function customAlert(text, icon){
    var icons = new Array();
    icons[1] = 'icon_info';
    icons[2] = 'icon_warning';
    icons[3] = 'icon_error';

    var alts = new Array();
    alts[1] = 'Информация';
    alts[2] = 'Предупреждение';
    alts[3] = 'Грешка';

    if(icon == undefined || parseInt(icon) < 1 || parseInt(icon) > 3){
        icon = 3;
    }

    var iconImage = icons[icon];
    var iconAlt = alts[icon];

    var alert = '';
    alert += '<div id="alert" class="modalform regtransparent">';
    alert += '<div class="regbox" style="height: 240px; top: 50%; margin: -120px 0 0 -240px;">';
    alert += '<div class="alertboxtop"></div>';
    alert += '<div class="alertboxmiddle">';
    alert += '<div class="registration">';
    alert += '<span class="img">';
    alert += '<img src="/images/themes/default/'+iconImage+'.png" width="30" height="30" alt="'+iconAlt+'"/>';
    alert += '</span>';
    alert += '<span class="message">';
    alert += text;
    alert += '</span>';
    alert += '</div>';
    alert += '<div class="clear"></div>';
    alert += '</div>';
    alert += '<div class="alertboxbottom">';
    alert += '<div class="registration"><button id="alert_ok" value="draft" name="commit" type="submit">O.K.</button></div>';
    alert += '</div>';
    alert += '</div>';
    alert += '</div>';
    $("body").append($(alert));

    $("#alert_ok").focus();
    $("#alert_ok").live('click', function(){
       $("#alert").remove();
       return false;
    });
    return true;
}

function notifications(){
    $.get('/index/ajax_getNotifications/nocache/'+new Date().getTime()+'/', function(data){
        $('#notifications-container').html("");
        var notificationsInfo = $.parseJSON(data);
        if(notificationsInfo.error_status == 0){
            for(var index in notificationsInfo.notifications){
                var notification = notificationsInfo.notifications[index];
                var images = new Array();
                images[1] = 'RightBoxBIGLinksBGLeague';
                images[2] = 'RightBoxBIGLinksForum';
                images[3] = 'RightBoxBIGLinksAlbums';
                images[4] = 'RightBoxBIGLinksForum';
                var classname = notification.active == 0 ? ' class="viewed"' : '';
                var elm = $('<div class="notification_entry"><a href="'+notification.link+'"' + classname + '><img src="/images/themes/new/'+images[notification.type]+'.png" alt="" title="" /><p>' + notification.text + '</p></a></div>');
                $('#notifications-container').append(elm);
                $('#notifications-btn b').html(notificationsInfo.count);
            }
        }
    });
}

$(document).ready(function(){
    //notifications
    if($('#Taskbar #notifications-btn').length == 1){
        notifications();
        setInterval('notifications()', 20*1000);
    }

    $('#taskbar-arrow-collapse').bind('click', function(){
        var taskbar = $('#Taskbar');
        var w = parseInt($('#taskbar-arrow-expand').width()) + parseInt($('#notifications-btn').width());
        taskbar.find('td').hide();
        taskbar.animate({'width': w}, 'normal', function(){taskbar.find('.Moves.expand, td.Notifications').show()});

        return false;
    });

    $('#taskbar-arrow-expand').bind('click', function(){
        var taskbar = $('#Taskbar');
        var w = 2*parseInt($('#taskbar-arrow-expand').width()) + parseInt($('#notifications-btn').width());
        //taskbar.find('td').hide();
        taskbar.animate({'width': '100%'}, 'normal', function(){
            taskbar.find('td').show();
            taskbar.find('.Moves.expand').hide();
        });
        return false;
    });
    
    $('#notifications-btn').bind('click', function(){
        return false;
    });

    $('#notifications-btn').bind('mouseover', function(){
        $('#notifications-area').show();
    });

    $('#notifications-btn').bind('mouseout', function(event){
        if($(event.relatedTarget).parents('div#notifications-area').length == 0){
            $('#notifications-area').hide();
        }
    });

    $('div#notifications-area').bind('mouseout', function(event){
        if($(event.relatedTarget).attr('id') != 'notifications-btn' && $(event.relatedTarget).parents('div#notifications-area').length == 0){
            $(this).css('display', 'none');
        }
    });

    $('#menu-btn').bind('mouseover', function(){
        $(this).parent().nextAll('div.TaskbarMenu-area').show();
    });

    $('#menu-btn').bind('mouseout', function(event){
        if($(event.relatedTarget).parents('div.TaskbarMenu-area').length == 0){
            $(this).parent().nextAll('div.TaskbarMenu-area').hide();
        }
    });

    $('#Taskbar div.TaskbarMenu-area').bind('mouseout', function(event){
        if($(event.relatedTarget).attr('id') != 'menu-btn' && $(event.relatedTarget).parents('div.TaskbarMenu-area').length == 0){
            $(this).css('display', 'none');
        }
    });

});
