function slide_show() {
  var $active = $('#slideshow img.active');

  if ( $active.length == 0 ) $active = $('#slideshow img:last');

  var $next =  $active.next().length ? $active.next() : $('#slideshow img:first');

  $active.addClass('last_active');

  $next.css({opacity: 0}).addClass('active').animate({opacity: 1}, 750, function() {
    $active.removeClass('active last_active');
  });
}

$(document).ready(function() {
  setInterval( "slide_show()", 5000 );
  
  $('#left #artwork a').each(function() { $(this).fancyZoom({closeOnClick: true,directory: '/workspace/images/zoom'});});
  
  $('a.gallery').each(function() { $(this).fancyZoom({closeOnClick: true,directory: '/workspace/images/zoom'});});
   	
  $("div.post-content:contains('The URL you requested could not be found.')").prev("div").hide();
  
  $("form#subForm").validate({
      onkeyup: false,
      onfocusout: false,
      errorPlacement: function(error, element) {
              alert(error.html());
      }
    });
  
  var pause_button = "<a href=\"#\" id=\"jplayer_pause\" class=\"jp-pause\" tabindex=\"1\">pause</a>"
  var playItem = 0;
  if (!(window.play_list === undefined)) {
    var myPlayList = play_list; 
  }
  
    $("#jquery_jplayer").jPlayer({
   ready: function () {
     // TODO Add Ogg Version
     displayPlayList();
        playListInit(true); // Parameter is a boolean for autoplay.
     //this.element.jPlayer("setFile", mp3_file, "http://www.miaowmusic.com/audio/ogg/Miaow-07-Bubble.ogg");
   },
   volume: 80,
   preload: 'none'
  })
  .jPlayer("onSoundComplete", function() {
   playListNext();
  });
	
	function displayPlayList() {
  		$("#jplayer_playlist").empty();
  		for (i=0; i < myPlayList.length; i++) {
  			var listItem = "<a href='#' id='jplayer_playlist_item_"+i+"' tabindex='1'>"+ myPlayList[i].name +"</a></li>";
  			$("#jplayer_playlist").append(listItem);
  			$("#jplayer_playlist_item_"+i).data( "index", i ).click( function() {
  				var index = $(this).data("index");
  				if (playItem != index) {
  					playListChange( index );
  					
  				} else {
  				  player = $("#jquery_jplayer");
            if (player.jPlayer( "getData","diag.isPlaying")) {
              player.jPlayer("pause");
              pause_track( index );
            } else {
              player.jPlayer("play");
              unpause_track( index );
            }
  				}
  				$(this).blur();
  				return false;
  			});
  		}
  	}
  	
  	function playListInit(autoplay) {
    		if(autoplay) {
    			playListChange( playItem );
    		} else {
    			playListConfig( playItem );
    		}
    	}

    	function playListConfig( index ) {
    		$("#jplayer_playlist_item_"+playItem).removeClass("jplayer_playlist_current").parent();
    		$("#jplayer_playlist_item_"+playItem).removeClass("jplayer_playlist_current_paused");
    		$("#jplayer_playlist_item_"+index).addClass("jplayer_playlist_current");
    		playItem = index;
    		$("#jquery_jplayer").jPlayer("setFile", myPlayList[playItem].mp3, myPlayList[playItem].ogg);
    	}
    	
    	function playListNext() {
      		var index = (playItem+1 < myPlayList.length) ? playItem+1 : 0;
      		playListChange( index );
      	}
    	
    	function pause_track( index ) {
    		$("#jplayer_playlist_item_"+index).addClass("jplayer_playlist_current_paused");
    	}
    	
    	function unpause_track( index ) {
    		$("#jplayer_playlist_item_"+index).removeClass("jplayer_playlist_current_paused");
    	}

    	function playListChange( index ) {
    		playListConfig( index );
    		$("#jquery_jplayer").jPlayer("play");
    	}
  
});
