/* -*-mode: js2; coding: utf-8-unix; -*-
 * slider.js
 * Copyright (C) 2009  Pumpkin Net  All rights reserved.
 * Pumpkin Net <http://www.pumpkinnet.to/>
 */
$(function() {
    var scrollSpeed = 1000;

    var scrPrev = function() {
      if (this.getRoot().data('scroll') && (this.getItemWrap().queue() == 0)) {
	this.prev(scrollSpeed, scrPrev);
      }      
    };

    var scrNext = function() {
      if (this.getRoot().data('scroll') && (this.getItemWrap().queue() == 0)) {
	this.next(scrollSpeed, scrNext);
      }      
    };

    $('.scrollable').hover(
      function(e) {},
      function(e) { $(this).data('scroll', false); }
    );
    
    $('.scrollable').mousemove(
      function(e) {
	var itemWidth = this.clientWidth / $(this).scrollable().getConf().size;
	var left = e.clientX - this.offsetLeft;
	if (left < itemWidth) {
	  // prev
	  if (! $(this).data('scroll')
	      && ($(this).scrollable().getItemWrap().queue() == 0)) {
	    $(this).data('scroll', true);
	    $(this).scrollable().prev(scrollSpeed, scrPrev);
	  }
	}
	else if ((this.clientWidth - itemWidth) < left) {
	  // next
	  if (! $(this).data('scroll')
	      && ($(this).scrollable().getItemWrap().queue() == 0)) {
	    $(this).data('scroll', true);
	    $(this).scrollable().next(scrollSpeed, scrNext);
	  }
	}
	else {
	  $(this).data('scroll', false);
	}
      }
    );
});

