// JavaScript Document

/* $(document).ready(function() {
   $("a").click(function() {
     alert("These links don't work yet. I'm just redeveloping the site!");
   });
 });

$(function() {
	$('div.gallery img').slidingGallery({
	container: $('div.gallery')
	});
	});


		$(document).ready(function(){	
			$("#slider").easySlider({
				auto: false, 
				continuous: true,
				prevText: '',
				nextText: ''
			});
		});	
*/
$(document).ready(function(){
  gallery.trigger = $('#photos .trigger');
  gallery.content = $('#photos_inner');
  gallery.scroll = false;
  gallery.width = 950;
  gallery.innerWidth = gallery.content.width();
  gallery.timer = false;
  
  gallery.init();
});

gallery = {};

gallery.offset = function() {
  var left = gallery.content.position().left;
  if (gallery.scroll == '>') {
    if (left < 0) {
      left += gallery.width;
    }
  }
  else {
    if (left <= 0 && left >= ((gallery.innerWidth * -1) + (gallery.width * 2))) {
      left -= gallery.width;
    }
  }
  return left + "px";
}

gallery.slide = function() {
  if (gallery.timer) {
    clearTimeout(gallery.timer);
  }
  if (gallery.scroll) {
    $(gallery.content).stop(true,true).animate({left: gallery.offset()}, 750);
    gallery.timer = setTimeout(gallery.slide, 1500)
  }
}

gallery.direction = function(e,which) {
  var x = e.pageX - which.offset().left;
  gallery.scroll = (x >= gallery.width / 2) ? ">" : "<";
}

gallery.init = function() {
  $(gallery.trigger)
    .mouseout(function() {gallery.scroll = false;})
    .mousemove(function(e) {gallery.direction(e,gallery.trigger);})
    .mouseover(function(e) {
      gallery.direction(e,gallery.trigger);
      gallery.slide();
    });
}



