﻿jQuery(document).ready(function() {

    //select all the a tag with name equal to modal
    jQuery('a[name=modal]').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();

        //Get the A tag
        var id = jQuery(this).attr('href');
        //alert(id);
        //Get the screen height and width
        //var maskHeight = jQuery(document).height();
        var mh = parseInt(document.getElementById('mainBodyBot').offsetTop) + 207;
        var maskHeight = mh;
        //var maskWidth = jQuery(document).width();
        var maskWidth = document.body.clientWidth;
        //alert(maskWidth);
        //Set heigth and width to mask to fill up the whole screen
        jQuery('#mask').css({ 'width': maskWidth, 'height': maskHeight });
        //jQuery('#mask').css('top',  0);
        //jQuery('#mask').css('left', 0);

        //transition effect
        jQuery('#mask').fadeIn(1000);
        jQuery('#mask').fadeTo("slow", 0.8);

        //Get the window height and width
        var winH = jQuery(document).height();
        var winW = jQuery(document).width();

        //Set the popup window to center
        jQuery(id).css('top', winH / 2 - jQuery(id).height() / 2);
        jQuery(id).css('left', winW / 2 - jQuery(id).width() / 2);



        //transition effect
        jQuery(id).fadeIn(1000);


        //jQuery(id).css('width',  maskWidth/2);
        //jQuery(id).css('height', maskHeight/2);
    });

    //if close button is clicked
    jQuery('.window .close').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();

        jQuery('#mask').hide();
        jQuery('.window').hide();
    });

    //if mask is clicked
    jQuery('#mask').click(function() {
        jQuery(this).hide();
        jQuery('.window').hide();
    });

});