var information = {};
var Callbacks = new Object();
var old_height;

function notify(title, text, image, option) {
    if (! option) {
        option = {};
    }
    option.header = '<img src="/static/' + image + '"> <h2>' + title + '</h2>'
    $.jGrowl(text, option );

}
function inform(title, text, option) {
    notify(title, text, 'dialog-information.png', option);
}

function play_info(text) {
    notify('Playing', text, 'media-playback-start.png');

}
function error(title, text) {
    notify(title, text, 'dialog-error.png');
}
Callbacks.last_id = 0;
Callbacks.play = function () {
    $('#switching').jqmHide();
    this.play();
    play_info($(".playlist_current .title").text());
}

Callbacks.on_error = function () {
    $('#switching').jqmHide();
    error('Error', "Could not load video for " + Callbacks.current.fields.room);
}

Callbacks.initialize = function() {
    $("video").each(function() { this.addEventListener("canplaythrough", Callbacks.play, false )});
    $("video").each(function() { this.addEventListener("error", Callbacks.on_error, false )});
    if ( ! Callbacks.initialized) {
        if (location.hash == "") {
            $("video").toggle();
            old_height = $("#playlist_list ul").height();
            $("#playlist_list ul").height(400);
        } else {
            $(location.hash).click();
        }
    }
    Callbacks.initialized=true;
}

Callbacks.update_information = function(self) {
    location.hash = $(self).attr("id");
}

Callbacks.mouse_over = function() {

    overlib($(this).find(".note").text(), CAPTION,'Abstract');
}
Callbacks.mouse_out = function() {
    nd();
}


Callbacks.li_click = function() {

    $("#playlist_list ul").height(old_height);
    $("video").show();
    $("#playlist_list li").removeClass("playlist_current");
    $(this).addClass("playlist_current");
    Callbacks.update_information(this);
    var id = $(this).attr("id");
    $.get("location/" + id, function(data) {
            $("video").get(0).pause();
            $("video").html(data);
            $("video").get(0).load();
            $('#switching').jqmShow();
            });
}

Callbacks.update = function () {
    $.getJSON("/schedule/", function(data) {
            $.each(data, function(){
                var obj = $("#" + this.fields.room.toLowerCase());
                obj.find(".title").text(this.fields.title);

                information[obj.attr("id")] = this;
                });
        });
}
Callbacks.twitter = function() {
    $.jTweet(hashtag, 4, Callbacks);


}

