var slideGoto = function (mode) {
	var slideSrc;
	var hit = false;
	var next_time = -1;
	var prev_time = -1;
	var position = -1;
	var position_count = -1;
	var timecode = -1;
	var slideUrl = null;
	var arraySrc;
	var arrayTime;
	var arrayTimecode;
	var last_position = -1;

	//determine last position
	last_position = 0;
	for (i = 0; i < sync_data_records.length; i++) {
		if (sync_data_records[i]['handler'] != 'slide') {
			continue;
		}
		last_position++;
	}

	//test to see if there are slides
	if (mode == 'test') {
		if (last_position < 2) {
			return false;
		} else {
			return true;
		}
	}
	
	//get current slide path
	slideSrc = $('#slide').css('backgroundImage');
	slideSrc = slideSrc.replace(/url\(|\)/gi, '');
	arraySrc = '';
	
	//determine next / previous times
	for (i=0; i < sync_data_records.length; i++) {
		if (sync_data_records[i]['handler'] != 'slide') {
			continue;
		}
		position_count++;
		arraySrc = sync_data_records[i]['data']['src'];
		arraySrc = sync_data_records[i]['data']['src'];
		arrayTimecode = sync_data_records[i]['timecode'];
		if (arraySrc == slideSrc) {
			hit = true;
			position = position_count;
		} else {
			if (hit != true) {
				prev_time = arrayTimecode;
			} else {
				next_time = arrayTimecode;
				break;
			}
		}
	}

	//handle first / last test
	if (mode == 'position') {
		if (position == -1) {
			$("#slide_prev").css('display', 'none');
			$("#slide_next").css('display', 'none');
			return 'none';
		} else if (position == 0) {
			$("#slide_prev").css('display', 'none');
			$("#slide_next").css('display', 'block');
			return 'first';
		} else if (position >= (last_position - 1)) {
			$("#slide_prev").css('display', 'block');
			$("#slide_next").css('display', 'none');
			return 'last';
		} else {
			$("#slide_prev").css('display', 'block');
			$("#slide_next").css('display', 'block');
			return 'middle';
		}
	}
	
	//handle next / prev
	if (mode == 'next') {
		timecode = next_time;
	}
	if (mode == 'prev') {
		timecode = prev_time;
	}
	
	//seek video
	if (timecode != -1) {
		Framewelder_flash_player_v2_remoting.setTimeCode("flash_player", timecode);
	}
};

$(document).ready(
	function(){
		//add html for slide nav
		$('#slide').append('\
			<div id="slide_alt_container" class="nozoom">\
				<div id="slide_alt" class="nozoom">Slide 1</div>\
				<div id="slide_controls" class="nozoom"><a id="slide_prev" class="nozoom"></a><a id="slide_next" class="nozoom"></a></div>\
			</div>');
				
		//see if we need slide nav at all
		if (!slideGoto('test')) {
			$("#slide_alt_container")
				.css("display", "none");
			return;
		}
		
		//show black bar
		slideGoto('position');
		$("#slide_alt_container")
			.css("display", "block")
			.stop()
			.animate({opacity: 0}, 3000);
		
		//navbar animation
		$("#slide_container").hover(
			function() {
				slideGoto('position');
				$("#slide_alt_container").stop().animate({opacity: 1.0}, "fast");
			}, function () {
				$("#slide_alt_container").stop().animate({opacity: 0}, "fast");
			});
					
		//set up slide animation
		$("#slide_next")
			.click(function(e) {
				slideGoto('next');
				setTimeout(function() {
					slideGoto('position')
				}, 1000);
			});
		
		$("#slide_prev").
			click(function(e){
				slideGoto('prev');
				setTimeout(function() {
					slideGoto('position');
				}, 1000);
			});
	}
);
