var current_image = 0
var total_images = -1
var images_loaded = 0
var anim_speed = 200

//
function init(){
	total_images = Number($(".image:last").attr("id").replace("image_", ""))
	$("#prev").click(previous_image)
	$("#next").click(next_image) 
	$(".image:first").load(function(){
		show_image(1)
	})
}
//
function show_image(n_){
	//alert("show_image("+n_+")")
	///*
	///*
	$(".image").each(function(){
		if($(this).attr("id") == "image_"+n_){
			$(this).removeClass("hide")
			$(this).addClass("on_top")
			$(this).fadeTo(0, 0)
			$(this).fadeTo(anim_speed, 1)
		}else{
			if(!$(this).hasClass("hide")){
				$(this).removeClass("on_top")
				$(this).fadeTo(anim_speed, 1, function(){
					$(this).fadeTo(anim_speed, 0, function(){
						$(this).addClass("hide")						
					})
				})
			}
		}
	})
	//
	$("#images_hold").animate({
		height:$("#image_"+n_).height()
	}, 0)
	current_image = n_
}
//
function previous_image(){
	//alert("previous_image()")
	if(current_image > 1){
		show_image(current_image-1)
	}else{
		show_image(total_images)
	}
	return false
}
//
function next_image(){
	//alert("next_image()")
	if(current_image < total_images){
		show_image(current_image+1)
	}else{
		show_image(1)
	}
	return false
}
//
function an_image_has_loaded(){
	if(images_loaded == 0){
		show_image(1)
	}else{
		images_loaded++		
	}
}
//
$(document).ready(init)