function loadGalleryPage(photoset_id, pageNum, per_page, totalPageNum, gallery_id) {
	var galleryTMP = document.getElementById("galleryTMP_"+gallery_id); 
	
	//display ajax loader gif
	$("#gallery_"+gallery_id+" div.ajaxLoader").css({"display":"block"});	
	
	//Remotely load html page
	loadHTML('/gallery/html_gallery_page_loader.php?ps='+photoset_id+'&per_page='+per_page+'&page='+pageNum, loadNewGallery, galleryTMP, gallery_id);
	
	//Update Gallery Page Number tracking text
	$("#gallery_"+gallery_id+" p.galleryPageNum").html(pageNum + "/" + totalPageNum); 
	
	//Set the next and previous page numbers
	var currentPageNum = pageNum;
	var nextPage = currentPageNum + 1;
	var prevPage = currentPageNum - 1;
	
	var nextButton = document.getElementById("galleryNextButton_"+gallery_id);
	var prevButton = document.getElementById("galleryPrevButton_"+gallery_id);
	
	//Disable or enable Next button
	if(currentPageNum == totalPageNum) {
		nextButton.className = "galleryNextDisable";
		nextButton.onclick = function(){return false;};
	}else{
		nextButton.className = "galleryNextActive";
		nextButton.onclick = function(){loadGalleryPage(photoset_id, nextPage, per_page, totalPageNum, gallery_id); return false;};
	}
	//Disable or enable Prev button
	if(prevPage < 1){
		prevButton.className = "galleryPrevDisable";
		prevButton.onclick = function(){return false;};
	}else{
		prevButton.className = "galleryPrevActive";
		prevButton.onclick = function(){loadGalleryPage(photoset_id, prevPage, per_page, totalPageNum, gallery_id); return false;};
	}
}

function loadNewGallery(storage,gallery_id) {
		$("#galleryContent_"+gallery_id).fadeOut(400, function(){
			$("#galleryContent_"+gallery_id).empty();	//delete photos from main div
			$("#galleryTMP_"+gallery_id+" a").clone().prependTo("#galleryContent_"+gallery_id);	//copy new gallery photos into main div
			$("#galleryContent_"+gallery_id+" a").slimbox();
		});
		
		$("#gallery_"+gallery_id+" div.ajaxLoader").css({"display":"none"}); //hide ajax loader gif
		
		$("#galleryContent_"+gallery_id).fadeIn(400);	//fade in new gallery page	
}

function loadFirstGalleryPage(params){
	var photoset_id = params[0];
	var per_page = params[1];
	var gallery_id = params[2];
	
	var storageTMP = document.getElementById("galleryTMP_"+gallery_id);
	loadHTML('/gallery/html_gallery_page_loader.php?ps='+photoset_id+'&per_page='+per_page+'&page=1', loadNewGallery, storageTMP, gallery_id);	
}
