var noof_items = 0;
var current_item = 1;

function initializeGallery () {
	
	/* look at the url to see if it has a #no? and set current_item as appropriate */	
	
	$("#divGallery").find("li").each(function(){		
		noof_items ++;
		$(this).addClass("no" + noof_items).prepend("<a id=\"no" + noof_items + "\"></a>");
		if (noof_items != current_item) {
			$(this).toggle();
		}
	}).end().prepend("<div id=\"divGalleryControl\"></div>");
		
	setGalleryControl();
	
	$("#aGalleryControlPrev").click(function(){
		if (current_item > 1) {
			$("#divGallery ul li.no" + current_item).fadeOut("fast",function(){
				current_item --;
				$("#divGallery ul li.no" + current_item).fadeIn("fast",updateGalleryControl());
			});						
		}				
	});
	
	$("#aGalleryControlNext").click(function(){
		if (current_item < noof_items) {
			$("#divGallery ul li.no" + current_item).fadeOut("fast",function(){
				current_item ++;
				$("#divGallery ul li.no" + current_item).fadeIn("fast",updateGalleryControl());
			});						
		}				
	});	

}

function setGalleryControl () {		
	var myhtml = "";
	
	myhtml += "<span id=\"aGalleryControlCount\">" + current_item + " of " + noof_items + "</span> ";
	
	if (current_item > 1) {
		myhtml += "<a id=\"aGalleryControlPrev\" href=\"#no" + (current_item - 1) + "\">prev</a> | "	;
	} else {
		myhtml += "<a id=\"aGalleryControlPrev\">prev</a> | "	;		
	}
	
	if (current_item < noof_items) {
		myhtml += "<a id=\"aGalleryControlNext\" href=\"#no" + (current_item + 1) + "\">next</a>"	;
	} else {
		myhtml += "<a id=\"aGalleryControlNext\">next</a>"	;		
	}	
	
	$("#divGalleryControl").html(myhtml);		
}

function updateGalleryControl () {
	
	$("#divGallery #aGalleryControlCount").html(current_item + " of " + noof_items);
	
	if (current_item > 1) {
		$("#divGallery #aGalleryControlPrev").attr("href","#no" + (current_item - 1));
	} else {
		$("#divGallery #aGalleryControlPrev").removeAttr("href");	
	}
	
	if (current_item < noof_items) {
		$("#divGallery #aGalleryControlNext").attr("href","#no" + (current_item + 1));
	} else {
		$("#divGallery #aGalleryControlNext").removeAttr("href");	
	}	
}