/**
* General "replace image on hover" functionality (autorun on all
* .image-hover-enabled blocks)
*/
$(function() {
    $(".image-hover-enabled").hover(function() {
        $("img", this).hide();
        $("img.hover", this).show();
    }, function() {
        $("img", this).show();
        $("img.hover", this).hide();
    });
});

/**
* Text size in articles
*/

var clickCount = 0;
$(function() {
    $("#article .toolbar .size").click(function(event) {
        $('#article .toolbar .size').toggleClass('smaller');
        $('#article .resizable').toggleClass('resizable-large');


        if (clickCount % 2 == 0) {
            var text = $('#subheader .title2').text();
            $('#subheader em').remove();
            var emString = '';
            if (text != '')
                var emString = '<em>' + text + '</em>';
            $('#subheader').prepend(emString);
            $('#subheader em').addClass('title3').addClass('br3');
            event.preventDefault();
        }
        if (clickCount % 2 == 1) {
            var text = $('#subheader .title3').text();
            $('#subheader em').remove();
            var emString = '';
            if (text != '')
                var emString = '<em>' + text + '</em>';
            $('#subheader').prepend(emString);
            $('#subheader em').addClass('title2').addClass('br2');
            event.preventDefault();
        }
        clickCount++;

        $(".resizable ignore").remove(); // hack: to remove 'old' red panel over subheader element
        DD_RoundiesRoundify();

        event.preventDefault();
    });
});

/**
* General "text-tip" function for input fields
*/
function InitializeTextTips() {
    function FocusHandler() {
        var input = $(this); // clear textbox on focus
        if (input.val() == input.attr('title'))
            input.val('');
    }
    function BlurHandler() {
        var input = $(this); // reset textbox to title text when focus is
        // lost
        if (input.val() == '')
            input.val(input.attr('title'));
    }
    $('input.tipEnabled').unbind('focus', FocusHandler).unbind('blur', BlurHandler)
        .focus(FocusHandler)
        .blur(BlurHandler)
        .blur(); // set initial value (on load)
}
$(InitializeTextTips);

/**
* Function for handling the dropdown menu (main menu) (autorun)
*/
$(function() {
    $('#head .menudd').hide();
    $('#head .menu').mouseleave(function() {
        $('#head .menudd').hide();
    });
    $('#head .menuItem').mouseleave(function() {
        if ($.browser.msie) { }
        else {
            $('#head .menudd').hide();
        }
    });

    $('#head .menuItem').hover(function() {
        $('#head .menudd').hide();
        $(' .menudd', this).show();
    })

    $("div[class^='separator']").hover(function() {
        $('#head .menudd').hide();
    });
});

/**
* Method used to handle popups and external links (autorun)
*/
$(function() {
    // function for processing popup links
    $("a.popup").click(function(event) {
        var classNames = this.className.split(' ');
        var popupName = null;
        for (var index in classNames) {
            var key = classNames[index];
            if (popupClasses[key] != null) {
                popupName = key;
                break;
            }
        }
        if (popupName == null)
            popupName = "standard";
        // open new window
        var popup = window.open(this.href, popupName,
				popupClasses[popupName]);
        if (window.focus)
            popup.window.focus();
        // prevent browser from following link
        event.preventDefault();
        return false;
    });
    // functions for processing external links
    $("span.external_link a").attr("target", "_blank");
    $("a.external").attr("target", "_blank");
    $("a.blank").attr("target", "_blank");
});
