﻿//additional properties for jQuery object
$(document).ready(function(){
   //align element in the middle of the screen
   $.fn.alignCenter = function() {
      //get margin left

	  var addWidth=0; 
	  var addHeight=0; 
	  if ($(window).width()<$(this).width())
	  {
		addWidth=($(this).width()-$(window).width())/2;
	  }
	  if ($(window).height()<$(this).height())
	  {
		addHeight=($(this).height()-$(window).height())/2;
	  }
      var marginLeft =  addWidth - $(this).width()/2 + 'px';
      //get margin top
      var marginTop =  addHeight - $(this).height()/2 + 'px';
      //return updated element
      return $(this).css({'margin-left':marginLeft, 'margin-top':marginTop});
   };

   $.fn.togglePopup = function(){
     //detect whether popup is visible or not
     if($(this).hasClass('hidden'))
     {
		var $cur=$(this);
       //hidden - then display
       //when IE - fade immediately
       if($.browser.msie)
       {
         $('#opaque').height($(document).height()).toggleClass('hidden')
                    .click(function(){$cur.togglePopup();return false;});
       }
       else
       //in all the rest browsers - fade slowly
       {
         $('#opaque').height($(document).height()).toggleClass('hidden').fadeTo('slow', 0.7)
                    .click(function(){$cur.togglePopup();return false;});
       }
        $(this).alignCenter()
         .toggleClass('hidden');
     }
     else
     {
       //visible - then hide
       $('#opaque').toggleClass('hidden').removeAttr('style').unbind('click');
       $(this).toggleClass('hidden');
     }
   };
});

