var photos = [];

function cargarray(fondos){
  for (var i=0;i<fondos.length;i++){
		img = fondos[i];
		photos[i] = {image : baseURL+"all/tools/img/bckgrnd/"+img};
  }
}


// EN EL A.S.//

/*
on (press) {
getURL("javascript:SimularClick('img3')");
}
*/
// EN EL A.S.//


function SimularClick(idObjete){

<!--
var navegador = navigator.appName
if (navegador == "Microsoft Internet Explorer"){
document.getElementById(idObjete).click() 
}else{
var nouEvent = document.createEvent("MouseEvents");
nouEvent.initMouseEvent("click", true, true, window,0, 0, 0, 0, 0, false, false, false, false, 0, null);

var objecte = document.getElementById(idObjete);
var canceled = !objecte.dispatchEvent(nouEvent);
}
//-->


}


$(document).ready(function() {
	
	$("#img1").click(function() {
		stopAnimation();
		navigate("img1");
	});
	
	$("#img2").click(function() {
		stopAnimation();
		navigate("img2");
	});
	
	$("#img3").click(function() {
		stopAnimation();
		navigate("img3");
	});
	
	$("#img4").click(function() {
		stopAnimation();
		navigate("img4");
	});
	
	$("#img5").click(function() {
		stopAnimation();
		navigate("img5");
	});
	
	$("#img6").click(function() {
		stopAnimation();
		navigate("img6");
	});
	
	$("#img7").click(function() {
		stopAnimation();
		navigate("img7");
	});
	
	$("#img8").click(function() {
		stopAnimation();
		navigate("img8");
	});
	
	$("#img9").click(function() {
		stopAnimation();
		navigate("img9");
	});
	
	$("#img10").click(function() {
		stopAnimation();
		navigate("img10");
	});
	
	var interval;
	
	var activeContainer = 1;	
	var currentImg = 0;
	var animating = false;
	
	var navigate = function(direction) {

		/*if(animating) {
			return;
		}*/
		
			/*	
		if(direction == "next") {
			currentImg++;
			if(currentImg == photos.length + 1) {
				currentImg = 1;
			}
		} else {
			currentImg--;
			if(currentImg == 0) {
				currentImg = photos.length;
			}
		}
		*/
		switch(direction)
				{
				case "img1":
				  currentImg = 1;
				  break;
				case "img2":
				  currentImg = 2;
				  break;
				case "img3":
				  currentImg = 3;
				  break;
				case "img4":
				  currentImg = 4;
				  break;
				case "img5":
				  currentImg = 5;
				  break;
				case "img6":
				  currentImg = 6;
				  break;
				case "img7":
				  currentImg = 7;
				  break;
				case "img8":
				  currentImg = 8;
				  break;
				case "img9":
				  currentImg = 9;
				  break;
				case "img10":
				  currentImg = 10;
				  break;
				default:
				  currentImg = 1;
				  break;
				}
		
		// switch de conteiner
		var currentContainer = activeContainer;
		if(activeContainer == 1) {
			activeContainer = 2;
		} else {
			activeContainer = 1;
		}
		
		showImage(photos[currentImg - 1], currentContainer, activeContainer);
		
	};
	
	var currentZindex = -1;
	
	var showImage = function(photoObject, currentContainer, activeContainer) {
		animating = true;
		
		// container siempre al fondo
		currentZindex--;
		
		// seteo el background image
		$("#headerimg" + activeContainer).css({
			"background-image" : "url(" + photoObject.image + ")",
			"display" : "block",
			"background-repeat" : "repeat",
			"height" : "1300px",			
			"z-index" : currentZindex
		});
		
				
		$("#headerimg" + currentContainer).fadeOut(600,function() {
			setTimeout(function() {animating = false;}, 500);
		});
	};
	
	var stopAnimation = function() {
		clearInterval(interval);
	};
	
	//
	//navigate("next");

	
	/*
	// 	interval = setInterval(function() {
		navigate("next");
	}, slideshowSpeed);*/
	
});

