/**
* попап
**/
(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:	"#000000",
				opacity:			0.8,
				width:				arrPageSizes[0],
				height:				arrPageSizes[1]	
			}).show();
		 		//show
		 			 				
		$('.d-shadow').show();
   		$("html:not(:animated),body:not(:animated)").scrollTop($("body").position().top);
  		   		
  	};
  	// закрытие галереи
  	$.modalclose = function(id) {	 
  		$(".d-shadow").hide();
  		$('#white-overlay').hide();
  	};	
  	
})(jQuery);


/**
* Галлерея
**/
/*
var Total = $( '#promo #w img' ).length;
		var Counter = 0;
		var Wrapper = $('#promo div' );
		
		
		changei( Counter );
		function changei( Counter ){
			var Height = Wrapper.height();
			Wrapper.animate({
				'marginTop': (Height / Total * Counter * -1)
			}, 1300, 'easeInOutExpo', function(){
				var Current = $( '#promo #w img:eq(' + Counter + ')' );
				Counter++;
				if( Counter == Total ){
					$( '#promo #w img' ).not( Current ).appendTo( Wrapper );
					$( this ).css( 'margin-top', 0 );
					Counter = 1;
				}
				
				
				setTimeout(function(){
					changei( Counter );
				}, 5000);
				
			});
		}
*/
(function($) {
	$(window).resize(function() {
				var arrPageSizes = __getPageSize();
				$('#white-overlay').css({
					width:		arrPageSizes[0],
					height:		arrPageSizes[1]
				});
			});
			
			// +30
		
  	$.gallshow = function(id) {
  		    
  		     var Total = $( '.photos img' ).length;
  		     //alert(id);
  		     var Current = $( '.photos img:eq(' + id + ')' );
  		     var new_w=parseInt(Current.attr('width_big'))+40;;
  		     var new_h=Current.attr('height_big');
  		     
  		     $("#prev_p, #next_p").unbind('click');    
  		     if (id==0)
  		     	{
  		     		$("#prev_p").click(function () { 
      					$.gallshow(parseInt(Total-1));
      					return false;
    				});
  		     	}
  		     else
  		     	{
  		     		$("#prev_p").click(function () { 	
      					$.gallshow(parseInt(id-1));
      					return false;
    				});
  		     	}	
  		     if (id==(Total-1))
  		     	{
  		     		$("#next_p").click(function () { 
      					$.gallshow(0);
      					return false;
    				});
  		     	}
  		     else
  		     	{
  		     		$("#next_p").click(function () { 	
      					$.gallshow(parseInt(id+1));
      					return false;
    				});
  		     	}
  		    
  		     if (Total==1)
  		     	{
  		     		$("#nv").hide();
  		     	}	
  		      		
  		    // alert(new_w);
  		    $('#gimage').show();
  		    $('#gimage').css({'display':''});
  		    $('#gimage').hide();
  		    // $( '#gimage').attr('src',null);
  		     $('#gimage').attr('src','/car_image/'+Current.attr('id'));
  		     
  		
            $("#gimage").unbind('load');    
        	$('#gimage').load(function () {
  		      	//$(this).attr();
  		      	 $(this).show();
  		      	 //alert('ok');
  		      	return false;
  		      });
  		     
  		    // $( '#gimage').show();
        	//if (this.complete) $(this).fadeIn(500);	
  		      $(".gall_close, #white-overlay").unbind('click');
			 // на картинки класса close_gallery ставим закрытие
  		     $(".gall_close, #white-overlay").click(function () {
  		      	$.gallclose();
  		      	return false;
  		      });
            
  		       
  		      
  		     //$('.d-shadow-gall').animate({ width: new_w+"px", marginLeft: '-'+parseInt(new_w/2)+'px'});  
  		       
  		       //alert('okm');
  		    
		 		//show
			
			// размер страницы, для темной хрени        
	  		     var arrPageSizes = __getPageSize();    
	  		       $('#white-overlay').css({
					backgroundColor:	"#000000",
					opacity:			0.8,
					width:				arrPageSizes[0],
					height:				arrPageSizes[1]	
				}).show();
				
   		$("html:not(:animated),body:not(:animated)").scrollTop($("body").position().top);
  		   return false;		
  	};
  	// закрытие галереи
  	$.gallclose = function(id) {	
  		$(".d-shadow-gall:animated").hide(); 
  		$(".d-shadow-gall").hide();
  		$('#white-overlay').hide();
  		//$(".d-shadow-gall").css(display,'none');
  		//$("#dl").hide();
  		//alert('cloar');
  		return false;
  	};	
  	
})(jQuery);