$(document).ready(function() {

//{{{ home page tabbed block
$('#right > div').each(function(i) {
    var el = $(this),
        id = el.attr('id'),
        subhead = $('> h3', this).hide(),
        right = el.parent(),
        stext = subhead.text(),
        link = $('<a><span>' + stext + '</span></a>'),
        tab = $('<div class="tab" id="tab_link_' + stext.toLowerCase() + '" />');
    if (i === 0)
    {
        $(right).prepend('<div id="tabs" class="cleared" />');
        link.addClass('active hover');
    }
    else
    {
        el.hide();
    }
    $('#tabs').append(tab.append(link));
    link.click(function(e) {
        $('.block', right).hide();
        $('#' + id).show();
        $('#tabs .tab a.active').removeClass('active hover');
        $(this).addClass('active hover');
    });
});

var tabs = $('#tabs .tab');
tabs.eq(0).addClass('first');
tabs.eq(tabs.length - 1).addClass('last');
tabs.mouseover(function() {
    $('a', this).addClass('hover');
}).mouseout(function() {
    var link = $('a', this);
    if (!link.hasClass('active'))
    {
        link.removeClass('hover');
    }
});
//}}}
//{{{ schedule
var schedule_slideshow = $('#schedule .slides'),
    schedule_slides = $('img', schedule_slideshow),
    schedule_links = $('#schedule .days a'),
    schedule_link_21 = schedule_links.eq(0),
    schedule_link_22 = schedule_links.eq(1),
    schedule_link_23 = schedule_links.eq(2);

function schedule_slide(fin, el)
{
    schedule_links.removeClass('active');
    $(el).addClass('active');
    schedule_slides.eq(schedule_slideshow.data('showing'))
        .fadeOut(300, function() {
            schedule_slides.eq(fin).fadeIn(300);
        });
    schedule_slideshow.data('showing', fin);
}

schedule_link_21
    .click(function() {
        schedule_slide(0, this);
    });
schedule_link_22
    .click(function() {
        schedule_slide(1, this);
    });
schedule_link_23
    .click(function() {
        schedule_slide(2, this);
    });

schedule_slides.hide();
schedule_slides.eq(0).show();
schedule_slideshow.data('showing', 0);
//}}}
//{{{ video switcher
$('#video-nav').change(function(){
    var flash = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="100%" height="100%" ><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /><param name="wmode" value="transparent"></param><param name="bgcolor" value="#000000" /><param name="movie" value="';
    if($('option:selected', this).attr('class') === 'ted-movie')
    {
        flash += 'http://video.ted.com/assets/player/swf/EmbedPlayer.swf" /><param name="flashvars" value="' + $(this).attr('value');
        flash += '" /><embed flashvars="' + $(this).attr('value');
        flash += '" src="http://video.ted.com/assets/player/swf/EmbedPlayer.swf" width="100%" height="100%" allowScriptAccess="always" allowFullScreen="true" type="application/x-shockwave-flash" wmod="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" bgcolor="#000000"></embed></object>';
        
    }
    else
    {
        flash += 'http://fora.tv/embedded_player" /><param name="flashvars" value="' + $(this).attr('value');
        flash += '" /><embed flashvars="' + $(this).attr('value');
        flash += '" src="http://fora.tv/embedded_player" width="100%" height="100%" allowScriptAccess="always" allowFullScreen="true" type="application/x-shockwave-flash" wmod="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" bgcolor="#000000"></embed></object>';
    }

    if($('option:selected', this).text() != 'Choose a speaker')
    {
        $("#vid-player").html(flash);
    }
});
//}}}

});
