﻿// initial hides
$('.hideLate').hide();
$('.showLate').show();

// Set up for displaying modal dialogs
$('a[name=modal]').click(function(e) {

    $('html, body').animate({ scrollTop: 0 }, 'slow');

    // Prevent the default link behavior of navigation so we can use the link to show the Window
    e.preventDefault();

    // Determine which href was clicked if it was in fact an href (though this demo as only one.)
    var id = $(this).attr('href');

    // Determine browser windows dimensions.
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();

    // Set dimensions for the mask to opaque the screen when the modal window is displayed.
    $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

    // Make the Window Opaque 
    //$('#mask').fadeIn("fast");
    $('#mask').fadeTo("slow", 0.8);

    //Get the window height and width
    var winH = $(window).height();
    var winW = $(window).width();

    // Set the Modal Window's dimensions to center in the browser window.
    $(id).css('top', winH / 2 - $(id).height() / 2);
    $(id).css('left', winW / 2 - $(id).width() / 2);

    // Show the Modal Window
    $(id).fadeIn("fast");
});

// Handle Close Button Click Event
$('.window .close, .modalClose').click(function(e) {

    // Cancel the link behavior
    e.preventDefault();
    $('#mask').fadeOut('slow');
    $('.window').fadeOut('fast');
});

// The user clicks OUTSIDE the Modal Window and the window will be closed without save.
$('#mask').click(function() {
    $(this).fadeOut("slow");
    $('.window').fadeOut("slow");
});


// For vid
$(function() {
    $.nyroModalSettings({
        processHandler: function(settings) {
            var from = settings.from;
            if (from && from.href && from.href.indexOf('http://www.youtube.com/watch?v=') == 0) {
                $.nyroModalSettings({
                    type: 'swf',
                    height: 355,
                    width: 425,
                    url: from.href.replace(new RegExp("watch\\?v=", "i"), 'v/')
                });
            }
        }
    });
});