/*********************************************************************/
/*                                                                   */
/*               SCRIPT DE PREVISUALIZACION DE PANDOs                */
/*                             para SMF                              */
/*                                                                   */
/*********************************************************************/
/*                                                                   */
/*           Hecho por Moraleja39 para beer2pando.com                */
/*                                                                   */
/*   Modificado y sub-desarrollado por elprofesional007 para         */
/*              Beer2pando.com y es-pando.com                        */
/*                                                                   */
/*     Este script puedes utilizarlo en tu web, solo pedimos         */
/*           que no quites los enlaces de la cajita                  */
/*********************************************************************/

var package_out = new Array ();
var package_count = 0;

function printPackageCallBack(packageInfo) {
	//el packageInfo nos envia el dato de expired, aqui recogemos la info
var jodido = packageInfo['expired'];
	//TamaÃ±o
	var size = packageInfo['packageSize'] / 1024 / 1024;
	size = Math.round(size * 100) / 100;
	if (size < 1000) {
		size = size + ' MB';
	} else {
		size = Math.round([size / 1024] * 100) / 100 + ' GB';
	}
	//Get number of days till expiration (negative = expired)
	var days = Math.round( (new Date(packageInfo['expirationDate']) - new Date()) / 86400000);
	//store expiration status
	var expired = (days >= 0) ? 0 : 1;
	//use absolute values of days for a readable string
	days = Math.abs(days);
	//get title from package info
	var title = packageInfo['title'];
	//Â¿Titulo muy largo?
	if (title.length > 38) {
		title = title.substring(0,35) + '...';
	//titulo raton
	var linktitle = "title=\"" + packageInfo['title'] + "\"";
	}
	//generate img tag with thumbnail from package info
	var thumb = '<img width="50px" height="40px" src="'+ packageInfo['thumbnailURL'] +'" alt="" />';
	//generate anchor tag from package URL; assumes packageKey is set
	var packageA = "<a href='" + PandoAPI.getPackageURL(packageId,packageKey) + "&tt=S2W'" + linktitle + ">";
	//get appropriately pluralized X day(s) string
	var daystring = days +' d&iacute;a'+ ( (days > 1) ? ('s') : ('') );	
	//get # of downloads from package info
	var dl = packageInfo['downloads'];
	//if package is not expired, link the title and thumbnail to the package URL
	//  and set the expiration days string accordingly
	// mostrar propiedades del packageInfo
//for (var prop in packageInfo) 
		//document.write(prop+': <em>'+packageInfo[prop]+'</em><br/>'); 

	if(!expired) {
		title = packageA + title + '</a>';
		thumb = packageA + thumb + '</a>';
		dias = '<span style="color: #47748E;"><strong>Semilla por '+ daystring +'</strong></span><br />';
	}
  	else if (jodido == true){
		dias = '<span style="color: green;"><strong>Transferencia P2P</span></strong><br />'
			title = packageA + title + '</a>';
			thumb = packageA + thumb + '</a>';
	}
   else  {
			dias = '<span style="color: green;"><strong>Nunca expira</span></strong><br />'
			title = packageA + title + '</a>';
			thumb = packageA + thumb + '</a>';
		}

	//generate human-friendly Downloaded X times / Never Download string
	if(dl > 0)
		dlstring = '<strong>'+dl+'</strong> '+( (dl > 1) ? ('descargas') : ('descarga') );
	else
		dlstring = 'Nunca descargado';
	//El que lo sube
	var uploader = 'Subido por <strong>' + packageInfo['packager'] + '</strong>';
 	var creacion = 'Fecha de subida <strong>' + packageInfo['creationDate'] + '</strong>';
	package_out[package_count] = '<table class="pandopackage"><tr><td colspan="2" class="pandopackage"><abbr title="'+ packageInfo['title'] + '">' + title +'</abbr></td></tr><tr><td class="packagethumb">' + thumb + '</td><td valign="middle" class="packagemeta">'+ uploader +'<br />'+ 'el d&iacute;a '+ '<strong>' +formateafecha(packageInfo['creationDate']) +'</strong>' +'<br />'+dlstring + ' // ' + size + '<br />' + dias + '</td></tr><tr><td>&nbsp;</td><td class="copy">&copy; 2007. <a href="http://www.beer2pando.com">B2p </a>& <a href="http://www.es-pando.com">ES-Pando</a></td></tr></table><div class="clr"></div>';
	
		document.write(package_out[package_count]);
}
function parsePandoUrl(url) {
  var parts = url.split('?',2);
  var args = parts[1];
  parts = args.split('&amp;');
  for(var i=0; i<parts.length; i++) {
    if(parts[i].match(/^id=[A-Z0-9]*/))
      packageId = parts[i].substring(3);
    if(parts[i].match(/^key=[A-Z0-9]*/))
      packageKey = parts[i].substring(4);			
  }
}
function showPackage(url) {
  parsePandoUrl(url);
  PandoAPI.getPackageInfo(packageId,printPackageCallBack,packageKey);
  package_count++
}
function formateafecha(fecha)
{
var long = fecha.length;
var dia;
var mes;
var ano;
var mifecha;

dia=fecha.substr(5,2);

switch(fecha.substr(8,3))
{
case 'Jan':
  mes = '01';
  break;    
case 'Feb':
  mes = '02';
  break;    
case 'Mar':
  mes = '03';
  break;
case 'Apr':
  mes = '04';
  break;
case 'May':
  mes = '05';
  break;   
case 'Jun':
  mes = '06';
  break;   
case 'Jul':
  mes = '07';
  break;   
case 'Aug':
  mes = '08';
  break;   
case 'Sep':
  mes = '09';
  break;   
case 'Oct':
  mes = '10';
  break;      
case 'Nov':
  mes = '11';
  break;   
case 'Dec':
  mes = '12';
  break;        
default:
  mes= fecha.substr(8,3);
}

ano=fecha.substr(12,4);
mifecha = dia + '/' + mes + '/' + ano


return (mifecha);
}
// streampando
function streamprintPackageCallBack(packageInfo) {
var image = packageInfo['torrentId'];
// cuando el packageInfo nos envie el dato de expired, aqui esta la orden necesaria
  var jodido = packageInfo['expired'];
// por el momento damos valor a mano como true, ya que el packageInfo no recoge ese dato
//var jodido = true;
	//torrentId
	var torrentId = packageInfo['torrentId'];
	//packageURL
	var packageURL = packageInfo['packageURL'];
	var titulo = packageInfo['title'];
  //TamaÃ±o
	var size = packageInfo['packageSize'] / 1024 / 1024;
	size = Math.round(size * 100) / 100;
	if (size < 1000) {
		size = size + ' MB';
	} else {
		size = Math.round([size / 1024] * 100) / 100 + ' GB';
	}
	//Get number of days till expiration (negative = expired)
	var days = Math.round( (new Date(packageInfo['expirationDate']) - new Date()) / 86400000);
	//store expiration status
	var expired = (days >= 0) ? 0 : 1;
	//use absolute values of days for a readable string
	days = Math.abs(days);
	//get title from package info
	var title = packageInfo['title'];
	//Â¿Titulo muy largo?
	if (title.length > 38) {
		title = title.substring(0,35) + '...';
	//titulo raton
	var linktitle = "title=\"" + packageInfo['title'] + "\"";
	}
	//generate img tag with thumbnail from package info
	var thumb = '<img width="50px" height="40px" src="'+ packageInfo['thumbnailURL'] +'" alt="" />';
	//generate anchor tag from package URL; assumes packageKey is set
	var packageA = "<a href='" + PandoAPI.getPackageURL(packageId,packageKey) + "&tt=S2W'" + linktitle + ">";
	//get appropriately pluralized X day(s) string
	var daystring = days +' d&iacute;a'+ ( (days > 1) ? ('s') : ('') );	
	//get # of downloads from package info
	var dl = packageInfo['downloads'];
	//if package is not expired, link the title and thumbnail to the package URL
	//  and set the expiration days string accordingly
	// mostrar propiedades del packageInfo
if(!expired) {
		title = packageA + title + '</a>';
		thumb = packageA + thumb + '</a>';
		dias = '<span style="color: #47748E;"><strong>Semilla por '+ daystring +'</strong></span><br />';
	}
  	else if (jodido == true){
		dias = '<span style="color: green;"><strong>Transferencia P2P</span></strong><br />'
			title = packageA + title + '</a>';
			thumb = packageA + thumb + '</a>';
	}
   else  {
			dias = '<span style="color: green;"><strong>Nunca expira</span></strong><br />'
			title = packageA + title + '</a>';
			thumb = packageA + thumb + '</a>';
		}

	//generate human-friendly Downloaded X times / Never Download string
	if(dl > 0)
		dlstring = 'Visto <strong>' + dl + '</strong> '+( (dl > 1) ? ('veces') : ('vez') );
	else
		dlstring = 'Nunca visto';
	//El que lo sube
	var uploader = 'Subido por <strong>' + packageInfo['packager'] + '</strong>';
 		package_out[package_count] = '<div class=\"visibleflv\" id=\"' + image + '3\"><a href=\"pando:stream?' + packageURL + '\"><img src=\"/portal/forum/Sources/pando/playerflv.jpg\" class=\"guionflv\" alt=\"Imagen 01" onclick=\"document.getElementById(\''+image+'4\').style.visibility=\'visible\';\"></a><br></div><div class=\"ocultoflv\" id=\"' + image + '4\"><embed src="http://www.jeroenwijering.com/embed/mediaplayer.swf" width="425" height="355" allowscriptaccess="always" allowfullscreen="true" flashvars="height=355&width=425&file=http://localhost:60513/stream/' + torrentId + '/' + titulo + '&image=/portal/forum/Sources/pando/playerflvfondo.jpg&backcolor=0x0000CC&frontcolor=0xCCCCFF&lightcolor=0x6666FF&screencolor=0x000000&showstop=true"/><br><a href=\"http://localhost:60513/stream/' + torrentId + '/' + titulo + '\">Guardar Video</a>&nbsp;|&nbsp; <a href=\"http://localhost:60513\" target=\"_blank\">Progreso de descarga</a><br></div><b>'+ titulo +'</b>&nbsp;|&nbsp;' + size +'&nbsp;|&nbsp; ' + dlstring +'<br> ' + uploader +'&nbsp;|&nbsp;' + formateafecha(packageInfo['creationDate']) + '&nbsp;|&nbsp;'+ dias + '';

	//	package_out[package_count] = '<a href="pando:stream?' + packageURL + '">Click aquí una vez para poder visualizar</a><br><a href="http://localhost:60513/" target="_blank">Ver el progreso de descarga desde goodies</a><br><embed src="http://www.jeroenwijering.com/embed/mediaplayer.swf" width="425" height="355" allowscriptaccess="always" allowfullscreen="true" flashvars="height=355&width=425&file=http://localhost:60513/stream/' + torrentId + '/' + titulo + '&image=http://www.es-pando.com/fondostream.jpg&backcolor=0x0000CC&frontcolor=0xCCCCFF&lightcolor=0x6666FF&screencolor=0x000000&showstop=true"/><br>'+ titulo +'&nbsp;|&nbsp;' + size +'&nbsp;|&nbsp; ' + dlstring +'<br> ' + uploader +'&nbsp;|&nbsp;' + formateafecha(packageInfo['creationDate']) + '&nbsp;|&nbsp;'+ dias + '';
		document.write(package_out[package_count]);
}

function streamshowPackage(url) {
  parsePandoUrl(url);
  PandoAPI.getPackageInfo(packageId,streamprintPackageCallBack,packageKey);
  package_count++
}

// divxpando
function divxpandoprintPackageCallBack(packageInfo) {
var image = packageInfo['torrentId'];

// cuando el packageInfo nos envie el dato de expired, aqui esta la orden necesaria
  var jodido = packageInfo['expired'];
// por el momento damos valor a mano como true, ya que el packageInfo no recoge ese dato
//var jodido = true;
	//torrentId
	var torrentId = packageInfo['torrentId'];
	//packageURL
	var packageURL = packageInfo['packageURL'];
	var titulo = packageInfo['title'];
  //TamaÃ±o
	var size = packageInfo['packageSize'] / 1024 / 1024;
	size = Math.round(size * 100) / 100;
	if (size < 1000) {
		size = size + ' MB';
	} else {
		size = Math.round([size / 1024] * 100) / 100 + ' GB';
	}
	//Get number of days till expiration (negative = expired)
	var days = Math.round( (new Date(packageInfo['expirationDate']) - new Date()) / 86400000);
	//store expiration status
	var expired = (days >= 0) ? 0 : 1;
	//use absolute values of days for a readable string
	days = Math.abs(days);
	//get title from package info
	var title = packageInfo['title'];
	//Â¿Titulo muy largo?
	if (title.length > 38) {
		title = title.substring(0,35) + '...';
	//titulo raton
	var linktitle = "title=\"" + packageInfo['title'] + "\"";
	}
	//generate img tag with thumbnail from package info
	var thumb = '<img width="50px" height="40px" src="'+ packageInfo['thumbnailURL'] +'" alt="" />';
	//generate anchor tag from package URL; assumes packageKey is set
	var packageA = "<a href='" + PandoAPI.getPackageURL(packageId,packageKey) + "&tt=S2W'" + linktitle + ">";
	//get appropriately pluralized X day(s) string
	var daystring = days +' d&iacute;a'+ ( (days > 1) ? ('s') : ('') );	
	//get # of downloads from package info
	var dl = packageInfo['downloads'];
	//if package is not expired, link the title and thumbnail to the package URL
	//  and set the expiration days string accordingly
	// mostrar propiedades del packageInfo
if(!expired) {
		title = packageA + title + '</a>';
		thumb = packageA + thumb + '</a>';
		dias = '<span style="color: #47748E;"><strong>Semilla por '+ daystring +'</strong></span><br />';
	}
  	else if (jodido == true){
		dias = '<span style="color: green;"><strong>Transferencia P2P</span></strong><br />'
			title = packageA + title + '</a>';
			thumb = packageA + thumb + '</a>';
	}
   else  {
			dias = '<span style="color: green;"><strong>Nunca expira</span></strong><br />'
			title = packageA + title + '</a>';
			thumb = packageA + thumb + '</a>';
		}
	//generate human-friendly Downloaded X times / Never Download string
	if(dl > 0)
		dlstring = 'Visto <strong>' + dl + '</strong> '+( (dl > 1) ? ('veces') : ('vez') );
	else
		dlstring = 'Nunca visto';
	//El que lo sube
	var uploader = 'Subido por <strong>' + packageInfo['packager'] + '</strong>';

package_out[package_count] = '<div class=\"visible\" id=\"' + image + '0\"><a href=\"pando:stream?' + packageURL + '\"><img src=\"/portal/forum/Sources/pando/playerdivx.jpg\" class=\"guion\" alt=\"Imagen 01" onclick=\"document.getElementById(\''+image+'1\').style.visibility=\'visible\';\"></a><br></div><div class=\"oculto\" id=\"' + image + '1\"><object codebase=\"http://go.divx.com/plugin/DivXBrowserPlugin.cab\" height=\"270\" width=\"584\" classid=\"clsid:67DABFBF-D0AB-41fa-9C46-CC0F21721616\"><param name=\"autoplay\" value=\"false\"><param name=\"src\" value=\"http://localhost:60513/stream/' + torrentId + '/' + titulo + '\"><param name=\"custommode\" value=\"Stage6\"><param name=\"showpostplaybackad\" value=\"false\"><embed type=\"video/divx\" src=\"http://localhost:60513/stream/' + torrentId + '/' + titulo + '\" pluginspage=\"http://go.divx.com/plugin/download/\" showpostplaybackad=\"false\" custommode=\"Stage6\" autoplay=\"false\" height=\"270\" width=\"584\"></object><br><a href=\"http://localhost:60513/stream/' + torrentId + '/' + titulo + '\">Guardar Video</a>&nbsp;|&nbsp; <a href=\"http://localhost:60513\" target=\"_blank\">Progreso de descarga</a><br></div><b>'+ titulo +'</b>&nbsp;|&nbsp;' + size +'&nbsp;|&nbsp; ' + dlstring +'<br> ' + uploader +'&nbsp;|&nbsp;' + formateafecha(packageInfo['creationDate']) + '&nbsp;|&nbsp;'+ dias + '';
document.write(package_out[package_count]);
}
  
function divxpandoshowPackage(url) {
  parsePandoUrl(url);
  PandoAPI.getPackageInfo(packageId,divxpandoprintPackageCallBack,packageKey);
  package_count++
}
      // expandir contraer para pod
	var altura = 0;
	var velocidad = 10;
	function extender(ide) {
	objeto=document.getElementById(ide);
		objeto.style.visibility = 'visible';
		altura += velocidad;
		if (!(altura >= 464)) {
			objeto.style.height = ''+altura+'px';
			capa=ide;
			window.setTimeout ("extender(capa);", 20);
		   	}	
       else altura=0;	   	
			}
	function contraer(ide) {
		objeto2=document.getElementById(ide);
		altura -= velocidad;
			if (!(altura <= 0)) {
			objeto2.style.height = ''+altura+'px';
			capa=ide;
			window.setTimeout ("contraer(capa);", 20);
			} else {
			objeto2.style.visibility = 'hidden';
			objeto2.style.height = '0px';
		}
		
	}
