//additional properties for jQuery object
jQuery(document).ready(function(){
   //align element in the middle of the screen
   jQuery.fn.alignCenter = function() {
      //get margin left
      var marginLeft =  - jQuery(this).width()/2 + 'px';
      //get margin top
      var marginTop =  - jQuery(this).height()/2 + 'px';
      var w = jQuery(window);
      var marginTop = ((w.height()-this.height())/2+w.scrollTop()) + "px";
      return jQuery(this).css({'margin-left':marginLeft, 'top':marginTop});
   };

    jQuery.fn.togglePopup = function(sPopupSelector) 
    {
    	
        var sPopupSelector = sPopupSelector || '#popup';
       
        //detect whether popup is visible or not
        if (jQuery(sPopupSelector).hasClass('hidden'))
        {
        	
            //hidden - then display
            //when IE - fade immediately
            if (jQuery.browser.msie)
            {
                jQuery('#opaco').height(jQuery(document).height()).toggleClass('hidden')
                    .click(function(){jQuery(this).togglePopup();});
            }
            else //in all the rest browsers - fade slowly
            {
                jQuery('#opaco').height(jQuery(document).height()).toggleClass('hidden').fadeTo('slow', 0.7)
                    .click(function(){jQuery(this).togglePopup();});
            }

            jQuery(sPopupSelector)
                .html(jQuery(this).html())
                .alignCenter()
                .toggleClass('hidden');
        }
        else
        {
        	//visible - then hide
            jQuery('#opaco').toggleClass('hidden').removeAttr('style').unbind('click');
            jQuery(sPopupSelector).toggleClass('hidden');
        }
    };
});

