﻿//additional properties for jQuery object
jQuery(document).ready(function(){								
   //align element in the middle of the screen
  $.fn.alignCenter = function() {   
	 	var windowWidth = document.documentElement.clientWidth == 0 ? document.body.clientWidth : document.documentElement.clientWidth;
		var windowHeight = document.documentElement.clientHeight == 0 ? document.body.clientHeight : document.documentElement.clientHeight;
				
		var popupHeight = $(this).height();
		var popupWidth = $(this).width();
			
		if($.browser.msie)
        {   //centering
            return $(this).css({
			    "margin-top": (windowHeight - popupHeight)/2,
			    "margin-left": (windowWidth - popupWidth)/2 });	
        }
        else
	    {   //centering
		    return $(this).css({
			    "margin-top": (windowHeight - popupHeight)/2,
			    "margin-left": (windowWidth - popupWidth)/2 });	
	    }
   };
   
   $('#opaco').click(function(){$('#popup_messg').togglePopup();});

   $.fn.togglePopup = function(){	   
     //detect whether popup is visible or not
     if($('#popup').hasClass('hidden'))
     {
       //hidden - then display
       //when IE - fade immediately
       if($.browser.msie)
       {
         $('#opaco').height($(document).height()).toggleClass('hidden')
                    .click(function(){$(this).togglePopup();});
		 $('#opaco').width($(document).width());	
       }
       else
       //in all the rest browsers - fade slowly
       {
         $('#opaco').height($(document).height()).toggleClass('hidden').fadeTo('slow', 0.7)
                    .click(function(){$(this).togglePopup();});
       }

       $('#popup')
         .html($(this).html())
         .alignCenter()
         .toggleClass('hidden');
     }
     else
     {
       //visible - then hide
       $('#opaco').toggleClass('hidden').removeAttr('style').unbind('click');
       $('#popup').toggleClass('hidden');
     }
   };
});
