var currentgallery = 1;
var imgpos = 0;
var currentimage = 1;

var images = new Array('','p01','p03','p04','p05','p07','p08','p09','p10','p11','p12','p13','p14','p15','p16','p17','p18','p19','p20','p22','p23','p25','p26','p28','p29','p30','P31');

var totalimages = images.length-1;

function imagejump(jimg){
	var theimagesrc = "images_gallery/main/";
	/*if((imgpos+jimg) >= 1000){
		theimagesrc += (imgpos+jimg) + ".jpg";
	}else if((imgpos+jimg) >= 100){
		theimagesrc += "0" + (imgpos+jimg) + ".jpg";
	}else if((imgpos+jimg) >= 10){
		theimagesrc += (imgpos+jimg) + "s.jpg";
	}else{
		theimagesrc += "0" + (imgpos+jimg) + "s.jpg";
	}*/
	jumpimg = imgpos+jimg;
	theimagesrc += images[jumpimg] + ".jpg";
	document.getElementById("theimage").src = theimagesrc;
	currentimage = (imgpos+jimg);
}

function thumbnext(){
	++currentimage;
	if(currentimage > totalimages){currentimage = 1; resetthumbs()}
	
	var theimagesrc = "images_gallery/main/";
	/*if(currentimage >= 1000){
		theimagesrc += currentimage + ".jpg";
	}else if(currentimage >= 100){
		theimagesrc += "0" + currentimage + ".jpg";
	}else 
	if(currentimage >= 10){
		theimagesrc += currentimage + ".jpg";
	}else{
		theimagesrc += "0" + currentimage + ".jpg";
	}*/
	theimagesrc += images[currentimage] + ".jpg";
	
	//theimagesrc += currentimage + ".jpg";
	document.getElementById("theimage").src = theimagesrc;
	
		
	
	if(currentimage % 5 == 1 && currentimage != 1){
		thumbdown();
	}
}

function thumbprev(){
	
	--currentimage;
	if(currentimage <= 0){currentimage = totalimages; thumbbottom()}
	var theimagesrc = "images_gallery/main/";
	/*if(currentimage >= 1000){
		theimagesrc += currentimage + ".jpg";
	}else if(currentimage >= 100){
		theimagesrc += "0" + currentimage + ".jpg";
	}else if(currentimage >= 10){
		theimagesrc += "00" + currentimage + ".jpg";
	}else{
		theimagesrc += "000" + currentimage + ".jpg";
	}*/
	
	/*if(currentimage >= 10){
		theimagesrc += currentimage + ".jpg";
	}else{
		theimagesrc += "0" + currentimage + ".jpg";
	}*/
	
	theimagesrc += images[currentimage] + ".jpg";
	document.getElementById("theimage").src = theimagesrc;
	
	
	
	if(currentimage % 5 == 0){
		thumbup();
	}
}

function thumbup(){
	if(imgpos > 0){
		imgpos -= 5;
	}
	setthumbs();
}

function thumbdown(){
	imgpostest = (Math.floor(totalimages/5) * 5) - 10;
	if(totalimages % 5 > 0){
		imgpostest += 5;
	}
	if(imgpos < imgpostest){
		imgpos += 5;
	}
	setthumbs();
}

function resetthumbs(){
	imgpos = 0;
	setthumbs();
}

function thumbbottom(){
	imgpos = (Math.floor(totalimages/5) * 5) - 10;
	if(totalimages % 5 > 0){
		imgpos += 5;
	}
	setthumbs();
}
function setthumbs(){
	for(var i = 1; i <= 10; i++){
		thumbsrc = "images_gallery/thumb/";
		thethumb = imgpos + i;
		if(thethumb > totalimages){
			document.getElementById("thumb"+i).src = "../images/blank.jpg";
		}else{
			/*if(thethumb >= 1000){
				thumbsrc += thethumb + ".jpg";
			}else if(thethumb >= 100){
				thumbsrc += "0" + thethumb + ".jpg";
			}else*/ 
			/*if(thethumb >= 10){
				thumbsrc += thethumb + "t.jpg";
			}else{
				thumbsrc += "0" + thethumb + "t.jpg";
			}*/
			thumbsrc += images[thethumb] + ".jpg";
				//thumbsrc += thethumb + "t.jpg";
			document.getElementById("thumb"+i).src = thumbsrc;
		}
	}
}

function selectgallery(thegallery, currentimg, defaultimg, totalimgs){
	currentgallery = thegallery;
	currentimage = currentimg;
	totalimages = totalimgs;
	document.getElementById("theimage").src = "images/design/"+currentgallery+"/"+defaultimg+".jpg";
	resetthumbs();
}