(function ($) { $(function () {
	var overlay = $('#overlay');
  var bg      = $('#overlay-bg').css({opacity: 0.5});
  var iframe  = $('<iframe id="overlay-iframe" src="" frameborder="0" scrolling="no" width="980" height="580" hspace="0" vspace="0"></iframe>');
  var close   = $('<div class="close"><a href="#">close</a></div>');
  
  var frame_width  = 880;
  var frame_height = 586;
  
// open ********************************************
  $('a.overlay').click(window.open_overlay = function (){
  	var url = $(this).attr('href');
  	
  	overlay.append(iframe);
  	overlay.append(close);
  	_close(close.find('a'));
  	
    var window_width    = $(window).width();
    var window_height   = $(window).height();
    var document_width  = $(document.body).find('#header').width();
    var document_height = $(document.body).height();
  	var top             = parseInt(((window_height/2 - frame_height/2) < 0 ) ? 0 : (window_height/2 - frame_height/2));
  	var left            = parseInt(((window_width/2 - frame_width/2) < 0 )    ? 0 : (window_width/2 - frame_width/2));
    
  	iframe.css({top: (top + 12), left: (left + 12)});
  	close.css({top: top, left: left});
  	bg.css({width: document_width, height: document_height});
    
  	iframe.fadeIn(500, function () {
			iframe.attr('src', url);
			close.show();
  	});
  	
  	bg.fadeIn(500);
  	
  	return false;
  });
  
  
// resize ********************************************
  $(window).resize(function () {
    var document_width  = $(document.body).find('#header').width();
    var document_height = $(document.body).height();
    bg.css({width: document_width, height: document_height});
  });
  
// close ********************************************
  _close(bg);
  
  function _close (el) {
	  el.click(function () {
	  	iframe.fadeOut(500, function () {
		  	iframe.remove();
		  	close.hide();
		  	close.remove();
	  	});
	  	
/*
	  	close.hide(0, function () {
		  	close.remove();
	  	});
*/
	  	
	  	bg.fadeOut(500);
	  	
	  	return false;
	  });
  };
  
})})(jQuery);
