var J = jQuery.noConflict();
J(function() {	
    
    if(J(this).scrollTop()){ J("#toTop").fadeIn("slow"); }
	
    J("#toTop").hide().removeAttr("href");
    if (J(window).scrollTop()){ J("#toTop").fadeIn("slow"); }
    
    J(window).scroll(function(){
        if (J(window).scrollTop() < 600){ 
            J("#toTop").fadeOut("slow");
        } else {
            J("#toTop").fadeIn("slow");
        }
    });
    J("#toTop").click(function(){ J("html, body").animate({ scrollTop: 0 }, "slow"); }); 
    
});


/* KONAMI */

function onKonamiCode(fn) {
    var codes = (function(){
            var c = [38,38,40,40,37,39,37,39,66,65];
            onKonamiCode.requireEnterKey && c.push(13);
            return c;
        })(),
        expecting = function(){
            expecting.codes = expecting.codes || Array.apply({}, codes);
            expecting.reset = function() { expecting.codes = null; };
            return expecting.codes;
        },
        handler = function(e) {
            if (expecting()[0] == (e||window.event).keyCode) {
                expecting().shift();
                if (!expecting().length) {
                    expecting.reset();
                    fn();
                }
            } else { expecting.reset(); }
        };
    window.addEventListener ?
        window.addEventListener('keydown', handler, false)
        : document.attachEvent('onkeydown', handler);
}

//onKonamiCode.requireEnterKey = true;
onKonamiCode(function(){
     var iframe = $('<iframe/>')
        .bind('load', function(){
            var iframe = this;
            window.scroll(0,0);
            setTimeout(function(){
                $(iframe).animate({top : 0,opacity: 1}, 1400, function(){button.show();});
                $('body,html').css('overflow','hidden');
            }, 500);
        })
        .attr({
            src: 'http://www.youtube.com/watch_popup?v=utdKjUZz-o0',
            frameborder: 0,
            id: 'kiframe'
        })
        .css({
            top: -$(window).height(),
            height: $(window).height(),
            opacity: 0
        })
        .appendTo('body');
    var button = $('<div>Click Here To Close Konami Challenge.</div>');
    button
        .attr('id', 'koutofhere') 
        .click(function(){
            $('body,html').css('overflow','auto');
            iframe.animate({
                top : -$(window).height()
            }, 1000, function(){ $(this).remove(); });
            $(this).remove();
        })
        .appendTo('body');
});
