// JavaScript Document
var count;
var galleryIndex;
var imageIndex;
var timer;

function autoPager() {
	next();
	timer = setTimeout('autoPager();', 7000);	
}

function stopAutoPager() {
	clearInterval(timer);	
}

function loadGallery(galleryIndex, count, header) {
	if(this.galleryIndex != galleryIndex) {
		this.galleryIndex = galleryIndex;
		this.count = count;
		this.imageIndex = 0;
		document.getElementById('maxCount').innerHTML = count;
		document.getElementById('gMenyHeader').innerHTML = header;
		this.next();
		
	}
} 
	
function next() {
	if(imageIndex < count)
		imageIndex = imageIndex + 1;
	var imageLength = imageIndex.toString().length;
	var imageName;
	var preImageName;
	var preImageName2;
	
	if(imageLength == 1) {
		imageName = "00" + imageIndex + ".jpg";
		preImageName = "00" + (imageIndex + 1) + ".jpg";
		preImageName2 = "00" + (imageIndex + 2) + ".jpg";
	}
	else if(imageLength == 2){
		imageName = "0" + imageIndex + ".jpg";
		preImageName = "0" + (imageIndex + 1) + ".jpg";
		preImageName2 = "0" + (imageIndex + 2) + ".jpg";
	}
	else if(imageLength == 3) {
		imageName = imageIndex + ".jpg";
		preImageName = (imageIndex + 1) + ".jpg";
		preImageName2 = (imageIndex + 2) + ".jpg";
	}
	
	if(	imageIndex <= count) 
		document.getElementById('imgC').src = "/gallery/public/gallery" + galleryIndex + "/" + 	imageName;

	if(imageIndex <= count -1) {
		var preloadImage1 = new Image();
		var preloadImage2 = new Image();
		preloadImage1.src = "/gallery/public/gallery" + galleryIndex + "/" + preImageName;
		preloadImage2.src = "/gallery/public/gallery" + galleryIndex + "/" + preImageName2;
	}
	 
	document.getElementById('counter').innerHTML = imageIndex;

	if(document.all) {
	document.getElementById("imgC").style.filter="blendTrans(duration=1)";
   	document.getElementById("imgC").filters.blendTrans.Apply();
	document.getElementById("imgC").filters.blendTrans.Play();
	}
}

function previous() {
		
	if(imageIndex > 1)
		imageIndex = imageIndex - 1; 
	var imageLength = imageIndex.toString().length;
	var imageName;
	
	if(imageLength == 1)
		imageName = "00" + imageIndex + ".jpg";
	else if(imageLength == 2)
		imageName = "0" + imageIndex + ".jpg";
	else if(imageLength == 3)
		imageName = imageIndex + ".jpg";
	
	if(	imageIndex > 0) 
	document.getElementById('imgC').src = "/gallery/public/gallery" + galleryIndex + "/" + 	imageName;
		 
	document.getElementById('counter').innerHTML = imageIndex;
	
	if(document.all) {	
	document.getElementById("imgC").style.filter="blendTrans(duration=1)";
   	document.getElementById("imgC").filters.blendTrans.Apply();
	document.getElementById("imgC").filters.blendTrans.Play();
	}
}
