﻿/// In this file
//  Variables:
//
//  Functions:
//      SetupDialog()
//      SetInnerHeight(elts, settings, callback)
//      PreloadImg(imageSrc)
//      ShowClassListing(classID)

function SetupDialog()
{
    $.nyroModalSettings({
        endFillContent : function (elts, settings)
        {
            if(typeof($('#InstituteVideoPlayer')[0]) != 'undefined')
            {
                $('#InstituteVideoPlayer')[0].style.display = 'none';  //Video player needs to be hidden while the modal dialog is open.
            }
        },
        endRemove : function (elts, settings)
        {
            if(typeof($('#InstituteVideoPlayer')[0]) != 'undefined')
            {
                $('#InstituteVideoPlayer')[0].style.display = '';   //Show the video player
            }
            
            $('#InstituteClassContent').empty();
            $('#InstituteClassContent')[0].style.height = '';
        },
        endShowContent: function(elts, settings) 
        { 
            SetInnerHeight (elts, settings, null);
        },
        endResize : function(elts, settings, callback) 
        { 
            SetInnerHeight (elts, settings, callback);
        }
    });
}

//Sets the height of the inner DIV
function SetInnerHeight(elts, settings, callback)
{		    
    var borderHeight = $('#bottomPopoutImage').height() + $('#topPopoutImage').height();
    var innerHeight = $('#nyroModalContent').height() - borderHeight;
    
    if(innerHeight > 0)
    {
        $('#InstituteClassContent')[0].style.height = innerHeight + 'px';
    }
}

//Preloads an image with the given source.
function PreloadImg(imageSrc) 
{
	var img = new Image();
	img.src = imageSrc;
}

//Shows the information about the specified class
function ShowClassListing(classID)
{
    $('#InstituteClassContent').empty();
    $('#InstituteClassContent').append($(classID).clone().html());
    
    //Set the bottom button link href
    $('#bottomPopoutImage')[0].href = $(classID + ' .linkInfo')[0].href;
    
    $('#CourseListingShow').nyroModalManual();
    
    return false;
}