/* GYT BLACKBOX

   Developed by: Levente Balogh
   gyt.blackbox.js
*/


//BlackBox Plugin
(function($){
 
    $.fn.extend({
         
        //plugin name 
        blackBox: function() {
 
            //Iterate over the current set of matched elements
            var _this = this;
            return _this.each(function() {
            //////////////////////////////
             	
             	//Adding blackbox code, and HTML content
             	var html = $(this).html();
             	$('body').prepend('<div class="blackbox" style="display: none;"><div class="blackbox-fade"></div><div class="blackbox-content"><div class="blackbox-inner-content">'+html+'</div><div class="blackbox-navigation"><div class="button close-blackbox">Bezárás</div></div></div></div>');
				$('.blackbox').css('top',window.pageYOffset+'px');
				$('.blackbox').fadeIn('fast');				
				
				//Close
				$('.close-blackbox').click(function(){
					$('.blackbox').fadeOut('fast',function(){
						$('.blackbox').remove();
					});
					window.location.hash = 'none';
				});
				
				//Clicking on fade closes the blackbox
				$('.blackbox-fade').click(function(){ $('.close-blackbox').click();	});
				
				//Hitting ESC closes the blackbox
				$(document).keyup(function(e) {
				  if (e.keyCode == 27) { $('.close-blackbox').click(); }  // esc
				});
				
				
			//////////////////////////////
            });
        }
    });
           
})(jQuery);
