
var ancho = 224;
var total = 7;
var position = new Array(0,ancho*-1,ancho*-2,ancho*-3,ancho*-4,ancho*-5,ancho*-6,ancho*-total);
var vel = 0;
var pos = 0;
var estado;
var move;
var posfinal = 0;
var coef;
var dir;
var activo = true;

function dispara(p,c){
	if(activo){
		estado = false;
		coef = c;
		dir = p;
		if(!dir){
			if(posfinal < position.length - 1){
				posfinal = posfinal + 1;
				move = setInterval(moving,20);
				activo = false;
				if(posfinal == position.length - 1){
					document.getElementById("right").innerHTML = "";
				}
				if(document.getElementById("left").childNodes.length != 1){
					document.getElementById("left").innerHTML = "<a href=\"javascript:dispara(true,"+ coef +");\"><img src=\"images/izq.png\" alt=\"\" /></a>";
				}
			}else{
				activo = true;
			}
		}else{
			if(posfinal > 0){
				posfinal = posfinal - 1;
				move = setInterval(moving,20);
				activo = false;
				if(posfinal == 0){
					document.getElementById("left").innerHTML = "";
			
				}
				if(document.getElementById("right").childNodes.length != 1){
					document.getElementById("right").innerHTML = "<a href=\"javascript:dispara(false,"+ coef +");\"><img src=\"images/der.png\" alt=\"\" /></a>";
				}
			}else{
				activo = true;
			}
		}
	}
}

function moving(){
	if(!dir){
		if(pos > position[posfinal] + (ancho/2)){
			vel-= coef;
		}else{
			if(!estado){
				pos = position[posfinal] + (ancho/2);
				vel-= coef;
			}
			vel+= coef;
			estado = true;
		}
		pos+= vel;
		if(pos <= position[posfinal]){
			pos = position[posfinal];
			clearInterval(move);
			vel = 0;
			activo = true;
		}
	}else{
		if(pos <= position[posfinal] - (ancho/2)){
			vel+= coef;
		}else{
			if(!estado){
				pos = position[posfinal] - (ancho/2);
				vel+= coef;
			}
			vel-= coef;
			estado = true;
		}
		pos+= vel;
		if(pos >= position[posfinal]){
			pos = position[posfinal];
			clearInterval(move);
			vel = 0;
			activo = true;
		}	
	}
	document.getElementById('slide').style.background = 'url(images/iphones.jpg) repeat '+ pos +'px';
}

