/*
Clearpoint scripts by Mike Bingaman for Tanagram Partners
Extends MooTools
*/
var tp = {
  init: function() {
    slide.init();
    if ($('demo'))
      demo.init();
  }
};

var slide = {
  init: function(options) {
    this.options = Object.extend({
      slideContent: 'slide_content',
      slideLeft: 'slide_arrow-l',
      slideRight: 'slide_arrow-r',
      show: 3
    }, options || {});

    move = new Fx.Style(this.options.slideContent,'left',{duration:350,transition:Fx.Transitions.Quad.easeIn});

    var content = $(this.options.slideContent);
    if (content) {
      var children = content.getChildren();
      var margins = children[0].getStyles('margin-left', 'margin-right');
      var width = children[0].getSize().size.x+margins['margin-left'].toInt()+margins['margin-right'].toInt();
      var count = children.length;
      var maxLeft = width*count-width*this.options.show;
    }
      
    if ($(this.options.slideRight)) {
      $(this.options.slideRight).addEvent('click', function(e) {
        e = new Event(e);
        if(content.getStyle('left').toInt()>-maxLeft)
          move.start(content.getStyle('left').toInt()-width);
        e.stop();
      });

      $(this.options.slideLeft).addEvent('click', function(e) {
        e = new Event(e);
        if(content.getStyle('left').toInt()<0)
          move.start(content.getStyle('left').toInt()+width);
        e.stop();
      });    
    }
  }
};

var demo = {
  init: function() {
    $each($$('#slide_content a'), function(item){
      item.onclick = function() {
        $('demo_image').src = item.href;
        $('demo_caption').innerHTML = item.title;
        return false;
      }
    });
  }
}

window.addEvent('domready', tp.init);
