﻿$(document).ready(
	function() {
	    setLogoEffect();
	    setShadows();
	    setAutoSubmit();
	    setHelpTags();
	});

function setLogoEffect() {
    // Applies a hover effect to the main logo in the header
    $('#mainLogo a').css({ 'background-position': '0 0' }).hover(function() {
        $(this).append('<div></div>');
        $('#mainLogo a').children('div').hide().fadeIn(300);
    }, function() {
        $('#mainLogo a').children('div').fadeOut(400, function() { $(this).remove(); });
    });
}

function setShadows() {
    $('.shadow').each(function() { surroundWithShadow($(this)); });
    if ($('#dnn_ControlPanel table').length > 0) surroundWithShadow($('#dnn_ControlPanel'));
}

function surroundWithShadow(what) {
    var setWidths = false;
    what.wrap('<div class="outside-left" ' + (setWidths ? 'style="width:' + what.width() + 'px"' : '') + '></div>')
            .wrap('<div class="outside-right"></div>')
            .addClass('outside-inside')
            .parent() //returns the .outside-right element
            .prepend('<div class="outside-right-top"></div><div class="outside-right-top-corner"></div>')
            .parent() //returns the .outside-left element
            .prepend('<div class="outside-left-top"></div><div class="outside-left-top-corner"></div>')
            .after('<div class="outside-base" ' + (setWidths ? 'style="width:' + (what.width() + 30) + 'px"' : '') + '><div class="outside-base-left"></div><div class="outside-base-middle"></div><div class="outside-base-right"></div></div>');
}


function setAutoSubmit() {
    // Assigns a keypress listener to any text boxes on the page, to execute the action of the textbox's
    // associated link button when the user hits Enter in the box. Set the association using the REL property
    // on the textbox control. This must be done from server-side script, to get the final rendered HTML
    // ID of the button. Like so:
    //      txtSearch.Attributes.Add("rel", btnSearch.ClientID)

    $('#page_wrap input[type="text"]').each(function() {
        $(this).keypress(function(e) {
            if (e.which == 13 || e.which == 10) {
                var relBtn = '#' + $(this).attr('rel');
                if (relBtn != '#') {
                    if ($(relBtn).length > 0) {
                        location = $(relBtn).attr('href');
                        return false;
                    }
                }
            }
        });
    });
}

function setHelpTags() {

    $('.helptag').each(function() {
        // Hides any help tag elements and replaces them with a small icon to show the text on click.

        var helpText = $(this).html();
        $(this)
            .text('?')
            .append('<span class="helptag-popup">' + helpText + '</span>')
            .attr('class', 'button')
            .css({ 'position': 'relative', 'padding': '3px 5px' })
            .click(function() {
                var popup = $(this).children('.helptag-popup');
                if (popup.css('display') == 'none') popup.css('display', 'block');
                else popup.css('display', 'none');
            });

    });
    $('.helplink').each(function () {
        // Similarly, the helplink class on a DL element will put the DT (question) and DD (answer) into
        // a more unobtrusive Javascript-enabled control.

        $(this).children('.helplink-a').addClass('helptag-popup');
        
        $(this)
            .css('position', 'relative')
            .children('.helplink-q').click(function () {
                var popup = $(this).siblings('.helptag-popup');
                if (popup.css('display') == 'none') popup.css('display', 'block');
                else popup.css('display', 'none');
            });
        //*/
    });
    
}
