$(document).ready(initNoticias);

function initNoticias(){
	
	
	$.ajax({
		 type: "POST",
		 dataType: ($.browser.msie) ? "text" : "xml", // Reconocemos el browser.
		 cache: false,
	     url: "../conicet/simplenews/xmlNews/home:1/limit:1000",
		 timeout: 20000,
		 success: noticiasResponse, 
		 error: errorNoticias
		 });
}

function errorNoticias (XMLHttpRequest, textStatus, errorThrown) {

}


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

	$("#contenedorNoticias").html("");
	
	var id;
	var title;
	var preview;
	var image;
	var imagenProducto;
	var count=0;
		
	$("simplenews",xml).each(function(){
									
	id= $('id:eq(0)', this).text();
	title = $('title:eq(0)', this).text();
	preview= $('preview', this).text();
	image="/conicet" + $('image:eq(0) media', this).text();
	
	imagenProducto="";
	if(image == "/conicet")
		imagenProducto = "";
	else
		imagenProducto = '<img src="'+ image +'" style="border:#FFF 1px solid;margin-top:5px;" />';
	
	$("#contenedorNoticias").append(
						'<div class="noticia" id="noticia_'+ id +'" style="cursor:pointer">' +
                        	'<div class="fotoNoticia">' + 
								imagenProducto +
							'</div>' +
							'<div class="tituloNoticia">' +
								title +
							'</div>' +	
							'<div class="detalleNoticia">' +
								preview +
							'</div>' +
							'<div class="verticalSpacer"></div>'+	
						'</div>'
						);
	
	$('#noticia_'+id).click(function(){
											id = $(this).attr("id").replace("noticia_","");
											window.location='detalleNoticia.php?id=' + id;
											return false;
											});
	count++;
	if (count == 3){
		$("#contenedorNoticias").append(
										'<div class="clearFloats"></div>' +
										'<img src="layoutpics/lineaNoticia.jpg" style="margin-top:10px;"/>'
										);
		count=0;
	}
	
	});
	
	if (count == 0){
		$("#contenedorNoticias").append('<div class="clearFloats"></div>'+
										'<div style="width:100%; text-align:right;">' +
											'<a href="noticias.html"><img src="layoutpics/botonNoticias.jpg" style="margin-top:3px;margin-right:15px;" /></a>'+
										'</div>	');
	}else{
		$("#contenedorNoticias").append('<div class="clearFloats"></div>'+
										'<img src="layoutpics/lineaNoticia.jpg" style="margin-top:10px;"/>'+
										'<div style="width:100%; text-align:right;">' +
											'<a href="noticias.html"><img src="layoutpics/botonNoticias.jpg" style="margin-top:3px;margin-right:15px;" /></a>'+
										'</div>	');
	}
}


