$(function()
{
	$('#list1a').accordion();
	 $('.slideshow').cycle({
		fx: 'fade'
	});
	$('body div#base div#tabs div#botones div, body div#base div#tabs div#controles span').live('click',function()
	{
		var pre_id = this.id;
		var id_boton = pre_id.split('-');
		$('body div#base div#tabs div#botones div').css({'background-image':'none'});
		$('body div#base div#tabs div#botones').children('div#b-'+id_boton[1]+'').css({'background-image':'url(img/fondo_control.png)'});																var base = 'body div#base div#tabs div#base_c ';
		if($.browser.msie)
		{
			$(''+base+'div#c1,'+base+'div#c2,'+base+'div#c3,'+base+'div#c4,'+base+'div#c5,'+base+'div#c6').hide();	
			$(''+base+'a#esquina_1,'+base+'a#esquina_2,'+base+'a#esquina_3,'+base+'a#esquina_4,'+base+'a#esquina_5,'+base+'a#esquina_6').hide();	

			// Flecha Derecha
			var flecha_derecha = parseInt(id_boton[1]) + 1;
			
			if(flecha_derecha === 7)
			{
				flecha_derecha = 1;
			}
			$('body div#base div#tabs div#controles span.d').attr('id','b-'+flecha_derecha+'');
			
			// Flecha Derecha
			var flecha_izquierda = parseInt(id_boton[1]) - 1;
			
			if(flecha_izquierda === 0)
			{
				flecha_izquierda = 6;
			}
			$('body div#base div#tabs div#controles span.i').attr('id','b-'+flecha_izquierda+'');
			$('body div#base div#tabs div#base_c div#c'+id_boton[1]+'').show();	
			$('body div#base div#tabs div#base_c a#esquina_'+id_boton[1]+'').show();	
		}
		else
		{
			$(''+base+'div#c1,'+base+'div#c2,'+base+'div#c3,'+base+'div#c4,'+base+'div#c5,'+base+'div#c6').fadeOut();
			$(''+base+'a#esquina_1,'+base+'a#esquina_2,'+base+'a#esquina_3,'+base+'a#esquina_4,'+base+'a#esquina_5,'+base+'a#esquina_6').fadeOut();	
			// Flecha Derecha
			var flecha_derecha = parseInt(id_boton[1]) + 1;
			
			if(flecha_derecha === 7)
			{
				flecha_derecha = 1;
			}
			$('body div#base div#tabs div#controles span.d').attr('id','b-'+flecha_derecha+'');
			
			// Flecha Derecha
			var flecha_izquierda = parseInt(id_boton[1]) - 1;
			
			if(flecha_izquierda === 0)
			{
				flecha_izquierda = 6;
			}
			$('body div#base div#tabs div#controles span.i').attr('id','b-'+flecha_izquierda+'');
			$('body div#base div#tabs div#base_c div#c'+id_boton[1]+'').fadeIn();	
			$('body div#base div#tabs div#base_c a#esquina_'+id_boton[1]+'').fadeIn();
		}
	return false;
	});


//// BUSCADOR
function cambio()
{
	$('table#busqueda').delegate('select','change',function(){
		
		$('span#cargando').css('display','block');
		var id = $(this).val();
		if(this.id == 'fabricantes')
		{
			$('tr#n2').remove();
			$('tr#n3').remove();
			$('table#todos_tabla').remove();
			$('body table#todos').html('');
			$('body table#todos').hide();
			var clase = '';
		}
		if(this.id == 'categorias')
		{
				$('tr#n3').remove();
				$('table#todos_tabla').remove();
				$('body table#todos').html('');
				$('body table#todos').hide();
				var clase= $(this).attr('class');
				
				
				
		}
		if(this.id == 'productos')
		{
			if(id != 't')
			{
				var pre = id.split('-');
				var mi_id = pre[1];
				location.href="../gproductos2.php?id="+mi_id+"&xf=1";
			}
			else
			{
				var pre_val = $('input#cat_fab').val();
				var val = pre_val.split('-');
				var fabricante = val[0];
				var categoria = val[1];
				$.ajax
				({
					cache: false,
					async:true,
					url: '../Buscador_AJAX.php',
					data: 'fab='+fabricante+'&cat='+categoria,
					type: "GET",
					dataType: 'html',
					success: function listo(datos)
					{	
							$('span#cargando').fadeOut();
							$('body table#todos').html(datos);
							$('body table#todos').slideDown();
							cambio();
	
					return false;	
					}
				 });
				
			}
		}
		else
		{
			var pre = id.split('-');
			if(pre[0] == 'todos')
			{
				$.ajax
				({
					cache: false,
					async:true,
					url: '../Buscador_AJAX.php',
					data: 'id='+id+'&clase='+clase,
					type: "GET",
					dataType: 'html',
					success: function listo(datos)
					{	
								$('span#cargando').fadeOut();
								$('body form#miForm').append(datos);
								cambio();
					return false;	
					}
				 });
			}
			else
			{
				$.ajax
				({
					cache: false,
					async:true,
					url: '../Buscador_AJAX.php',
					data: 'id='+id+'&clase='+clase,
					type: "GET",
					dataType: 'html',
					success: function listo(datos)
					{	
								var id = $(this).val();	
								$('span#cargando').fadeOut();
								$('body table#busqueda').append(datos);
								cambio();
					return false;	
					}
				 });
			}
		}

	return false;
	});
}
cambio();

	



});


