var Villalvazo = {
	load_gallery: function(gallery_id, image_position){
		$("#current_gallery").attr("value", gallery_id);
		$("div .section-menu-element-thumbs").hide("slow");
		$("div .gallery-link").css('color', '#000000');
		$("#gallery-" + gallery_id).css('color', '#FF0033');
		$("#galleries-menu-element-thumbs-" + gallery_id).slideToggle("slow");
		if(galleries[gallery_id][image_position]){
			Villalvazo.load_image(gallery_id, image_position);
		}
	},
	load_image: function(gallery_id, image_position){
		$("#current_image").attr("value", image_position);
		$("#main-image").attr("src", galleries[gallery_id][image_position][0]);
		if($("#image-description")){
			$("#image-description").empty();
			$("#image-description").append("<span style='text-transform:uppercase;'>" + galleries[gallery_id][image_position][1] + "</span>");
			$("#image-description").append(" <i>" + galleries[gallery_id][image_position][2] + "</i>");
		}
		$("div #image-prev-next").empty();
		if(galleries[gallery_id].length > 1){
			$("div #image-prev-next").append("<a href='javascript:;' onclick='Villalvazo.prev_image()'>&lt;Prev</a>");
			$("div #image-prev-next").append("&nbsp;&nbsp;&nbsp;&nbsp;");
			$("div #image-prev-next").append("<a href='javascript:;' onclick='Villalvazo.next_image()'>Next&gt;</a>");
		}
		if($("#image-delete")){
			$("#image-delete").show();
			$("#image-delete").attr("href", galleries[gallery_id][image_position][3]);
		}
		if($("#image-edit")){
			$("#image-edit").show();
			$("#image-edit").attr("href", galleries[gallery_id][image_position][3] + "/edit");
		}
	},
	next_image: function(){
		current_gallery = $("#current_gallery").attr("value");
		current_image = $("#current_image").attr("value");
		image_position = parseInt(current_image) + 1;
		if(image_position > (galleries[current_gallery].length - 1)){
			image_position = 0;
		}
		Villalvazo.load_image(current_gallery, image_position);
	},
	prev_image: function(){
		current_gallery = $("#current_gallery").attr("value");
		current_image = $("#current_image").attr("value");
		image_position = parseInt(current_image) - 1;
		if(image_position < 0){
			image_position = (galleries[current_gallery].length - 1);
		}
		Villalvazo.load_image(current_gallery, image_position);
	}
}