//main menu 

var timeout	= 500;
var closetimer	= 0;
var ddmenuitem	= 0;

function mopen(el_id){

	mcancelclosetime();
	
	ddmenuitem = document.getElementById(el_id);
	
	ddmenuitem.style.display = "";

}

function mclose()
{
	if(ddmenuitem) ddmenuitem.style.display = 'none';
}

function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

function toggleSlide(id_name){
	$('#'+id_name).slideToggle();
}

function toggleReadMore(id_name,id_link){
	
	var el = document.getElementById(id_name);
	var el_link = document.getElementById(id_link);
	
	if(el.style.display=="none"){
		el.style.display="";
		el_link.innerHTML = "<a href=\"#\" onclick=\"toggleReadMore('"+id_name+"','"+id_link+"');return false;\">Hide</a>";
	}else{
		el.style.display="none";
		el_link.innerHTML = "<a href=\"#\" onclick=\"toggleReadMore('"+id_name+"','"+id_link+"');return false;\">Read More</a>";
	}
	
}

function toggleShowMore(id_name,id_link){
	
	
	var el = document.getElementById(id_name);
	var el_link = document.getElementById(id_link);
	
	if(el.style.display=="none"){
		el.style.display="";
		el_link.innerHTML = "<a href=\"#\" onclick=\"toggleShowMore('"+id_name+"','"+id_link+"');return false;\">Hide</a>";
	}else{
		el.style.display="none";
		el_link.innerHTML = "<a href=\"#\" onclick=\"toggleShowMore('"+id_name+"','"+id_link+"');return false;\">Show More</a>";
	}							  
}

var curContent;
var sliderOut=false;

function togglePlayerContent(content_num){
	var el_slider = document.getElementById("playerslider");
	foundItem = false;

	for(i=1;i<=6;i++){

		var el = document.getElementById('playercon'+i);
		if(i==content_num && curContent!=i){
			el.style.display="";
			foundItem = true;
		}else{
			el.style.display="none";
		}
	
	}
	
	curContent = content_num;
	
	if(foundItem && !sliderOut){ 
		$('#playerslider').slideDown('fast');
		//Effect.SlideDown(el_slider, {duration:.5}); 
		sliderOut=true; 
	}
	if(!foundItem && sliderOut){ 
		$('#playerslider').slideUp('fast');
		//Effect.SlideUp(el_slider, {duration:.5}); 
		sliderOut=false; 
		curContent=0; 
	} 
	
}

var curContentNW;
var sliderOutNW=false;

function toggleNewsContent(content_num){
	
	var el_slider = document.getElementById("nwslider");
	foundItem = false;

	for(i=1;i<=3;i++){

		var el = document.getElementById('nwcon'+i);
		if(i==content_num && curContentNW!=i){
			el.style.display="";
			foundItem = true;
		}else{
			el.style.display="none";
		}
	
	}
	
	curContentNW = content_num;
	
	if(foundItem && !sliderOutNW){ Effect.SlideDown(el_slider, {duration:.5}); sliderOutNW=true; }
	if(!foundItem && sliderOutNW){ Effect.SlideUp(el_slider, {duration:.5}); sliderOutNW=false; curContentNW=0; } 
	
}

function toggleArtistContent(content_num){
	
	var el_slider = document.getElementById("playerslider");
	foundItem = false;

	for(i=1;i<=3;i++){

		var el = document.getElementById('playercon'+i);
		if(i==content_num && curContent!=i){
			el.style.display="";
			foundItem = true;
		}else{
			el.style.display="none";
		}
	
	}
	
	curContent = content_num;
	
	if(foundItem && !sliderOut){ Effect.SlideDown(el_slider, {duration:.5}); sliderOut=true; }
	if(!foundItem && sliderOut){ Effect.SlideUp(el_slider, {duration:.5}); sliderOut=false; curContent=0; } 
	
}

var toggled = false;
function expandAllListing(classname){
	
	if(toggled == false){
		var els = getElementsByClassName(classname);
		for(var i=0;i<els.length;i++){
			els[i].style.display = "";	
		}
		toggled = true;
		$('#expand').hide();
		$('#collapse').show();
	}else if(toggled == true){
		var els = getElementsByClassName(classname);
		for(var i=0;i<els.length;i++){
			els[i].style.display = "none";	
		}
		toggled = false;
		$('#expand').show();
		$('#collapse').hide();
	}
	
}

function launchSendToFriend(filename, width){
		var args = "filename="+filename;
		window.open("/sendtofriend.html?mode=video&"+args+"", 'Photo_Popup', 'width='+width+', height=400, top=125, screenY=125, left=150, screenX=150, menubar=no, toolbar=no, location=no, directories=no, scrollbars=yes, resizable=yes');

}

function launchSendPicToFriend(filename, width){
		var args = "filename="+filename;
		window.open("/sendtofriend.html?mode=photo&"+args+"", 'Photo_Popup', 'width='+width+', height=400, top=125, screenY=125, left=150, screenX=150, menubar=no, toolbar=no, location=no, directories=no, scrollbars=yes, resizable=yes');

}

function launchSendPlaylistToFriend(filename, width){
		var args = "filename="+filename;
		window.open("/sendtofriend.html?mode=playlist&"+args+"", 'Photo_Popup', 'width='+width+', height=400, top=125, screenY=125, left=150, screenX=150, menubar=no, toolbar=no, location=no, directories=no, scrollbars=yes, resizable=yes');

}

function launchContestTerms(contest){
	window.open("/contest_terms.html?contest_name="+contest+"", 'Contest_Terms', 'width=500, height=400, top=125, screenY=125, left=150, screenX=150, menubar=no, toolbar=no, location=no, directories=no, scrollbars=yes, resizable=yes');
	
}

function launchSendArticleToFriend(filename, width){
		var args = "filename="+filename;
		window.open("/sendtofriend.html?mode=article&"+args+"", 'Photo_Popup', 'width='+width+', height=450, top=125, screenY=125, left=150, screenX=150, menubar=no, toolbar=no, location=no, directories=no, scrollbars=yes, resizable=yes');

}

function getElementsByClassName(classname) {

node = document.getElementsByTagName("body")[0];

var a = [];

var re = new RegExp('\\b' + classname + '\\b');

var els = node.getElementsByTagName("*");

for(var i=0,j=els.length; i<j; i++)

if(re.test(els[i].className))a.push(els[i]);

return a;

}

var count = 1;

function getMoreVideos(){
	offset = count * 8;
	$.ajax({
        	type: "GET",
		url: "/morevideos.php?offset="+offset,
		dataType: "xml",
		success: function(xml) {
			moreVideosGot(xml);
			$(".popupbox").colorbox({trasition:"fade", scrolling: "false", innerWidth:500, innerHeight:300, inline:true, iframe:true});
		}
	});
	count++;
}

function moreVideosGot(t){

	var xmlDoc = t;
		
	var xmlItems = xmlDoc.getElementsByTagName('video');
		
	var newhtml = "";
	
	for (var i=0;i<xmlItems.length;i++){

			var videolink = xmlItems[i].getAttribute("videolink");
			var artistlink = xmlItems[i].getAttribute("artistlink");
			var thumbnail = xmlItems[i].getAttribute("thumbnail");
			var artistname = xmlItems[i].getAttribute("artistname");
			var videoname = xmlItems[i].getAttribute("videoname");
			var playlist_add0 = xmlItems[i].getAttribute("playlist_add0");
			var playlist_add1 = xmlItems[i].getAttribute("playlist_add1");
			var playlist_add2 = xmlItems[i].getAttribute("playlist_add2");
			var playlist_add = playlist_add0+'?'+playlist_add1+playlist_add2;
			newhtml += "<li><div class='item'><div class='tn'>"+playlist_add+"<a href='"+videolink+"'><img src='"+thumbnail+"'  alt='"+artistname+" - "+videoname+"' /></a></div><h2><a href='"+artistlink+"'>"+artistname+"</a></h2><h3><a href='"+videolink+"'>"+videoname+"</a></h3></div></li>";
	}		
	var el = document.getElementById('newvideos');
	el.innerHTML = newhtml;
}

//Utility Functions
function copytoClipboard(text){
	text.execCommand("Copy");
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//Search Functions
function track_search(page, search_hash, url){
	$.ajax({
	   type: "GET",
	   url: "/track_click.php",
	   data: 'page='+encodeURIComponent(page)+'&shash='+search_hash+'&search_url='+encodeURIComponent(url),
	   success: function(data){
	   }
	 });
}

function track_ringtone(page, url){
	$.ajax({
	   type: "GET",
	   url: "/track_click.php",
	   data: 'page='+encodeURIComponent(page)+'&shash='+search_hash+'&search_url='+encodeURIComponent(url),
	   success: function(data){
	   }
	 });
}


function add_member_group(user_ID, artist){
	$.ajax({
	   type: "GET",
	   url: "/artist_ajax.php",
	   data: 'mode=add&user_ID='+user_ID+'&artist='+artist,
	   success: function(data){
		   	$('#becomefan').hide();
			$('#notfan').hide();
			$('#fan').show();
	
			var numfans = $('#numfans');
			var num = numfans.html();
			num = parseInt(num.replace(/\,/, ''));
			$('#numfans').text(addCommas(num+1));
	   }
	 });
}


function remove_member_group(user_ID, artist, id){
	$.ajax({
	   type: "GET",
	   url: "/artist_ajax.php",
	   data: 'mode=delete&user_ID='+user_ID+'&artist='+artist,
	   success: function(data){
			$('#'+id).fadeOut("700");
	   }
	 });
}

function add_member_group2(user_ID, artist){
	$.ajax({
	   type: "GET",
	   url: "/artist_ajax.php",
	   data: 'mode=add&user_ID='+user_ID+'&artist='+artist,
	   success: function(data){
			$('#notfan').hide();
			$('#fan').show();
	   }
	 });
}


function newsletter_add(){
	$.ajax({
	   type: "GET",
	   url: "/newsletter_ajax.php",
	   data: 'email_address='+$('form_text').val,
	   success: function(data){
			$('#newsletter_successmessage').show();
			$('#newsletter_errormessage').text("Thanks for signing up!  You will receive a confirmation email shortly.");
			$('#footerboxnewsletter').hide();
	   }
	 });
}


function reportProblem(){

	var requiredMajorVersion = 8;
	// Minor version of Flash required
	var requiredMinorVersion = 0;
	// Minor version of Flash required
	var requiredRevision = 0;

	var flashvar;
	flashvar = GetSwfVer();
	
	$.ajax({
	   type: "GET",
	   url: "/log_problem.php",
	   data: 'flashver='+flashvar+'&problem='+$('#playerdebugger').html(),
	   success: function(data){
			togglePlayerContent(6);
			//new Effect.Highlight(bugform, { startcolor: "#ff0000", duration: 2});
			$('#bugform').html('Thank you! <br/>We are aware of your problem and we will do our best to resolve it immediately.');
			$('#bugform').effect('highlight', {}, 3000);
			setTimeout('redirect();', 3000);
	   }
	 });

}


function redirect(){
	var current = window.location;
	window.location = current+'&bug=y';
}

//Functions to add tags
function addTag(filename, userID, type){
	var newtag = $('newtag');
	if(userID > 0  && newtag != 'Add Your Tag Here' && newtag != ''){
		var opt = {
			// Use POST
			method: 'get',
			// Send this lovely data
			// Handle successful response
			onComplete: function(t){ 
				tagFormUpdate(t);
			},		
			onSuccess: function(t) {
				tagFormUpdate(t);
			},
			// Handle other errors
			onFailure: function(t) {
				alert('Error ' + t.status + ' -- ' + t.statusText);
			}
		}
		//new Ajax.Request('/tag_ajax.php?type='+type+'&userID='+userID+'&tag='+newtag.value+'&filename='+filename, opt);
		new Ajax.Request('/tag_ajax.php?type='+encodeURIComponent(type)+'&userID='+encodeURIComponent(userID)+'&tag='+encodeURIComponent(newtag.value)+'&filename='+encodeURIComponent(filename), opt);
	}else{
		alert('You Must Login to Add a Tag.');
	}

}

function tagFormUpdate(t){
	var tagform = document.getElementById('addtagform');
	tagform.innerHTML = t.responseText;
}

//End Tags


//Comments
function show_comment_block(block, num){
	var block = document.getElementById(block);
	block.style.display = 'block';
	
	var current_block_num = document.getElementById('current_block_num');
	 var current_block = document.getElementById('comment_block_'+current_block_num.value+'');
	 current_block.style.display = 'none';	
	 
	 current_block_num.value = num;
}

function show_comment_block2(block, num, start, end, total, comm_per_page, total_comms){
	
	
	var current_block_num = document.getElementById('current_block_num');
	
	if (num != current_block_num.value){
	
		//alert(current_block_num.value);
		
		//Set block to viewable
		 var block = document.getElementById(block);
		 block.style.display = 'block';
		
		 var current_block_num = document.getElementById('current_block_num');
		 var current_block = document.getElementById('comment_block_'+current_block_num.value+'');
		 current_block.style.display = 'none';	
		 
		 current_block_num.value = num;
		 	 
		 //return(true);
		
		 //update the showing text
		  
		 var start_comm = (comm_per_page * (num-1)) + 1;
		 
		 if (num == total){
		 	var end_comm = total_comms;
		 }else{
		 	var end_comm = (comm_per_page * num);
		 }
		 
		 var showing = 'Showing ' + start_comm + '-' + end_comm + ' of ' + total_comms;
		 //alert(showing);

 		 var showing1 = document.getElementById('showing1');
		 var showing2 = document.getElementById('showing2');
		 
		 showing1.innerHTML = showing;
		 showing2.innerHTML = showing;
		 
		 //update the pagination
		 var pagination1 = document.getElementById('comment_pagination_1');
		 var pagination2 = document.getElementById('comment_pagination_2');
		 
		 
		 var max_links = (end - start) + 1;
		 
		 var pagination_text = '';
		 
		 for (x=start; x<=end; x=x+1){
		 
		 	if (x == num){
		 		pagination_text = pagination_text + '<li class="active">' + x;
		 	
		 	}else{
		 	
		 		if (x < Math.ceil(max_links/2)){
					var pstart = 1;
					var pend = max_links;
					
					//alert('ONE: ' + i + ' - ' + start + ' - ' + end);
				
				}else if(x > (total - (max_links/2))){
					var pend = total;
					var pstart = total - (max_links-1);
					
					//alert('TWO: ' + x + ' - ' + start + ' - ' + end);
				
				}else{
					//$start = $i - floor(($max_links-1)/2) + 1;
					//$end = $i + floor(($max_links-1)/2);
					var pstart = x - Math.floor((max_links-1)/2);
					var pend = x + Math.floor(max_links/2);
					
					//alert('THREE: ' + x + ' - ' + start + ' - ' + end);
				
				}
		 	
		 		pagination_text = pagination_text + '<li>';
		 		
		 		pagination_text = pagination_text + '<a href="" onclick="show_comment_block2(\'comment_block_' + x + '\', ' + x + ', ' + pstart + ', ' + pend + ', ' + total +', ' + comm_per_page + ',' + total_comms + '); return false;">' + x + '</a>';
		 	}

		 	if (x<end){
		 		pagination_text = pagination_text + '&nbsp;|&nbsp;';
		 	}
		 	pagination_text = pagination_text + '</li>';
		 
		 }
		 
		pagination_text = pagination_text + '<li> &nbsp; of ' + total + '</li>';
		
		//alert(pagination_text);
		
		pagination1.innerHTML = pagination_text;
		pagination2.innerHTML = pagination_text;
	
	} //end if num!=
}



function submit_comment(filename, type, userID, usernick){
	var comment = $('#comment-ta-sm').val();
	
	//alert(filename + ' ' + type + ' ' + userID + ' ' + usernick);
	if(comment == ""){
		alert('You must enter a comment!');
	}else{
		if(userID > 0){
			$.ajax({
			   type: "GET",
			   url: "/comment_ajax.php",
			   data: 'userID='+encodeURIComponent(userID)+'&usernick='+encodeURIComponent(usernick)+'&comment='+encodeURIComponent(comment)+'&type='+encodeURIComponent(type)+'&filename='+encodeURIComponent(filename),
			   success: function(data){
				 
				$('#commentform2').html(data)
				var commentnum = $('#commentnum');
				var num = commentnum.html();
				num = parseInt(num.replace(/\,/, ''));
				$('#commentnum').text(addCommas(num+1));
				updateComments(filename);
				updateCommentForm(filename);
			   }
			 });
		}else{
			alert('You Must Login to Comment.');
		}
	}
}
//END Comments


//Stars

starsEnabled = true;
rated = false;

function starSet(num,showHover){
	if(starsEnabled){
		var hover_txt = document.getElementById('star_hover_text');
		
		if(!showHover){
			hover_txt.innerHTML = "";
		}else{
			switch(num){
			  case(1):
			  hover_txt.innerHTML = "This Sucks";
			  break;
			  case(2):
			  hover_txt.innerHTML = "Kinda Lame";
			  break;
			  case(3):
			  hover_txt.innerHTML = "Okay";
			  break;
			  case(4):
			  hover_txt.innerHTML = "Pretty Sweet";
			  break;
			  case(5):
			  hover_txt.innerHTML = "Awesome";
			  break;
		   }
		}
		
		for(i=1;i<=5;i++){
			
			var star = document.getElementById('star'+i);
			
			if(i<=num){
				star.className = "one_star";
			}else{
				star.className = "three_star";	
			}
		}
	}
	
}

function starSetLock(num){
		
		starsEnabled = false;
		
		for(i=1;i<=5;i++){
			
			var star = document.getElementById('star'+i);
			
			if(i<=num){
				star.className = "one_star_lock";
			}else{
				star.className = "three_star";	
			}
		}
	
}

function setStarRating(rating,filename,userID, type){
	if(type=='')type = 'video';
	starSetLock(rating)
	$.ajax({
  		   type: "POST",
		   url: "/rate.php",
		   data: 'filename='+filename+'&userID='+userID+'&rating='+rating+'&type='+type,
		   success: function(data){
				starRatingSet();
				createCookie("rating"+filename,rating,365);
		   }
		 });
}

var starRatingSet = function(t) {
	var hover_txt = document.getElementById('star_hover_text');
	hover_txt.innerHTML = "Thanks for Voting!";
	$rating = readCookie(name);
	if(!$rating && rated!=true){
		rated=true;
		var num = $('#total_ratings').html();
		num = parseInt(num.replace(/\,/, ''));
		$('#total_ratings').text(addCommas(num+1));
	}
}

function convert(x)
{
  var _x=x.toString();
  var _len=_x.length;
  var _ret="";
  for(var i=_len;i>0;i--)
  {
    if(!((_len-i)%3))
    {
      _ret=","+_ret;
    }
    _ret=_x[i-1]+_ret;
  }
  _ret=_ret.substr(0,_ret.length-1);
  return _ret;
} 


function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}
//END Stars

function change_parent_url(url){
   parent.document.location=url;
}	


//Watching Starts
function watching_refresh(){
	//alert('test');
	$.ajax({
   type: "GET",
   url: "/watching_ajax.php",
   data: "",
   success: function(data){
     $('#watching').html(data);
	 $('#watchingmessage').css("display", "block");
	 $('#watchingmessage').effect('highlight', {}, 3000);
	 $('#watchingmessage').effect('clip');
	 restart_timer();
   }
 });
}
								
function restart_timer(){
	setTimeout(watching_refresh, 10000);
}
//End Watching

//Cookies
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

//Moved from player_blastro.js
function PlayerSettingsCookie() {

	document.cookie = "playerSettingsUpdate=true; path=/";
	return true;
}
//End Cookies

//Start Favorites
function removeFavorite(user_ID, filename){

	$('#'+filename).fadeOut();
	$.ajax({
   type: "GET",
   url: "/favorites_ajax.php",
   data: 'action=remove&filename='+filename+'&user_ID='+user_ID,
   success: function(data){ }
	});
}

function addtoFavorites(user_ID, filename){
	if(user_ID < 0 || user_ID == ""){
		togglePlayerContent(2);
		$('favform').html('You must be logged in to add Favorites. <a href="/login.php?action=login&redirect_to='+location.href+'" style="color:white">Login Here</a>');
	}else{
		$.ajax({
		   type: "POST",
		   url: "/favorites_ajax.php",
		   data: "action=add&user_ID=" + user_ID + "&filename=" + filename,
		   success: function(data){ 
			   favorites_added();
			   }
		   });
	}	
}

function favorites_added() {
	
	$('#favform').html('Added to Favorites!');
	$('#removefav').show();
	$('#addfav').hide();
			
	urchinTracker("/favorites_added.html");
			
	var numfans = $('#favoritenum');
	var num = numfans.html();
	num = parseInt(num.replace(/\,/, ''));
	$('#favoritenum').text(addCommas(num+1)); 
	togglePlayerContent(2);
}

function removeFavorites(user_ID, filename){
	if(user_ID < 0){
		togglePlayerContent(2);
		$('favform').html('You must be logged in to add Favorites. <a href="/login.php?action=login&redirect_to='+location.href+'" style="color:white">Login Here</a>');
	}else{
		$.ajax({
		   type: "POST",
		   url: "/favorites_ajax.php",
		   data: "action=remove&user_ID=" + user_ID + "&filename=" + filename,
		   success: function(data){ 
			   favorites_removed();
			   }
		   });
	}	
}

function favorites_removed() {
	
	$('#favform').html('Removed from Favorites!');
	$('#removefav').hide();
	$('#addfav').show();
			
	urchinTracker("/favorites_added.html");


	var numfans = $('#favoritenum');
	var num = numfans.html();
	num = parseInt(num.replace(/\,/, ''));
	$('#favoritenum').text(addCommas(num-1)); 
	
	togglePlayerContent(2);
}
//End Favorites


//Got a Bug
function reportproblem(){
	
	$.ajax({
		   	type: "POST",
		   	url: "/gotabug_ajax.php",
		   	data: "email=" + $('#email').val() + "&url=" + $('#url').val() +  "&os=" + $('#os').val() +  "&browser=" + $('#browser').val() +  "&problem=" + $('#problem').val() +  "&ip=" + $('#ip').val() + "&user=" + $('#user').val() + "&referer=" + $('#referer').val(),
			success: function(data){ 
			    $('#bugform').hide();
        		$('#success').show();
			
			bug.style.display = "none";
			success.style.display = "block";
		}
	});
}

//END Bug

//Playlist
//Functions to add tags
function addPlaylist(filename, userID){
	playlist_id = $('#existingplaylist').val();

	if(userID > 0  && filename != ''){
		$.ajax({
		   type: "GET",
		   url: "/playlist_ajax.php",
		   data: 'action=add&playlist_id='+playlist_id+'&userID='+userID+'&filename='+filename,
		   success: function(data){
				playlistFormUpdate(data);
		   }
		 });
	}else{
		alert('You Must Login to Add a video to a playlist.');
		$('#playlistname').effect('highlight', "#ff0000", 10000);
		// startcolor: , duration: 10});
	}
}

function addtoNewPlaylist(filename, userID){
	var playlistname = $('#playlistname').val();
 	if(playlistname != ''){
		if(userID > 0  && filename != ''){
			$.ajax({
				type: "GET",
			   	url: "/playlist_ajax.php",
				data: 'action=addtonew&playlistname='+playlistname+'&userID='+userID+'&filename='+filename,
			   	success: function(data){
					playlistFormUpdate(data);
			   	}
			 });
		}else{
			alert('You Must Login to Add a video to a playlist.');
		}
	}else{
		alert('Playlist name cannot be blank.  Please enter a title.');
	}
}


//Need two functions because we can add suggested videos and artists videos from the player page and need to update similar code with same ids
function addPlaylist2(filename, userID){
	var playlist_id = $('#existingplaylist2').val();
	if(userID > 0  && filename != ''){
			$.ajax({
			   type: "GET",
			   url: "/playlist_ajax.php",
			   data: 'action=add&playlist_id='+playlist_id+'&userID='+userID+'&filename='+filename,
			   success: function(data){
					playlistFormUpdate2(data);
			   }
			 });
	}else{
		alert('You Must Login to Add a video to a playlist.');
	}
}

function addtoNewPlaylist2(filename, userID){
	
	var playlistname = $('#playlistname2').val();
	if(playlistname != ''){
		if(userID > 0  && filename != ''){
			$.ajax({
			   type: "GET",
			   url: "/playlist_ajax.php",
			   data: 'action=addtonew&playlistname='+playlistname+'&userID='+userID+'&filename='+filename,
			   success: function(data){
					playlistFormUpdate2(data);
			   }
			 });
		}else{
			alert('You Must Login to Add a video to a playlist.');
		}
	}else{
		alert('Playlist name cannot be blank.  Please enter a title.');
		$('plalylistname2').effect('highlight', {}, 10000);
		//new Effect.Highlight('playlistname2', { startcolor: '#ff0000', duration: 10});
	}
}


function removePlaylist(id, filename, oid, userID, playlist_id){
	if(userID > 0  && oid != '' && filename != ''){
			$.ajax({
			   type: "GET",
			   url: "/playlist_ajax.php",
			   data: 'action=remove&playlist_id='+playlist_id+'&userID='+userID+'&oid='+oid+'&filename='+filename,
			   success: function(data){
					$("li[name='"+id+"']").fadeOut();
			   }
			 });

	}else{
		alert('You Must Login to Remove a video from your playlist.');
	}
}

function deletePlaylist(userID, playlist_id){
	if(userID > 0 ){
		$.ajax({
		   type: "GET",
		   url: "/playlist_ajax.php",
		   data: 'action=delete&playlist_id='+playlist_id+'&userID='+userID,
		   success: function(data){
	   			$('#playlist_'+playlist_id).fadeOut(700);
		   }
		 });
	}else{
		alert('You Must Login to Remove a video from your playlist.');
	}

}

function playlistFormUpdate(data){
	$('#playlistform').hide();
	$('#playlistmessage').text(data);
	setTimeout("parent.$.fn.colorbox.close()", 1500);
}

function playlistFormUpdate2(data){
	$('#playlistform2').hide();
	$('#playlistmessage2').text(data);
	$('#playlistmessage2').effect('highlight', {}, 1500);
	setTimeout("parent.$.fn.colorbox.close()", 1500);
}
//End Playlist