/**
* Author:	Daniel Saidi (daniel.saidi@activesolution.se)
*
* This file contains global JavaScript functions that are
* used by the application.
*
* IMPORTANT: As soon as you begin to load new content via
* AJAX (e.g. with an UpdatePanel) and the new content is
* to use the JavaScript functionality (e.g. round corners),
* you need to execute the init functions again, since the
* new content will not have it applied. This is easily done
* by binding an async postback event to the ScriptManager
* and execute the init function with it. Since this is not
* needed as of now, I have not implementet it.
*/


/**
* Page load function.
*/
jQuery(function($) {
    initGui();
});

$(document).ready(function () {
    $('#helpdivs').hide();
    //Slide up and down on click
    $(".expandClick").click(function () {
        $(this).next(".expandable").slideToggle();
    });

    $('span[data-help], select[data-help], input[data-help], textarea[data-help]').bt({
        contentSelector: "$('#help-'+$(this).attr('data-help'))",
        padding: 10,
        spikeLength: 20,
        spikeGirth: 10,
        cornerRadius: 10,
        fill: 'rgba(255, 255, 255, .95)',
        strokeWidth: 2,
        strokeStyle: '#017AAC',
        cssStyles: { color: '#000' },
        shrinkToFit: false,
        trigger: ['hoverIntent'],
        hoverIntentOpts: {
            interval: 500,
            timeout: 100
        }
    });

    $('a[data-help]').bt({
     contentSelector: "$('#help-'+$(this).attr('data-help'))",
        padding: 10,
        spikeLength: 20,
        spikeGirth: 10,
        cornerRadius: 10,
        fill: 'rgba(255, 255, 255, 1.0)',
        strokeWidth: 2,
        strokeStyle: '#017AAC',
        cssStyles: { color: '#000' },
        shrinkToFit: true
    });
});

/**
* Initialize GUI related functionality - do this as soon as new DOM content is loaded
*/
function initGui()
{
    //Apply rounding to the main content box
    $("#main-border-shadow").corner("10px");
    $("#main-border").corner("8px");

    $(".main-header").corner("7px top");
    $("#main-footer").corner("7px bottom");

    //Apply a shadow to all boxes that uses the shadow css
    $(".shadow").dropShadow({ "opacity": 0.7, "top": 1, "left": 1, "blur": 0 });    
}

/**
* Show/hide an absolutely positioned element as a popup menu.
*/
function togglePopupMenu(targetElement, id) {
    $("#" + id).toggle();
    $("#" + id).css("top", (targetElement.offsetTop + 20) + 'px');
    $("#" + id).css("left", (targetElement.offsetLeft - 6) + 'px');
    return false;
}

/**
* Döljer en modal popup. Skall anropas på ModalPopupExtender.OnCancelScript för att undvika "flicker"   
*/
function HideModal(panel) {

    var objPanel = document.getElementById(panel);

    if (objPanel) {
        objPanel.style.display = 'none';
    }
}
