// JavaScript Document
$(document).ready(function(){
						   
	var p   = new JOw.Pagina();
	var img = new JOw.Imagen();
	
	$.Listar = function(Listado,Categoria){
		
		p.setPlantilla('<li><table  width="200" border="0" cellpadding="0" cellspacing="0">'+
					'<tr><td class="cuadro"height="103"><div class="opciones_producto"><div onclick="$.VerDetalle(\'#(id)\',$(this));"  class="btn_detalle" >Ver Detalle</div></div><img src="images/productos/#(thumbnail) " width="235" height="120" alt="Producto" /></td></tr>'+
					'<tr><td align="right" class="galeria_titulos"> #(nombre) </td></tr>'+
					'</table></li>');
		
		p.setElementos($("#lista_productos"),$("#paginacion"),{ primera: "primera", anterior :"<img src='images/flechita_anterior.jpg' />" ,siguiente:"<img src='images/flechita_siguiente.jpg' />",ultima:"ultima" });
		p.setJSON("_data.php?Listado="+Listado+"&Categoria="+Categoria);
		p.setItems(8);
		//p.setOrden('nombre','asc');
		p.getPagina();		
		
		$("#lista_productos li")
		.live("mouseover",function(){
			$(this).find("div.opciones_producto").show();								
		})
		.live("mouseout",function(){
			$(this).find("div.opciones_producto").hide();								
		})
		$(".btn_detalle")
		.live("mouseover",function(){
			$(this).stop().animate({ opacity : 1 },500);								
		})
		.live("mouseout",function(){
			$(this).animate({ opacity : 0.5 },500);							
		})

	}
	$.verLinea = function(linea,obj){
		var p_local   = new JOw.Pagina();
		p = p_local;
		p.setPlantilla('<li><table  width="200" border="0" cellpadding="0" cellspacing="0">'+
					'<tr><td class="cuadro"height="103"><div class="opciones_producto"><div onclick="$.VerDetalle(\'#(id)\',$(this));"  class="btn_detalle" >Ver Detalle</div></div><img src="images/productos/#(thumbnail) " width="235" height="120" alt="Producto" /></td></tr>'+
					'<tr><td align="right" class="galeria_titulos"> #(nombre) </td></tr>'+
					'</table></li>');
		
		p.setElementos($("#lista_productos"),$("#paginacion"),{ primera: "primera", anterior :"<img src='images/flechita_anterior.jpg' />" ,siguiente:"<img src='images/flechita_siguiente.jpg' />",ultima:"ultima" });
		p.setItems(8);
		
		if(linea == 'todo'){
			$("#lLineas li").css({'text-decoration':'none','color':'#BAA39E'});
			obj.css({'text-decoration':'underline','color':'#3b2307'});
			p.setJSON("_data.php?Listado=Productos&Categoria=3");
		}else{
			$("#lLineas li").css({'text-decoration':'none','color':'#BAA39E'});
			obj.css({'text-decoration':'underline','color':'#3b2307'});
			p.setJSON("_data.php?Listado=pLinea&Categoria=3&iLinea="+linea);
		}
		p.getPagina();
	}
	
	$.Ordenar = function(Tipo){
		/*p.setOrden('nombre',Tipo);
		p.Actualizar();	*/
	};
	
	$.Productos  = function(Categoria){		window.location = "productos.php?Pagina=Productos&Categoria="+Categoria;	}
	
	$(".hoverimg")
	.live("mouseover",function(){	img.Hover($(this),"_over",true)		})
	.live("mouseout",function(){	img.Normal($(this),"_over",true)	})
	
	var Pagina = new Object();
	var activo = 0;
	
	$.Init = function() {
		Pagina = {
			Body	: $("body"),
			Detalle : $("#detalle"),
			Galeria : $("#galeria"),
			cboProducto : $('#cboproducto')
		}
	};

	$.Init();

	$.VerDetalle = function(Producto,obj){
		
		if(activo==0){	activo=1;
			Pagina.Body.attr("class","detalles_producto");
			Pagina.Galeria.fadeOut();
			Pagina.Detalle.load("_detalle.php",{Producto : Producto},function(){
				Pagina.Detalle.fadeIn("slow");		activo=0;
			})
			$.Log("Mostrando Producto... (OK)",{clear:true});
		}
										
			//var li = obj.parent().parents("li");//.trigger('click');
			//li.find(".btn_detalle").trigger('click');			
		
	}
	
	$.Volver = function(){	Pagina.Body.attr("class","cuadros");Pagina.Galeria.fadeIn();Pagina.Detalle.fadeOut();	}


	$.Cargar=  function(Categoria){
		$.getJSON("_data.php",{Listado : 'Listar_Productos',Categoria:Categoria},function(response){
			Pagina.cboProducto.html("");
			for(var index in  response){
				Pagina.cboProducto.append("<option value='"+response[index].codigo+"' >"+response[index].nombre+"</option>");
			}
		});
		$.SetCategoryName();
	}
	
	$.SetCategoryName = function() {
		$('#category_name').val($('#cbocategoria :selected').text().toUpperCase());
	}
	
	$.MensajeMail = function(){
			
			$("body").append('<div id="mensaje"></div>');
			
			var Mensaje = $("#mensaje");
			var Ventana = {width  : 0,height : 0 };
			var Capa    = {width  : 0,height : 0 };
			
			Ventana.width   = $(window).width();			
			Ventana.height  = $(window).height();
			
			Capa.height  = Mensaje.outerHeight();		
			Capa.width   = Mensaje.outerWidth();
			
			var top =  (Ventana.height - Capa.height)/2;		
			var left = (Ventana.width  - Capa.width)/2;
			
			Mensaje.css({'top' : top + $(document).scrollTop()  , 'left' : left});
			
			Mensaje.fadeIn("slow");
			setTimeout(function(){
					Mensaje.fadeOut();			
			},3000);	
			
	}
	
	$.Solicitar = function(Categoria,Producto){
			
			$("body").append('<div id="frm_solicitar"></div>');
			
			var Mensaje = $("#frm_solicitar");
			var Ventana = {width  : 0,height : 0 };
			var Capa    = {width  : 0,height : 0 };
			
			$("#cerrar_solicitud").live("click",function(){
				Mensaje.hide();									  
			})
			
			Mensaje.draggable({cursor:'move'});
			Mensaje.load("solicitar.php",{ Categoria : Categoria , Producto : Producto });
			Ventana.width   = $(window).width();			
			Ventana.height  = $(window).height();
			
			Capa.height  = Mensaje.outerHeight();		
			Capa.width   = Mensaje.outerWidth();
			
			var top =  (Ventana.height - Capa.height)/2;		
			var left = (Ventana.width  - Capa.width)/2;
			
			Mensaje.css({'top' : top + $(document).scrollTop()  , 'left' : left});
			
			Mensaje.show("clip");
	}
	
})
