var hestonify_count = 0;
hestonify_add = function() {
    hestonify_count += 1;
    var div = document.createElement('div');
    div.style.position = 'fixed';
    
    var numType = 'px';
    var heightRandom = Math.random()*.75;
    var windowHeight = 768;
    var windowWidth = 1024;
    var height = 0;
    var width = 0;
    var de = document.documentElement;
    if (typeof(window.innerHeight) == 'number') {
        windowHeight = window.innerHeight;
        windowWidth = window.innerWidth;
    } else if(de && de.clientHeight) {
        windowHeight = de.clientHeight;
        windowWidth = de.clientWidth;
    } else {
        numType = '%';
        height = Math.round( height*100 )+'%';
    }
    
    div.onclick = hestonify_add;
    div.style.zIndex = 10;
    div.style.outline = 0;
    
    if( hestonify_count==15 ) {
        div.style.top = Math.max( 0, Math.round( (windowHeight-530)/2 ) )  + 'px';
        div.style.left = Math.round( (windowWidth-530)/2 ) + 'px';
        div.style.zIndex = 1000;
    } else {
        if( numType=='px' ) div.style.top = Math.round( windowHeight*heightRandom ) + numType;
        else div.style.top = height;
        div.style.left = Math.round( Math.random()*90 ) + '%';
    }
    
    var img = document.createElement('img');
    var currentTime = new Date();
    var chuck =  Math.round(Math.random() * 6);
    img.setAttribute('src','http://godhatesfraggles.net/charlton/chuck' + chuck + '.jpg');
    var body = document.getElementsByTagName('body')[0];
    body.appendChild(div);
    div.appendChild(img);
}


/*
 * Adapted from http://www.snaptortoise.com/konami-js/
 */
var hestonami = {
    input:"",
    pattern:"38384040373937396665",
    clear:setTimeout('hestonami.clear_input()',5000),
    load: function() {
        window.document.onkeydown = function(e) {
            if (hestonami.input == hestonami.pattern) {
                hestonify_add();
                clearTimeout(hestonami.clear);
                return;
            }
            else {
                hestonami.input += e ? e.keyCode : event.keyCode;
                if (hestonami.input == hestonami.pattern) hestonify_add();
                clearTimeout(hestonami.clear);
                hestonami.clear = setTimeout("hestonami.clear_input()", 5000);
            }
        }
    },
    clear_input: function() {
        hestonami.input="";
        clearTimeout(hestonami.clear);
    }
}
hestonami.load();

