$(document).ready(initProducts);

function initProducts(currentPage){
			
	$.ajax({
		 type: "POST",
		 dataType: ($.browser.msie) ? "text" : "xml", // Reconocemos el browser.
		 cache: false,
	     url: "pintucciyguizzo/products/ajaxPromote",
		 timeout: 20000,
		 success: productResponse, 
		 error: errorProducts
		 });
	$("#box2BodyProductos").height(50);
	$("#box2BodyProductos").block({ 
                message: 'Cargando productos...'
            }); 
}

function errorProducts (XMLHttpRequest, textStatus, errorThrown) {
	$("#box2Body").unblock();
}

function productResponse (data, textStatus){
	$("#box2BodyProductos").height("auto");
		var xml;
    	if(typeof data == "string"){
			xml = new ActiveXObject("Microsoft.XMLDOM");
			xml.async = false;
			xml.loadXML(data);
   		} else {
      		xml = data;
    	}

	$("#box2BodyProductos").html("");
	
	var eslaprimera = true;	
	var idproducto;
	var titulo;
	var imagen;
	
	$("producto",xml).each(function(){
	imagen=null;
	idproducto= $(this).attr("id");
	titulo= $("titulo",this).text();
	
	$(this).children('imagen:first').each(function() {
    	imagen = "/pintucciyguizzo/pintucciyguizzo" + $(this).attr("path");
	});
	
	if(imagen == null)
		imagen = "layoutpics/sinImagen.jpg";

	$("#box2BodyProductos").append(
						'<div title="haga clic para ver mas del producto" style="cursor:pointer;" class="productos" id="producto_'+ idproducto +'">' +
                        '<div class="imagenProductos" id="imagenProductos_'+ idproducto +'">' +
                        '<img src="'+ imagen +'" width="72" height="50" border="1" style="border-color:#554724"/>' +
                        '</div>' +
						'<div class="tituloProductos" id="tituloProductos_'+ idproducto +'">' +
                        '<span>'+titulo+'</span><br />' +
                    	'</div>' +
						'<div class="verProducto" id="verProducto_'+ idproducto +'">' +
                        '<span>VER +</span>' +
                        '</div>' +
						'</div>'
						);
	
	$('#producto_'+idproducto).click(function(){
											id = $(this).attr("id").replace("producto_","");
											window.location='detalleProducto.html?id=' + id;
											return false;
											});
	}
	);
	
	$("#box2Body").unblock(); 
}


