

$(document).ready(function() {
    var startX = YAHOO.util.Dom.getX('scrollable');
    // slides in one pic from the left if there are any
    $(document.getElementById('prev')).click(function() {
      var list = YAHOO.util.Dom.getElementsByClassName('thumbnail');
      var limit = -(list.length*58-576-startX);
      var currX = YAHOO.util.Dom.getX('scrollable');
      var currY = YAHOO.util.Dom.getY('scrollable');
      if(currX < startX) {
        var scrollanim = new YAHOO.util.Motion('scrollable',{points:{to:[currX+58,currY]}}, .5);
        scrollanim.animate();
	if(currX <= limit) {
	  var addanim = new YAHOO.util.Motion('next',{opacity:{to:1}},.5);
	  addanim.animate();
	}
      }
      if(currX+58 >= startX) {
        var removeanim = new YAHOO.util.Motion('prev',{opacity:{to:0}},.5);
	removeanim.animate();
      }
    });

    // slides in one pic from the right if there are any
    $(document.getElementById('next')).click(function() {
      var list = YAHOO.util.Dom.getElementsByClassName('thumbnail');
      var limit = -(list.length*58-576-startX);
      var currX = YAHOO.util.Dom.getX('scrollable');
      var currY = YAHOO.util.Dom.getY('scrollable');
      if(currX > limit) {
        var scrollanim2 = new YAHOO.util.Motion('scrollable',{points:{to:[currX-58,currY]}}, .5);
        scrollanim2.animate();
	if(currX >= startX) {
	  var addanim = new YAHOO.util.Motion('prev',{opacity:{to:1}},.5);
	  addanim.animate();
	}
      }
      if(currX-58 <= limit) {
        var removeanim = new YAHOO.util.Motion('next',{opacity:{to:0}},.5);
	removeanim.animate();
      }
    });

    // remove arrows if there aren't any to slide in
    if(YAHOO.util.Dom.getX('scrollable') >= startX) {
      var removeanim = new YAHOO.util.Motion('prev',{opacity:{to:0}},.5);
      removeanim.animate();
    }

    if(YAHOO.util.Dom.getElementsByClassName('thumbnail').length <= 9) {
      var removeanim = new YAHOO.util.Motion('next',{opacity:{to:0}},.5);
      removeanim.animate();
    }

    // bring image to front on hover and display text
    function hoveron (e) {
      var anim = new YAHOO.util.Anim(this,{opacity:{to:0}},.5);
      anim.animate();
      var nodes = this.parentNode.childNodes;
      var textnode = this.parentNode.lastChild;
      for(var i=0; i<nodes.length; i++) {
	if(nodes[i].className == "text") {
	  textnode = nodes[i];
	  break;
	}
      }
      var textanim = new YAHOO.util.Anim(textnode,{opacity:{to:1}},.5);
      textanim.animate();
    }

    function hoveroff (e) {
      var anim = new YAHOO.util.Anim(this,{opacity:{to:.5}},.5);
      anim.animate();
      var nodes = this.parentNode.childNodes;
      var textnode = this.parentNode.lastChild;
      for(var i=0; i<nodes.length; i++) {
	if(nodes[i].className == "text") {
	  textnode = nodes[i];
	  break;
	}
      }
      var textanim = new YAHOO.util.Anim(textnode,{opacity:{to:0}},.5);
      textanim.animate();
    }

    $('div.cover').hover(hoveron,hoveroff);

  });