$(function() {
    var hash = window.location.hash.substr(1);
        menu = ["about", "projects", "software", "partners", "friends", "texts", "contact"],
        content = {
            home: "\"In the face of ambiguity, refuse the temptation to guess.\" &mdash; <a href=\"http://www.python.org/dev/peps/pep-0020/\">PEP 20</a>",
            about: "0x2620, pronounced \"" + (Math.random() < 0.5 ? "two six two zero" : "twenty-six twenty") + "\", is registered in Berlin as a non-profit agency for the advancement of the<br/>international exchange of information, and usually operates at the intersections of, or in the void between, art,<br/>politics and technology. Its activities include extensive research on intellectual property and piracy, regular events<br/>in Berlin, Bombay and beyond, like film screenings, conferences or workshops, the development of open source software<br/>tools and web applications, with a strong focus on the extraction of structured information from unstructures sources<br/>and the archiving of digital media circulating in unstable networks, and the production of both technological and<br/>social infrastructure for the collaborative creation, maintenance and " + (Math.random() < 0.999 ? "use of relatively large data sets." : "deployment of relatively long sentences."),
            projects: [
                ["The Oil of the 21st Century", "http://oil21.org"],
                ["0xdb", "http://0xdb.org"],
                ["Pad.ma", "http://pad.ma"]
            ],
            software: [
                ["0xdb", "http://code.0xdb.org"],
                ["Pad.ma", "http://code.pad.ma"],
                ["Pan.do/ra", "http://pan.do/ra"],
                ["Firefogg", "http://firefogg.org"],
                ["oxjs", "http://oxjs.org"],
                ["Tetris", "http://0x2620.org/tetris"]
            ],
            partners: [
                ["Alternative Law Forum", "http://altlawforum.org"],
                ["Bootlab", "http://bootlab.org"],
                ["CAMP", "http://camputer.org"],
                ["Class Library", "http://classlibrary.de"],
                ["Constant", "http://constantvzw.org"],
                ["KEIN.ORG", "http://kein.org"],
                ["Know Future", "http://knowfuture.wordpress.com"],
                ["OKNO", "http://okno.be"],
                ["Partner gegen Berlin", "http://partnergegenberlin.de"],
                ["Piratbyr&aring;n", "http://piratbyran.org"],
                ["Pirate Cinema", "http://piratecinema.org"],
                ["Sarai", "http://sarai.net"],
                ["Starship", "http://starship-magazine.org"],
                ["The Thing", "http://thing.net"],
                ["V2V", "http://v2v.cc"],
                ["Waag Society", "http://waag.org"]
            ],
            friends: [
                ["Autonomedia", "http://autonomedia.org"],
                ["b_books", "www.b-books.de"],
                ["CCC", "http://ccc.de"],
                ["Dictionary of War", "http://dictionaryofwar.org"],
                ["EFF", "http://eff.org"],
                ["EXGAE", "http://exgae.net"],
                ["Jaaga", "http://jaaga.wikidot.com"],
                ["Mozilla", "http://mozilla.org"],
                ["Nettime", "http://www.nettime.org"],
                ["New Filmkritik", "http://newfilmkritik.de"],
                ["The Pirate Bay", "http://thepiratebay.org"],
                ["La Quadrature du Net", "http://laquadrature.net"],
                ["Raqs Media Collective", "http://www.raqsmediacollective.net"],
                ["Ubermorgen", "http://ubermorgen.com"],
                ["UbuWeb", "http://ubu.com"],
                ["Wikipedia", "http://wikipedia.org"]
            ],
            texts: [
                ["Adilkno, The Media Archive", "http://0x2620.org/txt/Adilkno - The Media Archive.txt"],
                ["Benjamin, The Work of Art", "http://0x2620.org/txt/Walter Benjamin - The Work of Art in the Age of Mechanical Reproduction.txt"],
                ["Deleuze, Societies of Control", "http://0x2620.org/txt/Gilles Deleuze - Postscript on the Societies of Control.txt"],
                ["Graham, Hackers and Painters", "http://0x2620.org/txt/Paul Graham - Hackers and Painters.txt"],
                ["Kafka, Intellectual Property", "http://0x2620.org/txt/Franz Kafka - Intellectual Property.txt"]
            ],
            contact: "<span class=\"bold\">0x2620 e.V.</span><br/>Memhardstra&szlig;e 2<br/>10178 Berlin/Germany<br/><a href=\"mailto:0x2620@0x2620.org\">0x2620@0x2620.org</a><br/><a href=\"irc://0x2620.org:+6670/#0x2620\">irc://0x2620.org:+6670/#0x2620</a><br/><br/><span class=\"bold\">Jan Gerber</span><br/><a href=\"mailto:0x006A@0x2620.org\">0x006A@0x2620.org</a><br/><br/><span class=\"bold\">Sebastian L&uuml;tgert</span><br/><a href=\"mailto:0x0073@0x2620.org\">0x0073@0x2620.org</a>",
            details: "<span class=\"bold\">0x2620 e.V.</span><br/>Bank: Berliner Sparkasse<br/>BLZ: 1005 0000<br/>Account: 6603 1844 09<br/>BIC/SWIFT: BE LA DE BE<br/>IBAN: DE08 1005 0000 6603 1844 09"
        },
        $menu = $("#menu"),
        $content = $("#content");
    $.each(menu, function(i, v) {
        i && $menu.append(" | ");
        $("<span>")
            .addClass("menu")
            .attr({
                id: v
            })
            .html(v.substr(0, 1).toUpperCase() + v.substr(1))
            .click(function() {
                click(v);
            })
            .appendTo($menu);
    });
    $content.html(content.home);
    content[hash] && click(hash);
    function click(menu) {
        var $link = $("#" + menu),
            selected = $link.hasClass("selected");
        $(".menu").removeClass("selected");
        $content.empty();
        if (!selected) {
            window.location.hash = menu;
            $link.addClass("selected");
            if ($.isArray(content[menu])) {
                $.each(content[menu], function(i, v) {
                    if (v[0] == "Partner gegen Berlin" || v[0] == "The Pirate Bay" || v[0] == "Graham, Hackers and Painters") {
                        $content.append("<br/><br/>");
                    } else {
                        i && $content.append(" | ");
                    }
                    $("<a>")
                        .addClass("menu")
                        .attr({
                            href: v[1],
                            title: v[1]
                        })
                        .html(v[0])
                        .appendTo($content);
                });
            } else {
                $content.html(content[menu]);
            }
        } else {
            window.location.hash = "";
            $content.html(content.home);
        }
    }
});

