
var max_num = imgArray.length - 1;
var img_str = '<img id="photo" src="'+init_img+'" />';

$(document).ready(function() {
	$("div#models-photos").append(img_str);
	reloadNav(1);
	$("div#models-photos div#cover").fadeOut("normal");
	
	$("#models-photo-nav img").click(function(){
		var file_name = $(this).attr('title');
		imageLoad(file_name);
	});
	
	$("#nav-next img").click(function(){
		var file_name = $(this).attr('title');
		imageLoad(file_name);
	});
	
	$("#nav-prev img").click(function(){
		var file_name = $(this).attr('title');
		imageLoad(file_name);
	});
});

function imageLoad(file_name) {
	var img_str = '<img id="photo" src="'+img_dir+ imgArray[file_name] + '.jpg" style="visibility:hidden" />';
	$("div#models-photos img#photo").remove();
	$("div#models-photos div#cover").show();
	$("div#models-photos").append(img_str);
	$("#photo").load().css("visibility", "visible");
	reloadNav(file_name);
	$("div#models-photos div#cover").fadeOut("normal");
}

function reloadNav(current_num) {
	current_num -= 0;
	if(current_num == max_num) {
		$("div#nav-next").hide();
	} else {
		var num = current_num + 1;
		$("div#nav-next img").attr("title", num);
		$("div#nav-next").show();
	}
	
	if(current_num == 1) {
		$("div#nav-prev").hide();
	} else {
		var num = current_num - 1;
		$("div#nav-prev img").attr("title", num);
		$("div#nav-prev").show();
	}
}