$(document).ready(function() {
	var videoPosition = 1;
	
	var mode = $('#partnerId').length; //Am I looking at a partner video page?
	var homepage = $('#video-content-mod').length; //Am I on the home page?
	var num = homepage?'4':'2'; //If you are on the home page, we need 4 videos. If not, we need 2
	$container = (num==4)?$('#video-content-mod'):$('#video-content'); //Do the container based on what page you are on.
	
	if(mode == 0) // Not on partners page.
	{
		$('#video-right-arrow').click(function(e) {
			e.preventDefault();
			// Get next set of videos

			videoPosition++;

			$.ajax({
				url: getBaseURL()+'videos/getLatest',
				type: 'POST',
				dataType: 'json',
				data: {position: videoPosition, num: num},
				complete: function(xhr, textStatus) {
				  //called when complete
				},
				success: function(data, textStatus, xhr) {
					$container.empty();
					$container.append(data.outputString);
					videoPosition = data.position;
				},
				error: function(xhr, textStatus, errorThrown) {
				  //called when there is an error
				}
			});


		});

		$('#video-left-arrow').click(function(e) {
			e.preventDefault();
			// Get previous set of videos

			videoPosition--;

			$.ajax({
				url: getBaseURL()+'videos/getLatest',
				type: 'POST',
				dataType: 'json',
				data: {position: videoPosition, num: num},
				complete: function(xhr, textStatus) {
				  //called when complete
				},
				success: function(data, textStatus, xhr) {
					$container.empty();
					$container.append(data.outputString);
					videoPosition = data.position;
				},
				error: function(xhr, textStatus, errorThrown) {
				  //called when there is an error
				}
			});
		});
	}
	else //Partner videos
	{
		$('#video-right-arrow').click(function(e) {
			e.preventDefault();
			// Get next set of videos

			videoPosition++;

			$.ajax({
				url: getBaseURL()+'partners/getLatestVideos',
				type: 'POST',
				dataType: 'json',
				data: {position: videoPosition,partnerId:$('#partnerId').html()},
				complete: function(xhr, textStatus) {
				  //called when complete
				},
				success: function(data, textStatus, xhr) {
					$('#video-content').empty();
					$('#video-content').append(data.outputString);
					videoPosition = data.position;
					Shadowbox.setup();
				},
				error: function(xhr, textStatus, errorThrown) {
				  //called when there is an error
				}
			});


		});

		$('#video-left-arrow').click(function(e) {
			e.preventDefault();
			// Get previous set of videos

			videoPosition--;

			$.ajax({
				url: getBaseURL()+'partners/getLatestVideos',
				type: 'POST',
				dataType: 'json',
				data: {position: videoPosition,partnerId:$('#partnerId').html()},
				complete: function(xhr, textStatus) {
				  //called when complete
				},
				success: function(data, textStatus, xhr) {
					$('#video-content').empty();
					$('#video-content').append(data.outputString);
					videoPosition = data.position;
					Shadowbox.setup();
				},
				error: function(xhr, textStatus, errorThrown) {
				  //called when there is an error
				}
			});
		});
	}
	
});
