var current_video= 0;
var shift_amount= 430; //width of each panel showing in the view pane
function move_video(num,auto){
	if(!auto) var auto= 0;
	if(auto == 0 && playStatus == true) pause();
	var rv_max= $('#rotater_pane .rotater_panel').length;
	var moving= false;
	if(num != current_video && num < rv_max){
		moving= true;
		current_video= num;
	}
	if(moving){
		//var rv_width= $('#rotater_pane .rotater_panel:first').width();
		//rv_width= rv_width + 14; // 14 is the right margin of the video
		$('#rotater_nav .panel_link').attr('className','panel_link');
		$('#rotater_nav #panel_link'+current_video).addClass('current_panel');
		var move= -1 * shift_amount * current_video;
		if(current_video == 0){
			$('#rotater_moveLeft img').attr('src','/photorotating/images/navLeft_down.jpg');
		}else{
			$('#rotater_moveLeft img').attr('src','/photorotating/images/navLeft.jpg');
		}
		if(current_video >= (rv_max-1)){
			$('#rotater_moveRight img').attr('src','/photorotating/images/navRight_down.jpg');
		}else{
			$('#rotater_moveRight img').attr('src','/photorotating/images/navRight.jpg');
		}
		$('#rotater_scroller').animate({
			'marginLeft' : move
		});
		autoTransition();
	}
}
function shift_video(dir,auto){
	if(!auto) var auto= 0;
	var rv_max= $('#rotater_pane .rotater_panel').length - 1;
	var new_vid= current_video;
	if(dir == 'right' && current_video != 0){
		new_vid--;
	}
	if(dir == 'left' && current_video < rv_max){
		new_vid++;
	}
	if(auto == 1 && current_video == rv_max){
		new_vid= 0;
	}
	move_video(new_vid,auto);
}
var playStatus= true;
var t;
function autoTransition(){
	//playStatus= false; //comment out if using autoTransitioning
	//$("#feature_options_loader").stop().css({'width':'0%'});
	clearTimeout(t);
	if(playStatus){
		t= setTimeout("shift_video('left',1)",8000);  //3 second = 3000 milliseconds
		// $("#feature_options_loader").animate({
		// 	'width': '99%'
		// },3000,function(){
		// 	feature_go();			
		// });
	}
}
function pause(){
	if(playStatus){
		playStatus = false;
		$('#play_pause img').attr('src','/photorotating/images/play.gif');
	}else{
		playStatus = true;
		$('#play_pause img').attr('src','/photorotating/images/pause.gif');
	}	
	autoTransition();
}
$(document).ready(function(){
	var rv_count= $('#rotater_pane .rotater_panel').length;
	if(rv_count <= 1){
		$('#rotater_moveRight img').attr('src','/photorotating/images/navRight_down.jpg');
	}
	var panel_links= "";
	for(var i=0;i<rv_count;i++){
		var extra= (i == 0)? " current_panel" : "";
		panel_links += "<li><a href=\"javascript:move_video("+i+");\" id=\"panel_link"+i+"\" class=\"panel_link"+extra+"\">"+(i+1)+"</a></li>\n";
	}
	$('#rotater_nav').html(panel_links);
	$('#rotater_moveLeft').click(function(){
		shift_video('right');
	}).attr('style','cursor : pointer');
	$('#rotater_moveRight').click(function(){
		shift_video('left');
	}).attr('style','cursor : pointer');
	autoTransition();
});