
var timeout                                             = 500;
var closetimer                                          = 0;
var ddmenuitem                                          = 0;

$(document).ready(function(){
    $("a.theBookmark").click(function(e){
        e.preventDefault(); // this will prevent the anchor tag from going the user off to the link
        var bookmarkUrl = this.href;
        var bookmarkTitle = this.title;

        if (window.sidebar) { // For Mozilla Firefox Bookmark
            window.sidebar.addPanel(bookmarkTitle, bookmarkUrl,"");
        } else if( window.external || document.all) { // For IE Favorite
            window.external.AddFavorite( bookmarkUrl, bookmarkTitle);
        } else if(window.opera) { // For Opera Browsers
            $("a.theBookmark").attr("href",bookmarkUrl);
            $("a.theBookmark").attr("title",bookmarkTitle);
            $("a.theBookmark").attr("rel","sidebar");
        } else { // for other browsers which does not support
            return false;
        }

        return true;
    });
});

// open hidden layer
function mopen(id)
{
        // cancel close timer
        mcancelclosetime();

        // close old layer
        if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';

        // get new layer and show it
        ddmenuitem = document.getElementById(id);
        ddmenuitem.style.visibility = 'visible';

}
// close showed layer
function mclose()
{
        if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

// go close timer
function mclosetime()
{
        closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
        if(closetimer)
        {
                window.clearTimeout(closetimer);
                closetimer = null;
        }
}

// close layer when click-out
document.onclick = mclose;

function openMenuItem(theId, linkto) {
    if ( !$("#subs_" + theId).is(":visible") ) {
        $.ajax({type: "POST",
                url: "doActions.php",
                async: false,
                data: "action=choose-category&data="+theId,
                success: function(data) {
                    $("#subs_" + theId).show();
                    if ( linkto )
                        window.location.href = "category.php?category="+theId;
                }
        });
    }
    else {
        $.ajax({type: "POST",
                url: "doActions.php",
                async: false,
                data: "action=choose-category&data=-1",
                success: function(data) {
                    $(".hiddensubs").hide();
                    if ( linkto )
                        window.location.href = "category.php?category="+theId;
                }
        });
    }
}
