 /*
jQuery.fn.center = function (absolute) {
    return this.each(function () {
        var t = jQuery(this);

        t.css({
            position:    absolute ? 'absolute' : 'fixed', 
            left:        '50%', 
            top:        '50%'
        }).css({
            marginLeft:    '-' + (t.outerWidth() / 2) + 'px', 
            marginTop:    '-' + (t.outerHeight() / 2) + 'px'
        });

        if (absolute) {
            t.css({
                top:    parseInt(t.css('marginTop'), 10) + jQuery(window).scrollTop(), 
                left:    parseInt(t.css('marginLeft'), 10) + jQuery(window).scrollLeft()
            });
        }
    });
};
           */


(function($){
        $.fn.extend({
                center: function (options) {
                        var options =  $.extend({transition:0, minX:0, minY:0}, options);
                        return this.each(function() {
                                $(this).css('position', 'absolute');
                                var top = ($(window).height() - $(this).outerHeight())/2+$(window).scrollTop();
                                var left = ($(window).width() - $(this).outerWidth())/2+$(window).scrollLeft();
                                $(this).animate({
                                        top: (top > options.minY ? top : options.minY)+'px',
                                        left: (left > options.minX ? left : options.minX)+'px'
                                }, options.transition);
                                return $(this);
                        });
                }
        });
})(jQuery);



function getPopinV3(nom, voile, params, encoding, sWidth)
{
 params = (params == null) ? '' : params;
 
 $.ajax({
               type: "POST",
               url: "/Popin/index",
               data: "nom=" + nom + params,
               success: function(val){                    

                 	$("body").prepend(val); 
                 	
                 	if(voile) 
                    {                    
	                    $('#voileGris').livequery('click', function(event) {
	    
	      					$("#voileGris").hide();
	      					$("#PhC_CMS_PopIn").hide();
	        
	                       event.preventDefault();
	                    });
	                    
                       var pageSize = getPageSize();
				  	   $('#voileGris').css({
				            width:  pageSize[0]+'px', 
				            height:  pageSize[1]+'px'
				       });
                      $("#voileGris").show();
                    }
                    
                 	$("#PhC_CMS_PopIn").css('visibility', 'visible');
                 	if (sWidth != null){
                 		$("#PhC_CMS_PopIn").width(sWidth+'px');
                 	}
	      			$("#PhC_CMS_PopIn").hide();
                 	$("#PhC_CMS_PopIn").show();
                    $("#PhC_CMS_PopIn").center(); 
                   
                     $(".croixFermer").click( function(event) {	 
	                     closePopinV3();
					});	
               }
             });
}

function closePopinV3()
{ 
    $("#PhC_CMS_PopIn").fadeOut('slow');
    $("#voileGris").fadeOut('slow');
	$('#voileGris').remove();				
	closePopin();
	$('#PhC_CMS_PopIn').remove();
}

function getPageSize() {
            
         var xScroll, yScroll;
        
        if (window.innerHeight && window.scrollMaxY) {  
            xScroll = window.innerWidth + window.scrollMaxX;
            yScroll = window.innerHeight + window.scrollMaxY;
        } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
            xScroll = document.body.scrollWidth;
            yScroll = document.body.scrollHeight;
        } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
            xScroll = document.body.offsetWidth;
            yScroll = document.body.offsetHeight;
        }
        var windowWidth, windowHeight;
        
        if (self.innerHeight) { // all except Explorer
            if(document.documentElement.clientWidth){
                windowWidth = document.documentElement.clientWidth; 
            } else {
                windowWidth = self.innerWidth;
            }
            windowHeight = self.innerHeight;
        } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
            windowWidth = document.documentElement.clientWidth;
            windowHeight = document.documentElement.clientHeight;
        } else if (document.body) { // other Explorers
            windowWidth = document.body.clientWidth;
            windowHeight = document.body.clientHeight;
        }   
        
        // for small pages with total height less then height of the viewport
        if(yScroll < windowHeight){
            pageHeight = windowHeight;
        } else { 
            pageHeight = yScroll;
        }
    
        // for small pages with total width less then width of the viewport
        if(xScroll < windowWidth){  
            pageWidth = xScroll;        
        } else {
            pageWidth = windowWidth;
        }
        return [pageWidth,pageHeight];
}

