var firstOrange=0; //first photo
var firstHotel=0; //first photo
var firstFood=0; //first photo
var firstPH=0; //first photo

var numOrange=0; //first photo
var numHotel=0; //first photo
var numFood=0; //first photo
var numPH=0; //first photo

var currOrange=0; //curr photo
var currHotel=0; //curr photo
var currFood=0; //curr photo
var currPH=0; //curr photo

var arrOrange=new Array();	//array of photos
var arrHotel=new Array();	//array of photos
var arrFood=new Array();	//array of photos
var arrPH=new Array();	//array of photos

var maxPhotos=5;	//max num photos per catagory

function photoScrollInit(cat,first,num){
	var arr=new Array();
	var p=0;
	//fill photo arrays and mark where first photo of this catagory exists
	
	if(cat=='orange'){
		firstOrange=first;
		numOrange=num;
		for(i=first;i<gallery.length;i++){
			arrOrange[p]=gallery[i];
			p++;
			if(p==num){break;}
		}
		arr=arrOrange;
	}else if(cat=='hotel'){
		numHotel=num;
		firstHotel=first;
		for(img=first;img<gallery.length;img++){
			
			arrHotel[p]=gallery[img];
			p++;
			if(p==num){break;}
		}
		arr=arrHotel;
	}else if(cat=='food'){
		firstFood=first;
		numFood=num;
		for(i=first;i<gallery.length;i++){
			arrFood[p]=gallery[i];
			p++;
			if(p==num){break;}
		}
		arr=arrFood;
	}else if(cat=='ph'){
		firstPH=first;
		numPH=num;
		for(i=first;i<gallery.length;i++){
			arrPH[p]=gallery[i];
			p++;
			if(p==num){break;}
		}
		arr=arrPH;
	}
	
	//show photos
	showPhotos(cat,0,arr,first);
}
function nextPhoto(cat){
	var arr=new Array();
	var first,curr=0;
	if(cat=='orange'){
		currOrange+=1;
		if(currOrange>numOrange){currOrange=currOrange-numOrange;}
		curr=currOrange;
		arr=arrOrange;
		first=firstOrange;
	}else if(cat=='hotel'){
		currHotel+=1;
		if(currHotel>numHotel){currHotel=currHotel-numHotel;}
		curr=currHotel;
		arr=arrHotel;
		first=firstHotel;
	}else if(cat=='food'){
		currFood+=1;
		if(currFood>numFood){currFood=currFood-numFood;}
		curr=currFood;
		arr=arrFood;
		first=firstFood;
	}else if(cat=='ph'){
		currPH+=1;
		if(currPH>numPH){currPH=currPH-numPH;}
		curr=currPH;
		arr=arrPH;
		first=firstPH;
	}
	showPhotos(cat,curr,arr,first);
}
function prevPhoto(cat){
	var arr=new Array();
	var first,curr=0;
	if(cat=='orange'){
		currOrange-=1;
		if(currOrange<0){currOrange=numOrange+currOrange;}
		curr=currOrange;
		arr=arrOrange;
		first=firstOrange;
	}else if(cat=='hotel'){
		currHotel-=1;
		if(currHotel<0){currHotel=numHotel+currHotel;}
		curr=currHotel;
		arr=arrHotel;
		first=firstHotel;
	}else if(cat=='food'){
		currFood-=1;
		if(currFood<0){currFood=numFood+currFood;}
		curr=currFood; 
		arr=arrFood;
		first=firstFood;
	}else if(cat=='ph'){
		currPH-=1;
		if(currPH<0){currPH=numPH+currPH;}
		curr=currPH;
		arr=arrPH;
		first=firstPH;
	} else {
		return;
	}
		
	showPhotos(cat,curr,arr,first);
}

function showPhotos(cat,loc,arr,first){
	var html='';
	var cell;
	var el,offset;
		
	for(var i=0;i<maxPhotos;i++){
		if((i+loc)>=arr.length){
			if((((loc+i) - arr.length))>=0){
				el=arr[((loc+i) - arr.length)];
				offset=((loc+i) - arr.length);
			}else{
				return;
			}
		}else{
			el=arr[i+loc];
			offset=i+loc;
		}
		
// 0 1 2 3 4 5 6 7 8
//                 L
// 1
//loc=8, i=1, arr.length=8, maxPhotos=5
//loc+i=9  ---  ((loc+i) - arr.length)


		html='<a href="javascript:chooseSlide('+(first+offset)+');"><img src="'+el[1]+'" alt="'+el[2]+'" name="img'+(first+offset)+'" width="47" height="29" border="0" class="photo-border" id="img'+(first+offset)+'" /></a>';
		cell=document.getElementById('td'+cat.toLowerCase()+(i));
		cell.innerHTML=html;
	}
}
function preloadGallery(){
	for(x=0;x<gallery.length;x++){
		MM_preloadImages(gallery[x][1]);
	}
}

