﻿/// <reference name="MicrosoftAjax.debug.js" />
/// <reference name="MicrosoftAjaxTimer.debug.js" />
/// <reference name="MicrosoftAjaxWebForms.debug.js" />
/// <reference name="relationalUtility.debug.js" />

Type.registerNamespace('Website.Behavior');

Website.Behavior.clickByProxy_click = function () {
    /// <summary>
    /// Handles the click event of _clickByProxy divs
    /// </summary>
    Relational.Utility.clickInside(this,'_ClickTarget');
}

// waitButton_click
//
// Handles the click event of WaitButtonLinks
//
Website.Behavior.waitButton_click = function () {
    var waitButton = this;
    if (waitButton) {
        if (waitButton.tagName=='SPAN') waitButton=waitButton.parentNode;
        if(Relational.Utility.isPageValid(waitButton) == true) {
            // build DummyButton
            var dummyButton = document.createElement('a');
            dummyButton.className = waitButton.className + " DummyButton"; // Keep same CSS classes as original link
            dummyButton.style.cssText = waitButton.style.cssText; // Keep any styles set manually on the page
            dummyButton.innerHTML="<span></span><img src='../images/dingbats/spinner.tiny.2.gif' />Please wait...";
            waitButton.parentNode.insertBefore(dummyButton,waitButton); 
            // hide WaitButton
            Relational.Utility.changeClassName(waitButton,'Button','Hidden');
        }
    } 
}

// Rules that are needed on both the admin and public sites
Website.Behavior.globalRules =
{

    // Wire up _clickByProxy divs to click through to the a.ClickTarget element
    'div._ClickByProxy' : function(element){
        $addHandler(element, 'click', Website.Behavior.clickByProxy_click);
    },

    // Wait button behavior
    'a._WaitButton' : function(element){
        $addHandler(element, 'click', Website.Behavior.waitButton_click);
    },
    // gallery drag and drop (link)
    'a._Handle' : function(element){
        var payloadElementId = element.id.replace(new RegExp('Handle_Link_(\d*)'), 'Payload_$1');
        var context = { payloadElementId : payloadElementId };
        $addHandler(element, 'dragstart', Function.createCallback(Relational.Utility.onDragGalleryItem, context));
    },
    // gallery drag and drop (image)
    'img._Handle' : function(element){
        var payloadElementId = element.id.replace(new RegExp('Handle_Image_(\d*)'), 'Payload_$1');
        var context = { payloadElementId : payloadElementId };
        $addHandler(element, 'dragstart', Function.createCallback(Relational.Utility.onDragGalleryItem, context));
    }
}

/************************************** BEHAVIORS FOR THIS APPLICATION */

Website.Behavior.initialize = function(isAdminPage) {

    // This needs to be called at the bottom of every root master page.
    Relational.Utility.Rules.register(Website.Behavior.globalRules);
    Relational.Utility.Rules.apply();

    //SHANE: converted to rules above
    // Wire up payloads for drag-and-drop (document gallery, image gallery)
    //Relational.Behavior.wireUpDragPayloads('a','Handle','Handle_Link_(\d*)','Payload_$1'); // Drag-and-drop links
    //Relational.Behavior.wireUpDragPayloads('img','Handle','Handle_Image_(\d*)','Payload_$1'); // Drag-and-drop images
}

    



// Notify ScriptManager that this is the end of the script.
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();







