/* *** VIDEO CONTROL *** */

function replaceAll(stringValue, replaceValue, newValue)
{
	var functionReturn = new String(stringValue);
	while ( true )
	{
		var currentValue = functionReturn;
		functionReturn = functionReturn.replace(replaceValue, newValue);
		if ( functionReturn == currentValue )
			break;
		}
	return functionReturn;
}



function controlTogglePlay(){
	var thePlayer = 'player1';
	player = document.getElementById(thePlayer);
	player.sendEvent("PLAY");
}


//comparte con facebook
 function encodeface(index){
                  var currentVideoIndex = index;
                  var s = encodeURI(laurlface); 
                  abreface = window.open(s)
                  return abreface;

 
}	
	     
 
// fin comparte con facebook	     
 
 
// comparte con twitter


        		function twit(index){
              		var videoPlayingIndex = index;
              		
          			BitlyCB.shortenResponse = function(data) {//alert("Viendo");
                          var s = '';
                          var first_result;
                          // Results are keyed by longUrl, so we need to grab the first one.
                          for     (var r in data.results) {
                                  first_result = data.results[r]; break;
                                 
                          }
                          
                          for (var key in first_result) {
                          
                                  s += key + ":" + first_result[key].toString() + "\n";
                          
                          }
          
                          var twite= "http://twitter.com/home?status=Viendo en PSOE.tv: " + first_result['shortUrl'];
                          twitee = window.open(twite)
          
                          
                          return twitee;
                          
                  	}

             BitlyClient.shorten(laurl, 'BitlyCB.shortenResponse');
      
      		}	
          
          
//// fin comparte con twiter 

function playVideo(index, showing){
	currentVideoIndex = index;
	currentlyShowing = showing;
	highlightPlaylistItem(index);
	displayPlayingItem(index, showing);
	initPlayer(currentVideoIndex);
	  
	$("#sidebar").show();
	$("#sidebar_flow").hide();

	
	/** Herramientas de descargar embeber y demás**/
	
	 var herramientas = "";
	 
	 	if(currentlyShowing == 'content'){
	 	
  	 var URLFriendlyTitle = replaceAll(contentArray[index].Title, " ", "-");
     var URLFriendlyTitle = URLFriendlyTitle.replace(/\"/g, "");
   	 var descargoVideo = contentArray[index].VideoPath;
  	 var elmetaID = contentArray[index].ContentMetaDataID;
    }

		if(currentlyShowing == 'search'){
		
  	 var URLFriendlyTitle = replaceAll(searchContentArray[index].Title, " ", "-");
  	 var URLFriendlyTitle = URLFriendlyTitle.replace(/\"/g, "");
  	 var descargoVideo = searchContentArray[index].VideoPath;
  	 var elmetaID = searchContentArray[index].ContentMetaDataID;
		}

 herramientas += "<li ><a href='download.php?file="+descargoVideo+"'>Descargar v&iacute;deo</a></li>";
 herramientas += "<li ><a href='embed.php?path="+descargoVideo+"&baseurl="+baseurl+"' onclick=\"return GB_showCenter('Embeber v&iacute;deo', this.href , 230, 500)\">Embeber v&iacute;deo</a></li>";
 herramientas += "<li ><a href='link.php?link="+baseurl+"video/"+ elmetaID +"/"+ URLFriendlyTitle +"/index.php' onclick=\"return GB_showCenter('Enlace al v&iacute;deo', this.href , 140, 540)\">Enlace al v&iacute;deo</a></li>";

	$("ol.navTools").html(herramientas);
	
	// los links para compartir
	var comparte = "";
	laurl= baseurl+"video/"+ contentArray[index].ContentMetaDataID +"/"+ URLFriendlyTitle +"/index.php";
  laurlface = "http://facebook.com/share.php?u=" + laurl;
   
	comparte += "<li><a href='#' onclick='javascript:encodeface(); return false' class='shareFacebook' title='Compartir en Facebook'>Compartir en Facebook</a></li>";
	comparte += "<li><a target='_blank' href='http://del.icio.us/post?url="+laurl+"' class='shareDelicious' title='Compartir en Delicious'>Compartir en Delicious</a></li>";
	comparte += "<li><a target='_blank' href='http://meneame.net/submit.php?url="+laurl+"' class='shareMeneame' title='Compartir en Meneame'>Compartir en Meneame</a></li>";
	comparte += "<li><a a href='#' onclick='javascript:twit(); return false' class='shareTwitter' title='Compartir en Twitter'>Compartir en Twitter</a></li>";
//	comparte += "<li><a href='#' class='shareTechnorati' title='Compartir en Technorati'>Compartir en Technorati</a></li>";
//	comparte += "<li><a href='#' class='shareYahoo' title='Compartir en Yahoo!'>Compartir en Yahoo!</a></li>";
//	comparte += "<li><a href='#' class='shareMySpace' title='Compartir en MySpace'>Compartir en MySpace</a></li>";
						
	$("ol#comparte").html(comparte);
	
			
}
