/*
*	Показывает модальное окно загружая файл по пути из переменной link.
* 	Разработано для отображения новой карты проезда.
*
*/

   $(document).ready(function() {	
	
	var width = '800px';
	var height = '680px';
	var id = "#new_scheme"; //название блока в который будет внедрение
	var link = "/shema/shema.php";	//ссылка что открываем
		
		var html = '<div id="boxes">'
				+	'<div style="background-color:#ffffff; position:absolute; left:0;  top:0; z-index:9999;" class="window" id="new_scheme">'
				+		'<div style=" width:'+width+'; height:'+height+'; padding:10px; position: relative" class="box_wrap">'
				+			'<div id="inner"></div>'
				+			'<a href="#" style="position: absolute; bottom: 15px; right: 15px;" class="close">Закрыть</a>'
				+			'</div>'
				+		'</div>'
				+		'<div style ="position:absolute; left:0; top:0; z-index:9000; background-color:#000; display:none;" id="mask"></div>'
				+'</div>';
				
		
		
		if ($.cookie('scheme_trigger') != "1") { //здесь надо заменить на != $.cookie('scheme_trigger') != "1"
			$.cookie('scheme_trigger', "1");
			$('body').append(html);
			
		
		
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight, 'opacity': 0, 'display':'block'});
		
		//transition effect			
		$('#mask').fadeTo("slow",0.8);	
	
		//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);
	
		//грузим ajax
		$(id + ' #inner').load(link);
		
		//transition effect
		$(id).fadeIn(1000); 
	
	
	//if close button is clicked
	$('.window .close').live('click',(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		$('#mask').hide();
		$('.window').hide();
	}));		
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});
	
	} else {console.log('кука есть')}//конец условия
});
