/* *** TAG CLOUD *** */


function tagClicked(id, wordToSearch){
//	$('#pane')[0].scrollTo(0); // try scroll back to the top.
	//$("#tagCloud").html("<p>Cargando...</p>");
	wordsToSearch = wordToSearch;
	tagSearchClick(wordToSearch);
	

	/* //Use the below if you're getting user interaction.
	$.ajax({
		type: "POST",
		url: "vzService/tagCloud-admin-process.php",
		data: "wordToClickID="+id+"",
		contentType: CONTENT_TYPE,
		success: function(msg){ 
			try{
				//alert("came back: " +msg );
				refreshTags(); //get the new tag collection.
				tagSearchClick(wordToSearch);

				//you have to put in a search for this keyword.

			}catch(exception){
				//alert("no videos returned for this playlist. Error details:" + exception);
			}
		}
	});
	*/
}


function refreshTags(){
	$.ajax({
		type: "POST",
		url: "vzService/tagCloud.php",
		data: "process=refresh",
		contentType: CONTENT_TYPE,
		success: function(msg){ 
			try{
				eval(msg);
				displayTagCloud();
			}catch(exception){
				//alert("no videos returned for this playlist. Error details:" + exception);
			}
		}
	});

}


function displayTagCloud(){
          
	var tagCloudLength = tagcloudArray.length;


	if(tagCloudLength > 0){
		var theTagCloud = "";
		for(var i=0;i < tagCloudLength; i++){ // imprime todas las tags 
	//	for(var i=0;i < 16; i++){ // imprimo sólo 10 tags

theTagCloud = theTagCloud +  "<a href='javascript:return false;' id='tagCloudStyle' onclick=\"javascript:tagClicked(" + tagcloudArray[i].TagID + ",'" + tagcloudArray[i].TagName + "'); _gaq.push(['_trackEvent', 'Herramientas - video', 'Nube de Tags', '" + tagcloudArray[i].TagName + "']); return false;\" style='font-size: "+ tagcloudArray[i].TagSize +"px'>"+tagcloudArray[i].TagName+"</a> ";
    // alert(theTagCloud);
              /*
theTagCloud = theTagCloud +  "<a href='javascript:return false;' id='tagCloudStyle' onclick=\"javascript:tagClicked(" + tagcloudArray[i].TagID + ",'" + tagcloudArray[i].TagName + "'); return false;\" style='font-size: "+ tagcloudArray[i].TagSize +"px'>"+tagcloudArray[i].TagName+"</a> ";    */




		}
		$("#tagCloud").html(theTagCloud);
	}
}



function tagSearchClick(wordsToSearch){
	//$('#pane')[0].scrollTo(0); // try scroll back to the top.
	$("#pane").html("<p>Cargando...</p>");
	$.ajax({
		type: "POST",
		url: "vzService/search.php",
		data: "clientID="+thisChannel.ClientID+"&channelID="+thisChannel.ChannelID+"&wordsToSearch="+escape(wordsToSearch)+"",
		contentType: CONTENT_TYPE,
		success: function(msg){ 
			try{
				//alert(msg);
				eval(msg);
				if(searchContentArray[0].Title != ""){
					currentlyShowing = 'search';
					
					
								c.reset();
						 contentLength = 0; 
					contentLength = searchContentArray.length;
				//	alert(contentLength);
					    c.size(contentLength); 
					   
					   	 c.scroll(1);
					
					
					buildPlaylistContent();
					playVideo(0, currentlyShowing);
								$(".movepane").css({'top' : ' 5px'});
				}else{
					alert("No hay resultados que mostrar.");
				}
			}catch(exception){
				alert("No hay resultados que mostrar.");
			}
		}
	});
}
