/* *** 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 twitter
function twit(index)
{
	var videoPlayingIndex = index;
		
	BitlyCB.shortenResponse = function(data) 
	{
    	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 ICEX.tv: " + first_result['shortUrl'];
        twitee = window.open(twite)
  
        return twitee;          
  	}

	BitlyClient.shorten(laurlNumero, 'BitlyCB.shortenResponse');
}	

function playVideo(index, showing)
{
	$("#vidtit").html("");
	
	currentVideoIndex = index;
	currentlyShowing = showing;
	
	highlightPlaylistItem(index);
	displayPlayingItem(index, showing);
	initPlayer(currentVideoIndex);
	 
	if(currentlyShowing == 'content')
	{ 	
		var titulo = contentArray[index].Title;
		var urldelvideo = contentArray[index].VideoPath;
		var descripcionlarga = contentArray[index].LongDesc;
		var tbimg = contentArray[index].ThumbnailPath;
  		var URLFriendlyTitle = replaceAll(contentArray[index].Title, " ", "-");
     	URLFriendlyTitle = URLFriendlyTitle.replace(/\"/g, "");
   	 	var descargoVideo = contentArray[index].VideoPath;
  	 	var elmetaID = contentArray[index].ContentMetaDataID;
    }

	if(currentlyShowing == 'search')
	{	
		var titulo = searchContentArray[index].Title;
		var urldelvideo = searchContentArray[index].VideoPath;
		var descripcionlarga = searchContentArray[index].LongDesc;
		var tbimg = searchContentArray[index].ThumbnailPath;
  		var URLFriendlyTitle = replaceAll(searchContentArray[index].Title, " ", "-");
  	 	URLFriendlyTitle = URLFriendlyTitle.replace(/\"/g, "");
  	 	var descargoVideo = searchContentArray[index].VideoPath;
  	 	var elmetaID = searchContentArray[index].ContentMetaDataID;
	}
	$("#vidtit").html(titulo);
}
