/**
* галерея
**/
(function($) {
	

	$(window).resize(function() {
				var arrPageSizes = __getPageSize();
				$('#white-overlay').css({
					width:		arrPageSizes[0],
					height:		arrPageSizes[1]
				});
				
			});
			
  	$.modalshow = function(id) {

			 // на картинки класса close_gallery ставим закрытие
  		     $(".modal_close, #white-overlay").click(function () {
  		      	$.modalclose();
  		       });
             
  		     // размер страницы, для белой хрени        
  		     var arrPageSizes = __getPageSize();       
  		       $('#white-overlay').css({
				backgroundColor:	"#ffffff",
				opacity:			0.8,
				width:				arrPageSizes[0],
				height:				arrPageSizes[1]
				
			}).show();
		 				
		$('.modal').show();
			  
         var winW = $(window).width();   
         var winH=$(window).height()/2;
       //  $('#modal-window').css('top',  winH/2-$('#modal-window').height()/2);   
         $('.modal').css('left', winW/2-$('.modal').width()/2);   
        
         $(".modal-content").load('/maker_info.php?id='+id, function(){
   					var margin=parseInt($(".modal").height())/2;
   					
   					if (margin>winH || ($.browser.msie && $.browser.version.substr(0,1)<7))
   						{
   							$(".modal").css("margin-top","10px");
   							$(".modal").css("position","absolute");
   							$("html:not(:animated),body:not(:animated)").scrollTop($(".modal").position().top);
   						//	alert($(".modal").position().top);
   						}
   					else
   						{
   							$(".modal").css("margin-top","-"+margin+"px");
   							$(".modal").css("position","fixed");
   						}		
   					//alert($(window).height()+' -  '+margin);		
				});
				
				//
			/* 
			//Get the window height and width   
        	var winH = $(window).height();   
        	var winW = $(window).width();   
                 
        //Set the popup window to center   
        $(id).css('top',  winH/2-$(id).height()/2);   
        $(id).css('left', winW/2-$(id).width()/2);   
			
			*/
		   
		
  	};
  	
  	// закрытие галереи
  	$.modalclose = function(id) {
  		 
  		$(".modal-content").html("<img src='/images/ajax_load.gif' alt='Загрузка...'/>");
  		$(".modal").hide();
  		$('#white-overlay').hide();
 

  	};	
  	

  	
  	function __getPageSize() {
			var xScroll, yScroll;
		  // alert(document.body.clientHeight);
			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;
			}	
			//alert(document.body.scrollHeight);
			// 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;
			}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
		};
})(jQuery);
