function showVideo(elm, vid_id) {
	
	var list = $(".week-current");
	$.each(list, function(i, item) {
		$(item).removeClass('week-current');
		$(item).addClass('week');
	});
	
	$(elm).removeClass('week');
	$(elm).addClass('week-current');
	
	var data = {
		video_id: vid_id,
		action: 'get_video_info'
	};

	$.postJSON('index.http.php', data,
		function(data) {
			$('#video_presenter').html(data.presenter);
			$('#video_title').html(data.title);
			$('#video_desc').html(data.description);
			$('#quiz_english_url').attr('href', data.quiz_english_url);
			$('#quiz_spanish_url').attr('href', data.quiz_spanish_url);
			//$('#quiz_take_url').attr("href", data.quiz_take_url);
			$('#wrapper').css('background-image', 'url(' + data.still + ')');
			$('#audio_button_wrapper').css('display', 'none');
			if  ( true === is_logged_in ) {
				
				// Make sure there is no player
				deletePlayer('wrapper', 'placeholder1', 'player1');
				
				// Bind the necessary actions to the play movie button
				$('#play_button').unbind('click');
				$('#play_button').click( function() {
					watchVideo(vid_id, 'video', function() {
						$('#watch_button_wrapper').css('display', 'none');
						$('#audio_button_wrapper').css('display', 'none');
						$('#play_button_wrapper').css('display', 'none');
						initPlayer(data.video_file, data.still, true);
					});
					return false;
				});
				$('#play_button_wrapper').css('display', 'block');
				
				// Bind the necessary actions to the play audio button on the right
				$('#spanish_audio').unbind('click');		
				$('#spanish_audio').bind('click', data, function(e) {
					deletePlayer('wrapper', 'placeholder1', 'player1');
					$('#watch_button_wrapper').css('display', 'none');
					$('#play_button_wrapper').css('display', 'none');
					$('#audio_button_wrapper').css('display', 'block');
					return false;
				});
				
				// Bind the necessary actions to the play audio button on the video
				$('#audio_button').unbind('click');
				$('#audio_button').bind('click', data, function(e) {
					watchVideo(vid_id, 'spanish', function() {
						$('#watch_button_wrapper').css('display', 'none');
						$('#play_button_wrapper').css('display', 'none');
						$('#audio_button_wrapper').css('display', 'none');				
						playAudio(e.data.audio_file);
					});
					return false;
				});
			} else {
				$('#individual_login').attr('href', 'individual-login.php?video=' + vid_id);
				$('#team_login').attr('href', 'team-login.php?video=' + vid_id);
			}
			$('#video_panel_right').css('display' , 'block');
			$('#video_panel_left').css('display' , 'inline');
		}
	);
}

function watchVideo(vid_id, type, callback) {
	var data = {
		video_id: vid_id,
		type: type,
		action: 'watch_video'
	};

	$.postJSON('index.http.php', data, function(data){
		if ( false == data.success ) {
			window.location.reload();
		} else {
			callback();
		}
	});
}

function playAudio(file) {
	initPlayer(file, 'assets/files/audio_sp/screens/audio_sp.jpg', true);
}

$.postJSON = function(url, data, callback) {
	$.post(url, data, callback, 'json');
}

$.postHTML = function(url, data, callback) {
	$.post(url, data, callback, 'html');
}

function validateLoginForm (form) {
	var pass = true;
	var list = $('#' + form + ' :input');
	$('#status_error').css('display', 'none');
	$.each(list, function(i, item) {
		$(item).removeClass('error_field');
		if ( false == valid(item) ) {
			pass = false;
			$(item).addClass('error_field');
		}
	});
	if ( false == pass ) {
		$('#status_error').css('display', 'block');
	}
	return pass;
}


function valid (e) {
	var req = $(e).attr('required');
	var val = $(e).val();
	if ( 1 == req ) {
		if ( val.length > 0 ) {
			return true;
		}
		return false;
	}
	return true;
}

function getTeamList() {
	email = $("#email_address");
	email.removeClass('error_field');
	$('#status_error').css('display', 'none');
	if ( false == valid(email) ) {
		email.addClass('error_field');
		$('#status_error').css('display', 'block');
	} else {
		$('#email_error').css('display', 'none');
		var data = {
			email: email.val(),
			action: 'get_dropdown'
		};
		$.postHTML('team-login.http.php', data,
			function(html) {
				$('#team_list').html(html);
				if ( $('#team_dropdown option').length < 2 ) {
					$('#email_error').css('display', 'block');
					$('#team_dropdown').attr("disabled", "disabled");
				}
			}
		);
	}
}


function validateAddMemberForm (form) {
	var pass = true;
	var member_list = $('.add-team-member');
	$('#status_error').css('display', 'none');
	$.each(member_list, function(i, item) {
		$(item).removeClass('member_error');
		var input_list = $(item).find(':input');
		if ( valid(input_list[0]) != valid(input_list[1]) ) {
			$(item).addClass('member_error');
			pass = false;
		}
	});
	if ( false == pass ) {
		$('#status_error').css('display', 'block');
	}
	return pass;
}

function validateSelectMemberForm(form) {
	var pass = true;
	var member_list = $('#' + form + ' :checked');
	$('#status_error').css('display', 'none');
	if ( member_list.length < 1 ) {
		$('#status_error').css('display', 'block');
		pass = false;
	}
	return pass;
}

function showHotel() {
	$('#hotel_wrapper').css('display', 'block');
	$('#hotel_id').attr('required', '1');
}

function hideHotel() {
	$('#hotel_wrapper').css('display', 'none');
	$('#hotel_id').attr('required', '0');
	$('#hotel_id option:contains(Select One...)').attr("selected", true);
}

//hover-show content for "video problems?"
function get_elm_id(item) {
  return document.getElementById(item); 
}

function showDescription() {
  var desc = get_elm_id('class-description');
  var h3 = get_elm_id('class');
    
  desc.className = 'on';
  desc.style.width = h3.offsetWidth + 'px';
  desc.style.left = (h3.offsetLeft + 15 ) + 'px';
  desc.style.top = (h3.offsetTop + 35 ) + 'px';
}

function noDescription() {
  var desc = get_elm_id('class-description');
    
  desc.className = '';
  desc.style.width = '0px';
  desc.style.left = '-9999px';
}
//end hover-show