var photo_id = 0;
var current_item = 0;

function preloadImages(){
	if (document.photos)
	{
		for(var i=0; i < photos[current_gallery_id].length; i++){
			var img = new Image();
			img.src = photos[current_gallery_id][i][1];	
		}
	}
}

function swapPhoto(id){
	try {
		if(id == 'next'){
			id = current_item + 1;
		}else if(id == 'prev'){
			id = current_item - 1;
		}
		//alert(current_gallery_id +", "+ id +", "+ photos[current_gallery_id]);
		document.getElementById('photo_url').src = photos[current_gallery_id][id][1];
		document.getElementById('photo_content').innerHTML = photos[current_gallery_id][id][2];
		current_item = id;
		updateNavButtons();
	} catch(e) { }
}

function updateNavButtons(){
	
	try {
		var prevbtn = document.getElementById('prevbtn');
		var nextbtn = document.getElementById('nextbtn');
		
		if(photos[current_gallery_id].length == 1){
			nextbtn.setAttribute('onClick', '');
			prevbtn.setAttribute('onClick', '');
			nextbtn.className = 'gallery_nav_inactive';
			prevbtn.className = 'gallery_nav_inactive';
		}else if(current_item == (photos[current_gallery_id].length-1)){
			nextbtn.setAttribute('onClick', '');
			prevbtn.setAttribute('onClick', "swapPhoto('prev');");
			nextbtn.className = 'gallery_nav_inactive';
			prevbtn.className = 'gallery_nav_active';
		}else if(current_item == 0){
			prevbtn.setAttribute('onClick', '');
			nextbtn.setAttribute('onClick', "swapPhoto('next');");
			nextbtn.className = 'gallery_nav_active';
			prevbtn.className = 'gallery_nav_inactive';
		}else{
			prevbtn.setAttribute('onClick', "swapPhoto('prev');");
			nextbtn.setAttribute('onClick', "swapPhoto('next');");
			nextbtn.className = 'gallery_nav_active';
			prevbtn.className = 'gallery_nav_active';
		}
	} catch(e) { }
}

preloadImages();
updateNavButtons();
