﻿$(document).ready(function() {
	$("#gallery, #gallery-small")
		.addClass("js")
		.css({"overflow": "hidden"})
		.find("ul.thumbnails")
			.each(function() {
				var li_width = $(this).children("li").outerWidth(false);
				var li_num = $(this).children("li").length;
				var need_width = li_width * li_num;

				$(this).width(need_width);
			}).end()
		.mousemove(function(e) {
			var this_width = $(this).outerWidth(false);
			var this_offset = $(this).offset();
			var diff = (e.pageX - this_offset.left - (.25 * this_width)) / this_width;
			var thumbs_width = $(this).find("ul.thumbnails").width() - (.25 * this_width);

			$(this).scrollLeft(diff * thumbs_width);
		});
	$("#gallery")
		.find("ul.thumbnails")
			.children("li")
				.mouseover(function(){
					var gallery = $(this).children("a").attr("href");
					gallery = gallery.split("=")[1];
					var subhead = $("#subhead img");
					var gallery_subhead = "galleries/" + gallery + "/hdor_" + gallery + ".gif";
					
					subhead.attr("src", gallery_subhead);
				});
});
