$(document).ready(function () {
	$("#header-photos-main-container").scrollable({autopause: true}).circular().mousewheel().autoscroll({
		steps: 4,
		interval: 5000
	}).find("li.cloned a[rel^=prettyPhoto]").attr("rel", "");

	var imagesetNum = 0;
 	$("#content").find(".gallery").each(function() {
		var gallery = this;
		$(gallery).find("img[class!=no-link]").each(function() {
			var img = this;
			var lightboxLink = document.createElement("a");
			lightboxLink.setAttribute("rel", "prettyPhoto[set" + imagesetNum + "]");

			if ($(img).attr("title"))
				lightboxLink.setAttribute("title", $(img).attr("title"));
			else if ($(img).attr("alt"))
				lightboxLink.setAttribute("title", $(img).attr("alt"));
			else 
				lightboxLink.setAttribute("title", " ");

			lightboxLink.href = $(img).attr("src").replace(/(_t|_n)\./, '.');
			$(lightboxLink).prettyPhoto({theme: 'dark_rounded'});
			$(img).wrap($(lightboxLink));
		});
		imagesetNum++;
	});

	$(".gallery a").prettyPhoto({theme: 'dark_rounded'});

	$("ul.subnav").parent().append("<span></span>");
	$("ul.topnav li span").hover(function() {
		$(this).parent().find("ul.subnav").slideDown('fast').show();
		$(this).parent().hover(function() {
		}, function(){	
			$(this).parent().find("ul.subnav").slideUp('slow');
		});

		}).hover(function() { 
			$(this).addClass("subhover");
		}, function(){
			$(this).removeClass("subhover");
	});
});
