
var cycle = new function() {

  this.index = 1;
  this.locked = false;
  this.effects = new Array();
  this.btn = null;

  this.imagelist = [ '',
    'iceberg_01_intro_318.jpg',
    'iceberg_02_pagination_318.jpg',
    'iceberg_03_typescaling_318.jpg',
    'iceberg_09_notes_318.jpg',
    'iceberg_04_search_318.jpg',
    'iceberg_05_bookshelf_318.jpg',
    'iceberg_06_store_318.jpg',
    'iceberg_07_copy_318.jpg',
    'iceberg_08_email_318.jpg',
    'iceberg_10_gotochapter_318.jpg',
    'iceberg_11_booknavigation_318.jpg'
    ];

  this.next = function(btn) {
    this.buttonHandle(btn);
    if (this.index != 11)
    {
      this.fade_to(this.index+1);
    }
    return false;
  }

  this.last = function(btn) {
    this.buttonHandle(btn);
    if (this.index != 1)
    {
      this.fade_to(this.index-1);
    }
    return false;
  }

  this.goto = function(btn,number) {
    this.buttonHandle(btn);
    if (this.index != number && number)
    {
      this.fade_to(number);
    }
    return false;
  }

  this.buttonHandle = function(btn) {
    btn.blur();
    /*
    if (this.btn) this.btn.className = '';
    this.btn = btn;
    this.btn.className = 'on';
    */
  }

  this.fade_to = function(number) {
    if (this.locked) return;
    this.locked = true;

    document.getElementById('cb'+this.index).className = '';
    document.getElementById('cb'+number).className = 'on';

    //begin download of image
    var imgsrc = 'http://cdn.cloudfiles.mosso.com/c111442/'+this.imagelist[number];
    var img = new Image();
    img.src = imgsrc;

    $('#cycle-image').fadeOut('slow',function() {
      document.getElementById('cycle-image').src = imgsrc;
      $('#cycle-image').fadeIn('slow', function() {});
    });

    $('#cycle-item'+this.index).fadeOut('slow',function() {
      $('#cycle-item'+number).fadeIn('slow', function() {
        cycle.index = number;
        cycle.locked = false;
      });
    });
  }

}

var slider = new function() {

  this.locked = false;

  this.right = function(btn) {
    btn.blur();
    if (this.locked) return;

    var l = parseInt($('#slider_pane').get(0).style.left); if(!l) l=0;
    /* below should really be inverse of offsetleft of last child + 600 */
    if (l > -92 * 200 + 800)
    {
      l -= 800;
        this.locked = true;
      $('#slider_pane').animate({left:l},1000, function() {
        slider.locked=false;
      });

    }
    return false;
  }

  this.left = function(btn) {
    btn.blur();
    if (this.locked) return;

    var l = parseInt($('#slider_pane').get(0).style.left); if(!l) l=0;
    if (l < 0)
    {
      l += 800;
      this.locked = true;
      $('#slider_pane').animate({left:l},1000, function() {
        slider.locked=false;
      });
    }
    return false;
  }

  this.showall = function(btn) {
    btn.blur();
    if (this.locked) return;

    $('#slider_container').css({left:0, height: 'auto', overflow: 'visible'});
    $('#slider_pane').css({width: 'auto'});
    $('#slider_left').hide();
    $('#slider_right').hide();
    $('.slider_entry').css({height:'160px',paddingTop:'8px'});
    $(btn).hide();
  }
}