$(function() {
   
    //all pages
    $("a.inline").colorbox({width:"400px", inline:true, href:"#contact_panel"});

    //Acting CV page
    if ($("#tabs").length){
        $("#tabs").tabs();
    }

    //gallery page
    $("a[rel='slideshow-image']").colorbox(); //default is elastic fade
	
	//showreel page
    $("a[rel='main-showreel']").colorbox({iframe:true, innerWidth:680, innerHeight:520});    //main showreel opens in its own colorbox
    $("a[rel='individual-clip']").colorbox({iframe:true, innerWidth:440, innerHeight:325});  //individual clips are more like a slideshow of clips

    //--------------------------------------------------
    //audioreel page
    $("#playerholder").jPlayer({
       swfPath: '/static/js/jplayer/',
       nativeSupport: true,
       oggSupport: false, 
       customCssIds: true
    });    

    //set up the links
    var clips = $(".playme");
    $.each( clips, function( i, obj ){
        $(obj).click( changeTrack ); //set up the clickosity
    });

    $('a#play').click(function(event){
        $("#playerholder").jPlayer("play");
        $("a#play").toggleClass('playing');
    	$("a#pause").toggleClass('paused');
        return false;
    }); 

    $('a#pause').click(function(event){
        $("#playerholder").jPlayer("pause");
        $("a#play").toggleClass('playing');
    	$("a#pause").toggleClass('paused');    	
        return false;
    }); 
});


//jPlayer call for audioreel
function changeTrack(e) {
	$("#trackname").text($(this).text());
	$("#playerholder").jPlayer("setFile", $(this).attr("href")).jPlayer("play");
	$(this).blur();
	
	//set the play and pause buttons too
	$("a#play").addClass('playing');
	$("a#pause").removeClass('paused');
	
	return false;
}

