$(document).ready(initNovedades);

function initNovedades(currentPage){
			
	$.ajax({
		 type: "POST",
		 dataType: ($.browser.msie) ? "text" : "xml", // Reconocemos el browser.
		 cache: false,
	     url: "/alegrie/alegrie/news/ajaxIndex/limit:5",
		 timeout: 20000,
		 success: novedadesResponse, 
		 error: errorNovedades
		 });
}

function errorNovedades (XMLHttpRequest, textStatus, errorThrown) {

}

function novedadesResponse (data, textStatus){
		var xml;
    	if(typeof data == "string"){
			xml = new ActiveXObject("Microsoft.XMLDOM");
			xml.async = false;
			xml.loadXML(data);
   		} else {
      		xml = data;
    	}

	$("#contenedor").html("");
	
	var idNovedades;
	var titulo;
	var copete;
	var imagen;
	
	$("noticia",xml).each(function(){
	imagen=null;
	idNovedades= $(this).attr("id");
	titulo= $("titulo",this).text();
	copete= $("copete",this).text();
	
	$(this).children('imagen:first').each(function() {
    	//imagen = "/pintucciyguizzo/pintucciyguizzo" + $(this).attr("path");
		imagen = "/alegrie/alegrie" + $(this).attr("path");
		imagen = imagen.replace("100x100","70x70");
	});
	
	if(imagen == null)
		imagen = "layoutpics/sinImagen.jpg";

	$("#contenedor").append(
						'<div class="novedades" style="cursor:pointer;" id="novedad_'+ idNovedades +'">' +
                        	'<div class="tituloNovedades">' + 
								titulo +
								'<img src="layoutpics/linea1.jpg" border="0"/>' +
							'</div>' +
							'<div class="imagenNovedades">' +
                    			'<img src="'+ imagen +'" border="0" style="border:#FAA0B9 solid 2px;"/>' +
							'</div>' +	
							'<div class="copeteNovedades">'+ 
								copete +
                            '</div>'+
							'<div class="clearFloats"></div>'+
							'<div class="verticalSpacer"></div>' +
                        	'<img src="layoutpics/linea.png" border="0" style="position:relative;top:10px"/>' +
                        '</div>'
						);
	
	$('#novedad_'+idNovedades).click(function(){
											id = $(this).attr("id").replace("novedad_","");
											window.location='detalleNovedades.html?id=' + id;
											return false;
											});
	}
	);
}


