// JavaScript Document

$(function(){
	
	var $window, $document, $popup, width, height, popup_width, popup_left;
	
	$window = $(window);
	$document = $(document);
	$popup = $('#popup');
	$overlay = $('.overlay');
	width = $document.width();
	height = $document.height();
	
	popup_width = $popup.width();
	popup_left = (($window.width() - popup_width) / 2) + 'px';
	$popup.css('top','200px').css('left',popup_left);
	
	$overlay.width(width).height(height);
	
	$window.resize(function(e){
	
		width = $document.width();
		height = $document.height();
		
		$overlay.width(width).height(height);
		
		popup_left = (($window.width() - popup_width) / 2) + 'px';
		$popup.css('left',popup_left);
	
	});

	$('.modal .close_btn, .modal .cancel_btn').live('click',function(e){
	
		$popup.fadeOut(500, function(){

			$overlay.fadeOut();

		});
		
		e.preventDefault();
	
	});

	$overlay.click(function(e){
			
		$popup.fadeOut(500, function(){
		
			$overlay.fadeOut();
			//$overlay.hide();

		});

	});

	$(document).keyup(function(e) {

  		if (e.keyCode == 27) { 
			
			$popup.fadeOut();
			$overlay.fadeOut();

		 }

	});
	
	$('.blog_btn').click(function(e){
	
		//console.log($(this).attr('href'));
		$.ajax({
				
			url: $(this).attr('href'),
			type: 'GET',
			success: function(msg){
			
				$('#popup').html(msg);
				$('.overlay').fadeIn(function(e){
					
					$('#popup').fadeIn();	
					
				});
			
			}
		
		});
		
		e.preventDefault();
	
	});
	
});
