// Initialize the gallery array.
arrOfImg = new Array();

// Array for the gallery position.
arrOfPos = new Array();

/**
 * Gallery image navigation.
 */

function changeGalleryImg(gallery, step) {
	galleryPosition = arrOfPos[gallery] + parseInt(step);

	// Loop over if the actual number is less than the first or higher than the last.
	if (galleryPosition < 0 ) {
		galleryPosition = arrOfImg[gallery].length - 1;
	}
	else if (galleryPosition >= arrOfImg[gallery].length) {
		galleryPosition = 0;
	}

	// Switch the image.
	galleryImage = document.getElementById("gallery" + gallery + "Image");
	galleryImage.src = arrOfImg[gallery][galleryPosition][0].toString();
	galleryImage.title = arrOfImg[gallery][galleryPosition][1].toString();
	galleryImage.alt = arrOfImg[gallery][galleryPosition][1].toString();
	//galleryImage.style.width = "auto";
	//galleryImage.style.height = "auto";

	// Switch the legend.
	galleryLegend = document.getElementById("gallery" + gallery + "Legend");
	galleryLegend.innerHTML = arrOfImg[gallery][galleryPosition][2].toString().replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&");

	// Update the visible counters.
	galleryPositionElement = document.getElementById("gallery" + gallery + "Position");
	galleryAllElement = document.getElementById("gallery" + gallery + "All");
	galleryPositionElement.innerHTML = galleryPosition + 1;
	galleryAllElement.innerHTML = arrOfImg[gallery].length;

	// Update the proportions of the container.
	galleryElement = document.getElementById("gallery" + gallery);
	//galleryElement.style.width = arrOfImg[gallery][galleryPosition][3].toString() + "px";
	//galleryElement.style.height = arrOfImg[gallery][galleryPosition][4].toString() + "px";
        $(galleryElement).animate({
                width: arrOfImg[gallery][galleryPosition][3].toString() + "px",
                height: arrOfImg[gallery][galleryPosition][4].toString() + "px"
	});
	$(galleryImage).animate({
		width: arrOfImg[gallery][galleryPosition][3].toString() + "px",
        	height: arrOfImg[gallery][galleryPosition][4].toString() + "px"
	});

	// Update thy current position.
	arrOfPos[gallery] = galleryPosition;
}
