function project_slide(proj) {
	if($("#projects .sliding").length > 0)
		return;
	
	// additional check to make sure the slideshow
	// stops when a clip is playing
	var isPlaying = false;
	$f('*').each(function() {
	  if(this.getState() == 3) {
	    isPlaying = true;
	    return;
	  }
	});	
	if(isPlaying) {
	  cancel_sliding();
	  return;
	}
	
	var shown = $('#projects .shown');
	var offscreen = $('#projects #' + $(proj).attr('id'));
	
	if(shown.attr('id') == offscreen.attr('id'))
		return;

	shown.addClass('sliding');
	offscreen.addClass('sliding');

	var pos = offscreen.css('left');
	var dir = "-";
	if(pos != undefined)
		dir = (pos.charAt(0) == "-") ? "+" : "-";

	$("#projects .sliding").animate({left:dir+"=695px"}, {
		duration: 500,
		complete: function() {
			offscreen.prevAll().css({left: -695});
			offscreen.nextAll().css({left: 695});
			offscreen.removeClass('sliding').addClass('shown');
			if(shown.hasClass('old'))
				shown.remove();
			else
				shown.removeClass('sliding').removeClass('shown');
		}
	});
}

function advance_project() {
	next = $('#projects .shown ~ div.project');
	if(next.length == 0) {
	  a = $('div#list a.next');
	  paginate(a.attr('href'), 'next', true);
    // next = $('ul.items a:first');
	} else {
	  project_slide($('ul.items a#'+next.attr('id')));
	}
}


function advance_carousel(from_left) {
  
  if(from_left === undefined)
    from_left = false;
  
  if($('.sliding').length > 0)
    return;
  
  $('div#list ul.items').addClass('sliding');
  
  var dir = "-";
  if(from_left) {
    dir = "+";
    $('div#list ul.items').not('.old').css({ left: "-581px"});
  } 

  $('div#list ul.items').animate({left:dir+"=581px"}, {
    duration: 500,
    complete: function() {
			if($(this).hasClass("old")) 
				return;
      $('div#list ul.old').remove();
			$('div#list ul.sliding').removeClass('sliding');
			
			
			$f("*").each(function() { 
        if($(this).hasClass('old') && !$(this).hasClass('shown')) {
          this.close();
          this.unload();
        }
			});
      // $('.old').not('.shown').flowplayer().each(function() { this.close(); this.unload(); });
			$('.old').not('.shown').remove();
			$('div#list a.button').removeClass('locked');
		}
  });
}
