var current = 1;
var imgList = new Array();

function fx(){
	if(current < 4){
		$$('#botones a')[current - 1].removeClass('sel');
		$$('#botones a')[current].addClass('sel');
		$('inner').tween('margin-left', '-'+(current*900).toString()+'px');
		current++;
	}else{
		$$('#botones a')[3].removeClass('sel');
		$$('#botones a')[0].addClass('sel');
		$('inner').tween('margin-left', 0);
		current = 1;
	}
	itime = setTimeout("fx()", 5000);
}

window.addEvent('domready', function(){
	if($chk($('form'))){
		$$('.add-carrito').addEvent('click', function(ev){
			ev = new Event(ev).stop();
			$('form').submit();
		});
	}
	if($chk($$('.form')[0])){
		$each($$('.add-carrito'), function(el){
			el.addEvent('click', function(ev){
				ev = new Event(ev).stop();
				$('form'+this.get('rel')).submit();
			});
		});
	}
	if($chk($('search'))){
		$('buscar').addEvent('click', function(ev){
			ev = new Event(ev).stop();
			$('search').submit();
		});
	}
	if($chk($$('.cantidad')[0])){
		$each($$('.cantidad'), function(el){
			el.addEvent('keydown', function(ev){
				if(ev.key == 'backspace' || ev.key == 'left' || ev.key == 'right' || ev.key == 'enter' || (ev.code >= 48 && ev.code <= 57) || (ev.code >= 96 && ev.code <= 105)){
					
				}else{
					ev = new Event(ev).stop();
				}
			});
		});
	}
	if($chk($('promociones'))){
		$each($$('#promo-text img'), function(el){
			el.addEvent('click', function(){
				document.location.href = "contacto.html";
			});
		});
	}
});
window.addEvent('load', function(){
	if($chk($('slider'))){
		$$('#inner img').addEvent('click', function(){
			document.location.href = "promociones.php";
		});
		$each($$('#botones a'), function(el){
			el.addEvent('click', function(ev){
				ev = new Event(ev).stop();
				x = el.get('id').replace('bot-', '').toInt();
				clearTimeout(itime);
				$$('#botones a').removeClass('sel');
				$$('#botones a')[x].addClass('sel');
				$('inner').tween('margin-left', '-'+(x*900).toString()+'px');
			});
		});
		itime = setTimeout("fx()", 5000);
	}
});
