﻿$(document).ready(function () {
    //select all the a tag with name equal to modal
    $('a[rel=pop-up]').click(function (e) {
        $('#mask').hide();
        $('.window').hide();
        //Cancel the link behavior
        e.preventDefault();

        //Get the A tag
        var id = '#dialog';
        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        //Set heigth and width to mask to fill up the whole screen
        $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

        //transition effect		
        $('#mask').fadeIn(1000);
        $('#mask').fadeTo("slow", 0.8);

        $('#iFrame').attr('src', $(this).attr('href'));

        //$('#iFrame').height(800).width(600);

        setInterval("$('#iFrame').height($('#iFrame').contents().find('body').height()).width($('#iFrame').contents().find('body').width())", 1);

        $('iframe').load(function () {
            $(id).css("position", "absolute");
            $(id).css("top", ($(window).height() - $(id).height()) / 2 + $(window).scrollTop() + "px");
            $(id).css("left", ($(window).width() - $(id).width()) / 2 + $(window).scrollLeft() + "px");
            $(id).fadeIn(2000);
        });
        $(window).focus(function () {
            $(id).css("left", ($(window).width() - $(id).width()) / 2 + $(window).scrollLeft() + "px");
        })
        $(window).scroll(function () {
            //Set the popup window to center
            // $(id).css("top", ($(window).height() - $(id).height()) / 2 + $(window).scrollTop() + "px");
            $(id).css("left", ($(window).width() - $(id).width()) / 2 + $(window).scrollLeft() + "px");
        });
        //transition effect


        return false;
    });

    //if mask is clicked

    $('.window').submit(function () {
   $('#mask').hide();
   $('.window').hide();
  });
});
function Close() {
    $('#mask').hide();
    $('.window').hide();
    reload();
};


