/* *** PLAYLIST *** */


function switchPlaylist(index){
	currentPlaylist  = playlists[index];
	if(currentPlaylist == ""){return;}
	
	if(currentPlaylist==471)
	{
		audioflag=1;
	}
	else
	{
		audioflag=0;
	}

	$.ajax({
		type: "POST",
		url: "vzService/contentajax.php",
		data: "playlistID="+currentPlaylist+"",
		contentType: CONTENT_TYPE,
		success: function(msg){ 
			try{
				eval(msg);
				if(contentArray[0].Title != ""){
					currentlyShowing = 'content';
						
					buildPlaylistContent();
					playVideo(0, currentlyShowing);
				//	$('#pane')[0].scrollTo(1*index);
					$('#pane')[0].scrollTo(1);

					
				}else{
					alert("No hay resultados que mostrar.");
				}
			}catch(exception){
				alert("No hay resultados que mostrar. Error:" + exception);
			}
		}
	});
					
}

function highlightPlaylistItem(index) { 
	
				try{
			/*$(".titulo").removeClass("selected"); //remove all the previous playlist highlights
		$("#item" + index).addClass("selected"); // find which playlist item to highlight*/
		$(".uvlItemBox").removeClass("selected"); //remove all the previous playlist highlights
		$("#itemu" + index).addClass("selected"); // find which playlist item to highlight
		
				if(index > 0){
				
				/*if (contentArray.length== 3 || contentArray.length== 2 ||contentArray.length== 1 || searchContentArray.length== 3 || searchContentArray.length== 2 ||searchContentArray.length== 1){
	
          $('#pane')[0].scrollTo(1*index); //si sólo hay 1 2 ó 3 vídeos no hagas scroll para centrar el highlight en la playlist 
            }else{*/
					$('#pane')[0].scrollTo(74*index); //-18 //88
          /*}*/
							                                
					}
			}catch(ex){
				// we might not be have to highlight this, if it's an advert.
			}
	
	
}

function displayPlayingItem(index, showing){
	var playingItem;
	currentlyShowing = showing;

	//Reset the vars used, so we can start fresh.
	$("#sidebar h2").html(""); //current_video_title 
	$("#sidebar #slider li#descripcion").html(""); // current video description
	$('.playlist_item_link').unbind('click'); 

	videoPlayer_ControlBar = 'over';

	if(currentlyShowing == 'content'){ playingItem = contentArray[index]; }
	if(currentlyShowing == 'search'){ playingItem = searchContentArray[index]; }
	$("#sidebar h2").html(playingItem.Title); //current_video_title
	$("#sidebar #slider li#descripcion").html(playingItem.LongDesc); // current video description
	

	if(playingItem.NoClickAway == 'true'){
		$(".playlist_item_link").click(function() { return false; });
		videoPlayer_ControlBar = 'none';
	}


}


//Build Playlist.
function buildPlaylistContent(){

	//if(currentlyShowing == 'content'){ 
  


	var playingItem;
	$("#playlistInner").html(""); //clear contents.
	var playlistContentBuilder = "";


	 contentLength = 0; //aaaa
	  //contentLength = contentArray.length; 
	  	
	if(currentlyShowing == 'content'){ contentLength = contentArray.length; }
	if(currentlyShowing == 'search'){ contentLength = searchContentArray.length; }
	
	     /* var navegador = window.navigator.userAgent;
      var numero= navegador.substring(30,31);
     
       if (numero==6){
        largoPlaylist = (contentLength * 72)+15; //calculate the playlist's lenght for IE6. Varaible used at the end of the page
      }else if (numero=="e"){
        largoPlaylist = (contentLength * 58)+15; //calculate the playlist's lenght for Safari 4
      }else{
        largoPlaylist = (contentLength * 52)+15; //calculate the playlist's lenght for the rest
      }
      
			alturaPlaylist(largoPlaylist);*/


	for(var i=0;i < contentLength;i++){
		var thumbnailpath = '';
		var title = '';
		var doNotShowInPlaylist = 'false';
		var adTag = '';
		var shortDesc = '';
		var longDesc ='';
		var playlistid='';
		var playlistname='';
		var duracion='';
		
    playingItem = contentArray[i]; 

		if(currentlyShowing == 'content'){ playingItem = contentArray[i]; }
		if(currentlyShowing == 'search'){ playingItem = searchContentArray[i]; }

		thumbnailpath = playingItem.ThumbnailPath;
		title = playingItem.Title;
		atitle = title.replace(":", "");
		aatitle = atitle.replace("\"", "");
		aaatitle = aatitle.replace("\"", "");
		shortDesc = playingItem.ShortDesc; 
    doNotShowInPlaylist = playingItem.DoNotShowInPlaylist;
		adTag = playingItem.AdTag;
		longDesc = playingItem.LongDesc;
		duracion = playingItem.Duration; 
	
		// minutes and seconds for duration (comes from Lenght all in seconds)		
		minVar = Math.floor(duracion/60);  // minutes
    secVar = duracion % 60;              //  seconds
      
      // add a zero to the seconds   
      secVarS = secVar+'' // turn integer into string for .length to work
      secVarS = secVarS.length; // how many characters?
      if (secVarS==1) //if it has just one decimal, just one charater
      {
          secVar= secVarS*10; //add a zero 
      }


		playlistid = playingItem.PlaylistID;
 	 var descargas = playingItem.VideoPath;
			
			  	 var URLFriendlyTitle = replaceAll(playingItem.Title, " ", "-");
     var URLFriendlyTitle = URLFriendlyTitle.replace(/\"/g, "");
 
  	 var elmetaID = playingItem.ContentMetaDataID;
  	 
  	 longDesc = replaceAll(longDesc,"\'","");
     var longDesc2 = longDesc.split("<br/>");
     longDesc2 = longDesc2[0];
     
     if (longDesc.length > 78)
     {
     	longDesc = longDesc.substr(0,78);
     	longDesc = longDesc + "...";
  	 }		
  	 
  	// alert(elmetaID);
  	 			
	/*var laURLr = playingItem.Lnk;
	if(laURLr != ""){ 

	
    var theurl_last3 = laURLr.substr(laURLr.length - 3);
    	
    var laURLreservar = "http://www.parador.es/es/cargarReOnParador.do?codigoParador="+theurl_last3;
    //alert(laURLreservar);
  	var reservButton = "<div id='reservar'><a href="+laURLreservar+" target='_blank'><img src='img/info_reservar.png' border=0/></a></div>";
  	$("#parareserva").html("");    
   $("#parareserva").append(reservButton);
  
  }*/

     
     /*
			if(playingItem.Lnk == ""){ 
 
  		$(".tiempo").html("<a title='Pulsa aqu&iacute; para + informaci&oacute;n' href='main.php' target='_blank'><img border="0/" src="img/info_reservar.png"></a>");
  	
			}

*/

  	 
  	 
/*
        	 
  var ponPlaylistName ="";
	ponPlaylistName += ""+playlistname+"";
 	$("#dentroparatitulo").html(ponPlaylistName);*/
 	
 	
 	

		 // deal with missing thumbnails
		if(thumbnailpath == ""){ thumbnailpath = THUMBNAIL_MISSING; }
	
		if(doNotShowInPlaylist == 'false'){
      
   playlistContentBuilder +="<div class='uvlItemBox' id='itemu"+i+"'>";
		playlistContentBuilder +="<a class='mini' href=\"javascript:playVideo("+ i +", '"+ currentlyShowing +"');\"  onclick=\"MM_showHideLayers('playlist','','show','playlist2','','hide');limpia2();_gaq.push(['_trackEvent', 'Videos', '"+aaatitle+"', 'Espanol']);\"><img title='"+title+"' class='elHolder'  src='"+thumbnailpath+"' style='height:"+THUMBNAIL_HEIGHT+"px;width:"+THUMBNAIL_WIDTH+"px;border-width:0px;' /><span></span></a>";
     playlistContentBuilder +="<div  class='uvlTextBox'>";
		playlistContentBuilder +="<a id='item"+i+"' class='uvlTitle uvlNormal' href=\"javascript:playVideo("+ i +", '"+ currentlyShowing +"');\" onclick=\"MM_showHideLayers('playlist','','show','playlist2','','hide');limpia2();\">"+title+"</a><span class='uvlAbstract uvlNormal' onmouseover=\"Tip('"+longDesc2+"')\" onmouseout=\"UnTip()\">"+longDesc+"</span><div style='display:none;'>"+elmetaID+"</div><span class='sep'>/</span></div>";
   
     playlistContentBuilder +="</div>";
    
    /*playlistContentBuilder +="<div id='rptUVL_ctl25_Times' class='uvlTimesBox'><span id='rptUVL_ctl25_StartDt' title='"+ minVar+':'+secVar +"' class='uvlStartDt uvlNormal'>"+ minVar+':'+secVar +"</span><span class='sep'>/</span></div></div>";*/
 
  
  
		}
  } //final for 

	$("#pane").html(playlistContentBuilder);
	$('#pane').jScrollPane({showArrows:true, scrollbarWidth:43, scrollbarMargin:15});
  
}//final funcion 



