// PLAYER PAGE FUNCTIONS
function addToChannel(video) {
	var channel = $('channel_id').getValue();
	var featured = $('is_featured').getValue();
	new Ajax.Request('/player/ajx/.addtochannel.php', {
		parameters: { channel: channel, video: video, featured: featured },
		onSuccess: function(r) { $('videoChannels').update(r.responseText);$('v_chan-list-wrap').highlight({startcolor: '#ffff99',endcolor: '#EEEECC'});}
	});
}
function remFromChannel(id) {
	new Ajax.Request('/modules/player/ajx/.remfromchannel.php', {
		parameters: { remove: id },
		onSuccess: function(r) { $('videoChannels').update(r.responseText);$('v_chan-list-wrap').highlight({startcolor: '#ffff99',endcolor: '#EEEECC'}); }
	});
}
function rateVideo(rating, video) {
	new Ajax.Request('/modules//player/ajx/.ratevideo.php', {
		parameters: { video: video, rating: rating },
		onSuccess: function(r) { $('rating').update(r.responseText); }
	});
}

function emailResults(r) {
	toggleShareThis();
	$('emailThisResults').update(r);
}
function emailThis() {
	var email = $('emailto').getValue();
	var regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
	if (regex.test(email)==true) {
		$('emailTheseWrap').show();
		$('emailTheseWrap').highlight();
		$('emailThese').insert('<li><input name="emails[]" type="hidden" value="'+email+'" />'+email+'</li>');
		$('emailto').value='';
	} else alert(email+' is an invalid address.');
}

function emailThisIA(email,user) {
	$('emailThese').insert('<li><input name="emails[]" type="hidden" value="'+email+'" />'+user+'</li>');
	$('emailtoia').value='';
	$('users_found').hide();
	$('emailTheseWrap').show();
	$('emailTheseWrap').highlight();
}

function toggleEmailField(selTab) {
	$$('.share-this-tab').each(function(x) {
		$(x).removeClassName('active-tab');
	});
	$(selTab).addClassName('active-tab');
	$('enterEmail').toggle();
	$('findStaff').toggle();
}

function findStaffEmail() {
	var str = $('emailtoia').getValue();
	if(str.length>=3) {
		new Ajax.Updater('users_found', '/player/ajx/.findstaffemail.php', {
			parameters: { empname: str, TYPE: 'SM' },
		 	evalScripts: true
		});
		$('users_found').show();
	} else {
		$('users_found').hide();
	}
}

function toggleShareThis() {
	if ($('emailThisWrap').getStyle('display') == "none") {
		$('flag-this').removeClassName('v_flag-video-link-active');
		$('flagVideoWrap').hide();
		$('share-this').addClassName('v_email-video-link-active');
		$('emailThisWrap').show();
	}
	else {
		$('share-this').removeClassName('v_email-video-link-active');
		$('emailThisWrap').hide();
	}
}

function toggleFlagThis() {
	if ($('flagVideoWrap').getStyle('display') == "none") {
		$('share-this').removeClassName('v_email-video-link-active');
		$('emailThisWrap').hide();
		$('flag-this').addClassName('v_flag-video-link-active');
		$('flagVideoWrap').show();
	}
	else {
		$('flag-this').removeClassName('v_flag-video-link-active');
		$('flagVideoWrap').hide();
		
	}
}

function resetPlayerOptions() {
	$('flag-this').removeClassName('v_flag-video-link-active');
	$('flagVideoWrap').hide();
	$('share-this').removeClassName('v_email-video-link-active');
	$('emailThisWrap').hide();
}

function addFavorite(vid) {
	/*var favLoader = new Element('img', {
							src: '/images/favorite-loader.gif',
						});
	$('v_favorite-link').insert({ 'before' : favLoader });*/
	resetStaffTabs();
	new Effect.Opacity('v_favorite-link', {
			from: 0.5,
			to: 0,
			duration: 0.2
		});
	new Ajax.Request('/player/ajx/.addfavorite.php', {
		parameters: { video_id: vid },
		evalScripts: true,
		onSuccess: function(r) {
			$('v_so-fav-status').show();
			new Effect.Appear('v_favorite-link', {
				from: 0,
				to: 1,
				duration: 0.2
			});
			$('v_favorite-link').update(r.responseText);
			$('v_so-fav-status').update('Added to favorites');
			$('v_so-fav-tab').addClassName('v_so-active-tab');
		}
	});
}
function remFavorite(vid) {
	resetStaffTabs();
	new Effect.Opacity('v_favorite-link', {
			from: 0.5,
			to: 0,
			duration: 0.2
		});
	new Ajax.Request('/player/ajx/.remfavorite.php', {
		parameters: { video_id: vid },
		evalScripts: true,
		onSuccess: function(r) {
			$('v_so-fav-status').show();
			new Effect.Appear('v_favorite-link', {
				from: 0,
				to: 1,
				duration: 0.2
			});
			$('v_favorite-link').update(r.responseText);
			$('v_so-fav-status').update('Removed from favorites');
			$('v_so-fav-tab').addClassName('v_so-active-tab');
		}
	});
}