var notas =[];

fxDestacada = function(j){

	var html = '';
	var path ='images/avatar-fundacion-big.jpg';
	if(notas[j].path!=null){
	
		var extensionNotes = (notas[j].path.substring(notas[j].path.lastIndexOf("."))).toLowerCase();
		if (extensionNotes != ".mpg"){
			path = notas[j].path;
		}
	}
	
	html = '<img src="' + path + '" width="287" height="215" alt="foto_icono_galeria"/>' +
			'<div>' +
				'<h2>' + notas[j].titulo + '</h2>' +
				'<p>' + notas[j].cuerpo + '</p>' +
				'<a class="mas" href="novedades-detalle.html?id=' + notas[j].id + '">ver mas</a>' +
			'</div>';

	$("#teaserInfo").html(html);
	
}

fxPrintPreview = function (json){
	
	var html1 = "<h2>Novedades</h2>";
	var html2 = "";
	
	var template1 = "";
	var template2 ='<div class="item bg${ord}">'+
    '<img src="${path}" alt="img1" height="51p" width="84p"/>'+
    '<div>'+
        '<h3><strong>${titulo}</strong></h3>'+
        '<p>${resumen}</p>'+  
        '<a href="novedades-detalle.html?id=${id}">ver m&aacute;s</a>'+
    '</div>'+
 	'</div>';
	
	var i=0;
	var l = 0;
	var ord=1;

	for (r in json.notes){
		// Si nivel es DESTACADO 1
		if (json.notes[r].novedadPrincipal == 1){
			notas[i]= json.notes[r];
			html2 = html2 +
			"<span onclick='fxDestacada("+i+")'>"+i+"</span>"
			i++; 
		}

		// Si nivel es DESTACADO 2
		if (json.notes[r].novedadPrincipal == 2 && l < 3){
			con = template2;
			con = con.replace("${titulo}",json.notes[r].titulo);
			con = con.replace("${path}",  ( (json.notes[r].path!=null) ? json.notes[r].path : 'images/avatar-fundacion.jpg' ) );
			con = con.replace("${resumen}", stripHTML(json.notes[r].cuerpo).substr(0,60) + "...");
			con = con.replace("${id}",json.notes[r].id);
			con = con.replace("${cat}","novedades");
			con = con.replace("${ord}",ord);

			ord++;
			html1 = html1 + con;
			l++;
		}
	}
	
	if (i > 0) fxDestacada (0);
	$("#navdestacados").html(html2);
	$("#novedades").html(html1);
};

$(function() { 
	callServiceJSON ("getNotePublicacionesHome", "", fxPrintPreview);	
});

function stripHTML(cadena)
{
    return cadena.replace(/<[^>]+>/g,'');
}


