function endsWith(str, s) {
    var reg = new RegExp (s + "$");
    return reg.test(str);
}

$(document).ready(function() {

    $("a[href$='video_view']").each(function() {
        var href = "/player/flash/loader.swf?flashXMLRef="+$(this).attr('href').slice(0,-10)+"video.xml";
        $(this).attr('href',href).attr('rel', 'shadowbox;width=690;height=450');
    });

    $(".hover").each(function() {
        if ($(this).attr("src").match(/_over\.(.+)$/i)) {
            $(this).removeClass("hover");
        }
    });
    $(".hover").hover(function() {
        s = $(this).attr("src").replace(/\.(.+)$/i, "_over.$1");
        $(this).attr("src", s);
    }, function() {
        s = $(this).attr("src").replace(/_over\.(.+)$/i, ".$1");
        $(this).attr("src", s);
    });
    $("#nav li").hover(function() {
        $(this).addClass("over");
    }, function() {
        $(this).removeClass("over");
    })
    var url = window.location.protocol + '//' + window.location.host;
    $('a[href^=http]:not(.link-plain):not([href^=' + url + '])').attr('target', '_blank');

});

$(window).bind('load', function() {
    Shadowbox.init();
    var preload = new Array();
    $(".hover").each(function() {
        s = $(this).attr("src").replace(/\.(.+)$/i, "_over.$1");
        preload.push(s)
    });
    var img = document.createElement('img');
    $(img).bind('load', function() {
        if(preload[0]) {
            this.src = preload.shift();
        }
    }).trigger('load');
});
