$(function() {

    $('.hover').each(function() {
        if ($(this).attr('src').match(/_on\.(.+)$/i)) {
            $(this).removeClass('hover');
        }
    });

    /* Mouseovers. */
    $('.hover').hover(function() {
        s = $(this).attr('src').replace(/-off\.(.+)$/i, '.$1');
        $(this).attr('src', s);
        $('.texts').hide();
        id = '#' + $(this).attr('id').replace(/_thumb$/i, '_text');
        $(id).show();
    }, function() {
        s = $(this).attr('src').replace(/\.(.+)$/i, '-off.$1');
        $(this).attr('src', s);
        $('.texts').hide();
    });

    /* JavaScript back link is a tad smarter. */
    $('#back a').bind('click', function() {
        history.back();
        return false;
    });
    
     $('#watch-vimeo').bind('click', function() {
         $('#vimeo').show();
         $('#video').hide();
         return false;
     });

     $('#watch-quicktime').bind('click', function() {
         $('#video').show();
         $('#vimeo').hide();
         return false;
     });
    
});
  
/* Preload sequentially after window is ready. */
$(window).bind('load', function() {
    var preload = new Array();
    $(".hover").each(function() {
        s = $(this).attr('src').replace(/-off\.(.+)$/i, '.$1');
        preload.push(s)
    });
    var img = document.createElement('img');
    $(img).bind('load', function() {
        if(preload[0]) {
            this.src = preload.shift();
        }
    }).trigger('load');
});
