function switchPlaylist(index) {
	var currentPlaylist  = playlists[index];
			
    if(currentPlaylist == ""){return;}

	$.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);
					$(".movepane").css({'top' : ' 5px'});
				
				}else{
					alert("No se han encontrado videos.");
				}
			}catch(exception){
				alert("No se han encontrado videos. Detalles del error:" + exception);
			}
		}
	});
}

function highlightPlaylistItem(index) {
	var mitad= paneheight/2;
        					
	try 
	{
		$(".playlist_item").removeClass("playlist_item_on"); //remove all the previous playlist highlights
		$("#item" + index).addClass("playlist_item_on"); // find which playlist item to highlight

		if(index > 0) {}
	}catch(ex){
		// we might not be have to highlight this, if it's an advert.
	}
}

function displayPlayingItem(index, showing) {
	currentlyShowing = showing;
	//Reset the vars.
	$("#current_video_title").html(""); 
	$("#current_video_description").html("");
	//$("#pane1").html("");
	$("#current_video_adtag").html("");
	$('.playlist_item_link').unbind('click'); 
	videoPlayer_ControlBar = 'over';

	if(currentlyShowing == 'content') {
		$("#current_video_title").html(contentArray[index].Title);
		$("#current_video_description").html(contentArray[index].LongDesc);
	
		if(contentArray[index].AdTag != "") {
			$("#current_video_adtag").html("<img src='"+contentArray[index].AdTag+"' alt='adtag'>");
		}
		
		if(contentArray[index].NoClickAway == 'true') {
			$(".playlist_item_link").click(function() { return false; });
			videoPlayer_ControlBar = 'none';
		}
		
		// This will change the title of the video to include click here for more information
		//if(contentArray[index].VideoLink == 'true' && contentArray[index].Lnk != ""){
		//	$("#current_video_title").html("<a href='"+contentArray[index].Lnk+"' target='_blank'>"+contentArray[index].Title+" - Click here for more information</a>");
		//}
	}
	
	if(currentlyShowing == 'search') {
		$("#current_video_title").html(searchContentArray[index].Title);
		$("#current_video_description").html(searchContentArray[index].LongDesc);
		//$("#pane1").html(searchContentArray[index].LongDesc);
		
		if(searchContentArray[index].AdTag != "") {
			$("#current_video_adtag").html("<img src='"+searchContentArray[index].AdTag+"' alt='adtag'>");
		}
		
		if(searchContentArray[index].NoClickAway == 'true') {
			$(".playlist_item_link").click(function() { return false; });
			videoPlayer_ControlBar = 'none';
		}
		
		// This will change the title of the video to include click here for more information
		//if(searchContentArray[index].VideoLink == 'true' && searchContentArray[index].Lnk != ""){
		//	$("#current_video_title").html("<a href='"+searchContentArray[index].Lnk+"' target='_blank'>"+searchContentArray[index].Title+" - Click here for more information</a>");
		//}
	}
	
}

//Build Playlist.
function buildPlaylistContent() {
	var playingItem;
	$("#pane").html(""); //clear contents.
	var playlistContentBuilder = "";

	var contentLength = 0;
	var i = 0;

	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 (i=0;i < contentLength;i++){
		var thumbnailpath = '';
		var title = '';
		var doNotShowInPlaylist = 'false';
		var adTag = '';
		var shortDesc = '';
		var duration = '';
		var duration_min = '';
		var playlistid='';
		var playlistname='';

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

		thumbnailpath = playingItem.ThumbnailPath;
		title = playingItem.Title;
		shortDesc = playingItem.ShortDesc;
		duration = playingItem.Duration;
		doNotShowInPlaylist = playingItem.DoNotShowInPlaylist;
		adTag = playingItem.AdTag;
		playlistid = playingItem.PlaylistID;
			
		// minutes and seconds for duration (comes from Lenght all in seconds)		
		minVar = Math.floor(duration/60);  // minutes
    	secVar = duration % 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 
      	}

		//get the playlist name for coremetrics
		if (playlistid==96){playlistname="eci:Nuestros Spots"}   
		else if (playlistid==97){playlistname="eci:Hoy en nuestra web"}   
		else if (playlistid==98){playlistname="eci:Marcas"} 
		else if (playlistid==99){playlistname="eci:Ocio y Cultura"} 
		else if (playlistid==100){playlistname="eci:Espectaculos"} 
		else if (playlistid==101){playlistname="eci:Anunciado en TV"} 
 
		 // deal with missing thumbnails
		if(thumbnailpath == ""){ thumbnailpath = THUMBNAIL_MISSING; }

		if(doNotShowInPlaylist == 'false') {
			playlistContentBuilder += "<div id='item"+i+"' class='playlist_item'>";	
		    playlistContentBuilder += "	<div class='playlist_item_image'>";	
		    playlistContentBuilder += "		<a href=\"javascript:playVideo("+ i +", '"+ currentlyShowing +"');\"    onclick='_gaq.push([\"_trackEvent\", \"Video\", \"Play\", \""+title+"\"]);cmCreatePageviewTag(\"VIDEO TV ECI: "+title+" \", \""+playlistname+"\");'  >";	//bb
  			playlistContentBuilder += "	<img ID='imgThumbnail' Width='"+THUMBNAIL_WIDTH+"' Height='"+THUMBNAIL_HEIGHT+"' src='"+ thumbnailpath +"' title='"+ title +"' class='border_on' /></a></div> ";	
      		playlistContentBuilder += "	<div class='playlist_item_text'>";
      		playlistContentBuilder += "	<div class='playlist_item_link'>";		
			playlistContentBuilder += "		<a class='playlist_item_link_href' href=\"javascript:playVideo("+ i +", '"+ currentlyShowing +"');\"   onclick='_gaq.push([\"_trackEvent\", \"Video\", \"Play\", \""+title+"\"]);cmCreatePageviewTag(\"VIDEO TV ECI: "+title+"\", \""+playlistname+"\");'>"+ title +"</a> ";	
			playlistContentBuilder += "	</div> ";	
      		playlistContentBuilder += "		<p class='shortd'><a href=\"javascript:playVideo("+ i +", '"+ currentlyShowing +"');\"  onclick='_gaq.push([\"_trackEvent\", \"Video\", \"Play\", \""+title+"\"]);cmCreatePageviewTag(\"VIDEO TV ECI: "+title+"\", \""+playlistname+"\");'>"+ shortDesc +"</a></p> ";	
			playlistContentBuilder += "	</div> ";	
			playlistContentBuilder += "</div>";
			playlistContentBuilder += "	<div style='clear:both;'>";
			playlistContentBuilder += "	<div class='raya'></div> <div class='duration'></div> ";	
			playlistContentBuilder += "	</div>";
		} else {
		}
	}
	try{
		$("#pane").html(playlistContentBuilder);
	}catch(exception){
	}
}
