window.addEvent('domready', function () {

  //init navigation logic
  navigation.init();

  //set img url for proper image resizing on homepage. TODO: DO THIS SERVERSIDE!!
  $$("#main-content-home-1 img, #main-content-home-2 img").each(function (img) {
    img.src = "/ImageResize?img=" + img.src.substring(img.src.indexOf("/upload")) + "&w=200&h=1000";
    //width en height weg i.v.m. netjes =D
    img.removeProperty("width");
    img.removeProperty("height");
  });

  //position T
  positionT();
});

$(window).addEvent('resize', function () {
    //position T
    positionT();
});

function positionT() {
    var hor = $("t-horizontal");
    var ver = $("t-vertical");
    var pagePos = $("page-content").getPosition();

    hor.setStyles({
        // top: pagePos.y - 40,
        left: pagePos.x + 10
    });

    var verHeight = $(window).getSize().y - (pagePos.y + 32) - 50; // Was 30 pixels, not sure where the extra two pixels are coming from.

    ver.setStyles({
        // top: pagePos.y + 32, // Was 30 pixels, not sure where the extra two pixels are coming from.
        left: pagePos.x + 444,
        bottom: +40
    });

}

//konami code :D
Element.Events.konami = {
    base: 'keyup',
    condition: function (e) {
        $clear(this.retrieve('konami_timeout'));
        var input = this.retrieve('konami_input', []);
        input.push(e.key);
        if (input.join(',') == "up,up,down,down,left,right,left,right,b,a") {
            this.removeEvents('konami');
            return true;
        }
        this.store('konami_input', input).store('konami_timeout', (function () { this.eliminate('konami_input'); }).delay(2000, this));
    }
};

window.addEvent("konami", function () {
    $("t-vertical").fade("out");
    $("t-horizontal").fade("out");
});
