﻿/// <reference name="MicrosoftAjax.js"/>



Type.registerNamespace('TUI');



TUI.Splash = function() {}
TUI.Splash.globalDialogId = null; // Will be set by startup script
TUI.Splash.lastPostbackElement = null;
TUI.Splash.openDialog = function()
{
    var
        globalDialog = $find(TUI.Splash.globalDialogId),
        $globalDialog = $(globalDialog.get_element());
    
    $.getScript
    (
        "/includes/Js/JQuery/jquery.scrollfollow.js", 
        function() 
        {
            $globalDialog.find('input.next').scrollFollow({ speed: 300, offset: 200 });
            $globalDialog.find('input.previous').scrollFollow({ speed: 300, offset: 200 });
        }
    );
    
    $globalDialog.find('input.next, input.previous').click( TUI.Splash.pagingClick );
    Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(TUI.Splash.dialogLoaded);

    window.scrollTo(0, 0);
    globalDialog.show();
}
TUI.Splash.pagingClick = function(e)
{
    TUI.Splash.lastPostbackElement = e.target;
    
    if (TUI.Splash.lastPostbackElement.fadeInComplete)
    {
        // Click event will now bubble up and be detected by AJAX UpdatePanel
        TUI.Splash.lastPostbackElement.fadeInComplete = false;
    }
    else
    {    
        // Prevent click event from bubbling up to AJAX UpdatePanel
        e.stopPropagation();
        e.preventDefault();
    
        var
            $globalDialog = $($get(TUI.Splash.globalDialogId)),
            globalDialogHeight = $globalDialog.find('div.dialog-center-inner').height();
            
        $globalDialog.find('div.transition-overlay').height(globalDialogHeight).fadeIn('normal', function() { 
            TUI.Splash.lastPostbackElement.fadeInComplete = true;
            $(TUI.Splash.lastPostbackElement).trigger('click'); 
        });
    }
}
TUI.Splash.dialogLoaded = function(sender, args)
{
    var $globalDialog = $($get(TUI.Splash.globalDialogId));
    window.scrollTo(0, 0);
    $globalDialog.find('div.transition-overlay').fadeOut('normal');
}