	var direction = 0;
	var maxScroll = 0;
	var scrollRight = true;
	$(function(){
		$("#menu ul.nav").superfish();
		loadXML();
		$(document).bind("reveal.facebox",function(){
			$("#facebox .right").css("margin-right", ( ( $("#facebox .body").width() )/ 2) - (($("#facebox .left").width() + $("#facebox .right").width()) - $("#facebox .left").width() + $("#facebox .close").width()));
		})
	});
	
	function loadXML() {
		$.get("popin.xml", function(data) {
			$("#scroller-pane").css("background", "none");
			var images = $("image",data);
			maxScroll = images.length * (148 + 14);
			$("#scroller-pane").css("width", ( maxScroll ) + "px");
			images.each(function(){
				var a = "<a href='images/popin/full/" + $(this).attr("src") + "' rel='facebox'><img src='images/popin/thumbs/" + $(this).attr("src") + "' /></a>";
				$("#scroller-pane").append(a)
			})
			initializeScroll();
		});
	}
	
	function initializeScroll() {
		$("#scroller").data("x",1).mouseover(function() {
			$("#scroller").dequeue();
/*			if((event.clientX - $(this).offset().left) < 400) {
				$(this).data("x", -1)
			} else {
				$(this).data("x", 1)
			}
*/		});
		$("#scroller-pane a").facebox().click(function() {
			$(this).addClass("selected");
		});
		$("#main a").facebox().click(function() {
		});
		
		scroll();
	}
	
	function scroll() {
		$("#scroller").dequeue();
		direction = direction + ($("#scroller").data("x") * 2)
		if(direction <= 0) {
			direction = 0;
			$("#scroller").data("x", 1);
		} 
		if(direction >= (maxScroll - 800-7) ) {
/*			direction = maxScroll - 800;
			$("#scroller").data("x",-1);
			
*/		
			direction = 0;
			$("#scroller").data("x", 1);
		} 
		
		$("#scroller").animate({scrollLeft: direction}, 45, scroll)
	}
