jQuery(function($) {
    
    if ($.hasFlashPlayer) {
        $('div.bigVideo p.warning').hide();
    }

    var current;
    
    var loadFlash = function(li, autoplay) {
        current = li;
    
        $('div.videoListing li.playing').removeClass('playing');
        li.addClass('playing');
    
        $('div.bigVideo h2').text($('h3', li).text());
    
        var path = li.attr('data-path');
    
        autoplay = autoplay ? 'on' : 'off';
        $('#flash').flash({
            swf: '../../content/flash/player.swf',
            width: 720, // 305
            height: 340, // 165
            params: {
                allowFullScreen: 'true'
            },
            flashvars: {
                movie: '../../content/video/flv/' + path,
                autoload: 'on',
                autoplay: autoplay,
                bgcolor: '0x222222',
                fgcolor: '0xec6e26'
            }
        });
    };
    
    $('div.bigVideo a.arrow').click(function(event) {
        var next;
        
        if ($(this).hasClass('next')) {
            next = $(current).next();
            if (next.length == 0) {
                var next = $('div.videoListing li:first-child');
            }
        } else {
            next = $(current).prev();
            if (next.length == 0) {
                var next = $('div.videoListing li:last-child');
            }        
        }
    
        loadFlash(next, true);
        
        return false;
    });
    
    $('.videoListing li').hover(function() {
        $(this).addClass('hover');   
    }, function() {
        $(this).removeClass('hover');
    });
    
    $('.videoListing li').click(function(event) {
        
        var li = $(this).closest('li');
        
        if (li.hasClass('playing')) {
            return false;
        }

        loadFlash(li, true);        
        $('html, body').animate({scrollTop: 0}, {complete: function() {

        }});      
        return false;
    
    });
    
    var first = $('.videoListing li:first-child');

    loadFlash(first, false);
        
});