$(document).ready(function() {

    // Bookmarks

    var activeclass = 'active';
    var hidingclass = 'hidden';

    //------------------------------------------------------------------------//

    var $bookmarks = $('.bookmarks:not(.disable)');

    $.each($bookmarks, function() {

        var $parent = $(this);
        var $links = $parent.find('li a');

        if($parent.hasClass('hover'))
            eventtype = 'mouseenter mouseleave';
        else
            eventtype = 'click';

        $.each($links, function() {

            var $link = $(this);

            try {
                // IE strange error handling
                if($link.attr('href') == '#')
                    var $target = $();
                else
                    var $target = $($link.attr('href'));
            } catch(e) {
                var $target = $();
            }

            // If the target exists
            if($target.length) {

                // Hide all bookmarks except first
//                if(!$link.closest('li').is(':first-child'))
//                    $target.addClass(hidingclass);
//                else
//                    $link.addClass(activeclass);

                // Binding with click event
                $link.bind(eventtype, function() {

                    $link = $(this);

                    $sibling = $link.closest('ul').find('.' + activeclass);

                    // Hide bookmark from active sibling and remove active class
                    $($sibling.attr('href')).addClass(hidingclass);
                    $sibling.removeClass(activeclass);

                    // Display target bookmark and add active class
                    $($(this).attr('href')).removeClass(hidingclass);
                    $link.addClass(activeclass);

                    return false;
                });

            } else { // The target doesn't exist

                $link.bind(eventtype, function() {
                    return false;
                });

            }

        });

    });

});
