function cambiarsplash(nuevo){
	var maximo = $("#content #novedades .enlaces a").length;
	var nuevotop = (nuevo-1)*180;
	var nuevofondotop = (nuevo-1)*36;
	//$('#content #novedades .enlaces .fondo').css("top",nuevofondotop+"px");
	
	$('#content #novedades .splash .in').animate({
		top: '-'+(nuevotop)+'px'
	}, 200, function() {
	});

	$('#content #novedades .enlaces a.active').removeClass("active");
	$('#content #novedades .enlaces a#nov-'+nuevo).addClass("active");
	$('#content #novedades .enlaces .fondo').css({"top": nuevofondotop+'px'})

}
var play;
$(document).ready(function() {
	base();
	$('.buscador').submit(function() {
		var b_stock = '';
		if($("input#b_stock:checked").length > 0){
			b_stock = '&s=1';
		}
		ir('productos/?b='+$("input#b_contenido").val().replace(/ /g, "+")+b_stock);
		return false;
	});
	$("#nav div").prepend($('<div class="fondo"><hr/></div>'));
	$("#nav div.fondo").each(function(index) {
		var padre = $(this).parent();
		$(this).css('width', padre.width()+'px');
		var ioactual = "<span>"+$(this).next().html()+"</span>";
		$(this).next().html(ioactual);
	});
	var navactivo = $("#nav div.active .fondo");
	function navactivodef(){
		if(navactivo != null){
			navactivo.stop().animate({
			"margin-top": 0
			}, 200,function(){$(this).parent().addClass("active");});
		}
	}
	navactivodef();
	var esperarnavactivo;
	$("#nav a").hover(
		function () {
			clearTimeout(esperarnavactivo)
			if(navactivo != null){
				
				navactivo.stop().animate({
				"margin-top": 36
				}, 100);
				navactivo.parent().removeClass("active");
			}
			
			$(this).prev().stop(true).animate({
			"margin-top": 0
			}, 200,function(){$(this).parent().addClass("active");});
		}, 
		function () {
			esperarnavactivo = setTimeout(navactivodef, 200);
			$(this).parent().removeClass("active");
			$(this).prev().stop(true).animate({
			"margin-top": 36
			}, 100);
		}
	);
	
	if($("#content #novedades .enlaces a").length > 0){
		var maximo = $("#content #novedades .enlaces a").length;
		$('#content #novedades .enlaces a').click(function(event){
			var nuevonumero = $(this).attr("id").split("nov-").slice(1);
			cambiarsplash(nuevonumero);
			event.preventDefault();
		});
		
		
		rotateSwitch = function(ira){
				play = setInterval(function(){
					$active = $('#content #novedades .enlaces a.active').next();
					if ($active.length === 0){
						$active = $('#content #novedades .enlaces a:first');
					}
					var numnuevo = $active.attr('id').split("nov-").slice(1)
					cambiarsplash(numnuevo);
				}, 3000);
			};
		$("#content #novedades").hover(function() {
			clearInterval(play);
		}, function() {
			rotateSwitch();
		});	
		rotateSwitch();
	}
	
	
});
$(window).load(function () {
	baseload();
});
