﻿/// <reference path="jquery-intellisense.js"/>

// modal, this launches the modal
$(document).ready(function() {	


	//select all the a tag with name equal to modal
	$('a[name=modal]').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();
		//Get the A tag
		var id = $(this).attr('href');
        //var id = "#pressWindow";
        
        
		//Get the window height and width
		var winH = $(document).height();
		var winW = $(document).width();

         
         //Set heigth and width to mask to fill up the whole screen
	    $('#mask').css({'width': '100%','height': '100%'});
		
    
       $('#mask').css({'width': ($(document).scrollLeft() + winW) + 'px','height': ($(window).scrollTop() + winH) + 'px'});

		//transition effect		
		$('#mask').fadeTo(0,0.75);	
		$('#mask').show();	
		


		//Set the popup window to center
		var topValue = winH/2-$(id).height()/2;
		var leftValue = winW/2-$(id).width()/2;
		if (topValue < 0) topValue = 0;
		if (leftValue < 0) leftValue = 0;
		
		$(id).css('top',  topValue);
		$(id).css('left', leftValue);
		
		$("#loader").css('top',  winH/2-$("#loader").height()/2 + "px");
		$("#loader").css('left', winW/2-$("#loader").width()/2) + "px";

	    $(window).bind('resize', function() {
	        $('#mask').css({'width': "0px",'height': "0px"});

	        var winH = $(document).height();
		    var winW = $(document).width();
		  $('#mask').css({'width': ($(document).scrollLeft() + winW) + 'px','height': ($(window).scrollTop() + winH) + 'px'});

		    var topValue = winH/2-$(id).height()/2;
		    var leftValue = winW/2-$(id).width()/2;
		    if (topValue < 0) topValue = 0;
		    if (leftValue < 0) leftValue = 0;
    		
		    $(id).css('top',  topValue);
		    $(id).css('left', leftValue);
		    
		    $("#loader").css('top',  winH/2-$("#loader").height()/2 + "px");
		    $("#loader").css('left', winW/2-$("#loader").width()/2 + "px");
		    
	    });

        $(id).show();
	});
	

	
	//if mask is clicked
	$('#mask').click(function () {
	        $(".modalwindow").hide();
		    $(this).hide();
	});			
	
	$('.modalwindow').click(function () {
	        $(".modalwindow").hide();
		    $("#mask").hide();
	});		
	
	
	function getScrollWidth()
    {
       var w = window.pageXOffset ||
               document.body.scrollLeft ||
               document.documentElement.scrollLeft;
               
       return w ? w : 0;
    }

    function getScrollHeight()
    {
       var h = window.pageYOffset ||
               document.body.scrollTop ||
               document.documentElement.scrollTop;
               
       return h ? h : 0;
    }
});
