// Accommodation image flipper

var maxHeight = 146; // Enter the height (in pixels) of the "tallest" picture in the gallery (can be greater, but not less than, height of tallest picture)
var maxWidth = 220; // Enter the width (in pixels) of the widest picture in the gallery (can be greater, but not less than, width of widest picture)

var nowPic = new Array(0,0,0);

document.write("<style type='text/css'> #mainpic0 {visibility:hidden;} </style>");
document.write("<style type='text/css'> #mainpic1 {visibility:hidden;} </style>");
document.write("<style type='text/css'> #mainpic2 {visibility:hidden;} </style>");

window.onload = function() {
	initImage();
	nowload('images/acc_apartment_2.jpg','images/acc_apartment_3.jpg','images/acc_apartment_4.jpg','images/acc_apartment_5.jpg','images/acc_apartment_6.jpg','images/acc_apartment_7.jpg','images/acc_courtstudio_2.jpg','images/acc_courtstudio_3.jpg','images/acc_courtstudio_4.jpg','images/acc_courtstudio_5.jpg','images/acc_seastudio_2.jpg','images/acc_seastudio_3.jpg','images/acc_seastudio_4.jpg','images/acc_seastudio_5.jpg');
	}

var arImages=new Array();
function nowload() {
 var temp = nowload.arguments; 
 for(x=0; x < temp.length; x++) {
  arImages[x]=new Image();
  arImages[x].src=nowload.arguments[x];
 }
}

function placeFirst() {
	document.getElementById('picTab').style.height = maxHeight.toString() + "px";
	document.getElementById('picTab').style.width = maxWidth.toString() + "px";
	change(nowPic(0),0);
	change(nowPic(1),1);
	change(nowPic(2),2);
}

function change(pic,n) {

	switch (n) {
		case 0: 
		{
			document.getElementById('mainpic0').src = fileNames0[pic];
			document.getElementById('picNum0').innerHTML = (pic+1) + "/" + fileNames0.length;		
			break;
		}
		case 1: 
		{
			document.getElementById('mainpic1').src = fileNames1[pic];
			document.getElementById('picNum1').innerHTML = (pic+1) + "/" + fileNames1.length;		
			break;
		}
		case 2: 
		{
			document.getElementById('mainpic2').src = fileNames2[pic];
			document.getElementById('picNum2').innerHTML = (pic+1) + "/" + fileNames2.length;		
			break;
		}
	}
}

function next(n) {
	nowPic[n]++;
	switch (n) {
		case 0: filenamesLength = fileNames0.length; break;
		case 1: filenamesLength = fileNames1.length; break;
		case 2: filenamesLength = fileNames2.length; break;
	}	
	
	if(nowPic[n]>=filenamesLength) {
		nowPic[n] = 0;
		}
	change(nowPic[n],n);
}

function previous(n) {
	nowPic[n]--;
	switch (n) {
		case 0: filenamesLength = fileNames0.length; break;
		case 1: filenamesLength = fileNames1.length; break;
		case 2: filenamesLength = fileNames2.length; break;
	}		
	if(nowPic[n] < 0) {
		nowPic[n] = (filenamesLength - 1);
		}
	change(nowPic[n],n);
}


function initImage() {
	imageId0 = 'mainpic0';
	imageId1 = 'mainpic1';
	imageId2 = 'mainpic2';
	pic = 0;	
	document.getElementById('picTab').style.height = maxHeight.toString() + "px";
	document.getElementById('picTab').style.width = maxWidth.toString() + "px";
	document.getElementById('mainpic0').src = fileNames0[pic];
	document.getElementById('mainpic1').src = fileNames1[pic];
	document.getElementById('mainpic2').src = fileNames2[pic];
	document.getElementById('picNum0').innerHTML = (pic+1) + "/" + fileNames0.length;
	document.getElementById('picNum1').innerHTML = (pic+1) + "/" + fileNames1.length;
	document.getElementById('picNum2').innerHTML = (pic+1) + "/" + fileNames2.length;	
	image = document.getElementById(imageId0);
	change(pic,0);
	image.style.visibility = 'visible';
	image = document.getElementById(imageId1);
	change(pic,1);
	image.style.visibility = 'visible';
	image = document.getElementById(imageId2);
	change(pic,2);
	image.style.visibility = 'visible';
}

