$(document).ready(function(){
	
	$("#mask").appendTo('body');
	$(".google-windows").appendTo('body');
	
	
	$(".google-map").click(function(e){
		
	    var gid = $(this).attr('id');
	    var reg = /^p-([\d]+)-([\d]+)$/i;
	    
	    if (reg.test(gid))
	    {
	    	var arr = reg.exec(gid);
	    	var vcartNo = arr[1];
	    	var id = arr[2];
				  
			$('#mask').css({'width':$(document).width(),'height':$(document).height()});
			$('#mask').fadeIn();
			$('#mask').fadeTo('fast', 0.8);
				       
			$('.google-windows').css({'left':$(window).width() / 2 - $('.google-windows').width() / 2});
			
			if ($.browser.msie) {
				$('.google-windows').css('position', 'absolute');
				$('body').scrollTop();
				$('.google-windows').css({'top':0});
				
				$('body').css({
					'height':'100%',
					'position': 'relative',
					'overflow': 'hidden'
				}); 
			}
			else{
				$('.google-windows').css('position', 'fixed');
				$('.google-windows').css({'top':0});
			}				   
			
			
			$('.google-windows').css({'height':$(window).height() - 50});
			$('.script-container').css({'height':$(window).height() - 120});	  
			  
			$('.google-windows').slideToggle('slow', function(){
				
				$('.script-container').html('Подождите, идет загрузка ... ');
				$.ajax({
	    			type: "GET",
	    			url: "/map.php?var1=" + vcartNo + '&var2=' + id,
	    			success: function(html){
	    				$('.script-container').html(html);
	    			}
		    	});
			});

	    	
	    }
	    
	    return false;
	});
	  
	$('.google-close').click(function () {
	    $('.google-windows').slideUp('slow', function(){
	    	$('.script-container').html('');
	    	$('#mask').fadeOut('fast', function(){
	    		$('body').css({
					'height':'auto'
				});
	    	});
	    });
	    
	}); 
	
	$('#mask').click(function () {
		$('.google-windows').slideUp('slow', function(){
			$('.script-container').html('');
			$('#mask').fadeOut('fast', function(){
	    		$('body').css({
					'height':'auto'
				});
	    	})
	    });
	});
		
});
