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

var images = new Array();
images[1] = new Array('','port01','port02','port03','port04','port05','port06','port07','port08','port09','port10','port11','port12','port13');
images[2] = new Array('','corp01','corp02','corp03','corp04','corp05','corp06','corp07','corp08','corp09','corp10','corp11','corp12','corp13','corp14','corp15','corp16','corp17','corp18','corp19','corp20','corp21','corp22','corp23','corp24','corp25','corp26','corp27','corp28','corp29','corp30','corp31','corp32','corp33');
images[3] = new Array('','enchant01','enchant02','enchant03','enchant04','enchant05','enchant06','enchant07','enchant08','enchant09','enchant10','enchant11','enchant12','enchant13');

var totalimages = images[currentgallery].length-1;

var imgloc = new Array("","portrait_gallery/","corporate_gallery/","enchanted_gallery/");

function imagejump(jimg){
	/*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 = imgloc[currentgallery]+"main/"+images[currentgallery][jumpimg] + ".jpg";
	document.getElementById("theimage").src = theimagesrc;
	currentimage = (imgpos+jimg);
}

function thumbnext(){
	++currentimage;
	if(currentimage > totalimages){currentimage = 1; resetthumbs()}
	
	/*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 = imgloc[currentgallery]+"main/"+images[currentgallery][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()}
	
	/*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 = imgloc[currentgallery]+"main/"+images[currentgallery][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++){
		//thumbsrcloc = "portrait_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 = imgloc[currentgallery]+"thumb/"+images[currentgallery][thethumb] + ".jpg";
				//thumbsrc += thethumb + "t.jpg";
			document.getElementById("thumb"+i).src = thumbsrc;
		}
	}
}

function selectgallery(thegallery, currentimg){
	currentgallery = thegallery;
	currentimage = currentimg;
	totalimages = images[currentgallery].length-1;
	document.getElementById("theimage").src = imgloc[currentgallery]+"main/"+images[currentgallery][1]+".jpg";
	setthumbs();
}