(function($) {

	$.fn.konami = function(callback, code) {
		if(code == undefined) code = "38,38,40,40,37,39,37,39,66,65";
		
		return this.each(function() {
			var kkeys = [];
			$(this).keydown(function(e){
				kkeys.push( e.keyCode );
				while (kkeys.length > code.split(',').length) {
					kkeys.shift();
				}
				if ( kkeys.toString().indexOf( code ) >= 0 ){
					$(this).unbind('keydown', arguments.callee);
					callback(e);
				}
			}, true);
		});
	}

})(jQuery);

function createShip()
{
	var width = $(window).width();
	var height = Math.floor(Math.random()*($(window).height()-200)); // Random height position
	var z = 1000+height;
	
	var ship = $('<img>').attr('src', '/forum/newxf/misc/pirate.png').css({'position':'fixed', 'left':(width+(Math.random()*500))+'px', 'top':height+'px', 'z-index':z});
	$(document.body).append(ship);
	
	setTimeout(function() {
		ship.animate({left:-250+'px'},((Math.random()*60000)+10000), function() {
			$(this).fadeOut('fast', function() { $(this).remove(); createShip(); });
		});
	}, 500);
}

$(window).konami(function(){ 
    var hideme = $('<div>').attr('id', 'hideme').css({'position':'fixed', 'top':0, 'left':-9999+'px'});
	$(document.body).append(hideme);
    $('#hideme').append('<iframe width="420" height="315" src="http://www.youtube.com/v/x-64CaD8GXw?start=6&amp;rel=0&amp;autoplay=1&amp;loop=1&amp;playlist=x-64CaD8GXw" frameborder="0" allowfullscreen></iframe>');
	
	for (i=0;i<=6;i++)
	{
		createShip();
	}
});
