// we need to preload images:
function doPreloadImages() {
    var preload = new Array();
    $(".hover").each(function() {
        if (!$(this).attr("src").match(/_on\.jpg$/i)) {
            s = $(this).attr("src").replace(/\.jpg$/i, "_on.jpg");
            preload.push(s)
        }
    });
    var img = document.createElement('img');
    $(img).bind('load', function() {
        if(preload[0]) {
            this.src = preload.shift();
        }
    }).trigger('load');
}

// we need to create hover where possible:
function doApplyHovers() {
    $(".hover").each(function() {
        if ($(this).attr("src").match(/_on\.jpg$/i)) {
            $(this).removeClass("hover");
        } else {
            $(this).hover(function() {
                s = $(this).attr("src").replace(/\.jpg$/i, "_on.jpg");
                $(this).attr("src", s);
            }, function() {
                s = $(this).attr("src").replace(/_on\.jpg$/i, ".jpg");
                $(this).attr("src", s);
            });
        }
    });
}

// init functions on page load:
$(window).bind('load', function() {
    doPreloadImages()
});


// init functions on page ready:
$(document).ready(function() {
    doApplyHovers();
//    $(document).pngFix();
    $('a[rel*=facebox]').facebox();
});


//timer support
jQuery.timer = function (interval, callback) {
    var interval = interval || 100;
    if (!callback) return false;

    _timer = function (interval, callback) {
        this.stop = function () {
            clearInterval(self.id);
        };

        this.internalCallback = function () {
            callback(self);
        };

        this.reset = function (val) {
            if (self.id) clearInterval(self.id);
            var val = val || 100;
            this.id = setInterval(this.internalCallback, val);
        };

        this.interval = interval;
        this.id = setInterval(this.internalCallback, this.interval);

        var self = this;
    };

    return new _timer(interval, callback);
};

function openFullscreen() {
    window.open($("#largest_slide").attr("src"),"fs","fullscreen=yes,channelmode=yes,scrollbars=yes,status=no,toolbar=no,menubar=no,titlebar=no,resizable=no");
}
/*
function playerReady(obj) {
//    var id = obj['id'];
//    p = $("#" + id).get(0);
//    p.sendEvent("SEEK", 5);
};
*/