Gallery = {
	current:1,
	total:null,
	currentUrl:null,
	nodeList:null,
	init:function(){
		Gallery.nodeList = $("#images-list a");
		Gallery.total = Gallery.nodeList.length;
		
		if(Gallery.total < 1) return;
		
		// make current bold
		$("#images-list a:eq(0)").addClass("current");
		
		// add url of zoom image to href
		Gallery.currentUrl = $("#zoom a")[0].href;
		var array = (Gallery.currentUrl.split("/"));
		Gallery.currentUrl = "http://www.millionhands.net/images/zoom/" + array[4] +"/"+ array[5];	
		Gallery.updateHref();
	},
	prevImage:function(){
		if (Gallery.current == 1){
			Gallery.current = Gallery.total;
		} else {
			Gallery.current--;
		}
		Gallery.update();
	},
	nextImage:function(){
		if (Gallery.current == Gallery.total){
			Gallery.current = 1;
		} else {
			Gallery.current++;
		}
		Gallery.update();
	},
	showImage:function(index){
		Gallery.current = index;
		Gallery.update();
	},
	update:function(){
		Gallery.updateImg();
		Gallery.updateIndicator();
		Gallery.createImageUrl();
		Gallery.updateHref();
		return false;
	},
	updateImg:function(){
		$("#zoom img").attr("src", Gallery.nodeList[Gallery.current - 1].href);
	},
	updateHref:function(){
		$("#zoom a").attr("href", Gallery.currentUrl);
	},
	updateIndicator:function(){
		//remove all classes
		$("#images-list a").removeClass("current");
		
		//add class="current"
		if(Gallery.current == 1){
			$("#images-list a:eq(0)").addClass("current");
		} else if (Gallery.current == 2) {
			$("#images-list a:eq(1)").addClass("current");
		} else if (Gallery.current == 3) {
			$("#images-list a:eq(2)").addClass("current");
		} else if (Gallery.current == 4) {
			$("#images-list a:eq(3)").addClass("current");
		} else if (Gallery.current == 5) {
			$("#images-list a:eq(4)").addClass("current");
		}
	},
	createImageUrl:function(){
		Gallery.currentUrl = Gallery.nodeList[Gallery.current - 1].href;
		var array = (Gallery.currentUrl.split("/"));
		Gallery.currentUrl = "http://www.millionhands.net/images/zoom/" + array[4] +"/"+ array[5];	
	}
}

$(function() {   	
	Gallery.init();
 });
