
$(document).ready(function() {
  Movers.init();
});

/**
 * Movers
 * Author:  Frank Broersen
 * Created: 8  - 12 - 09
 */
var Movers = {

  /**
   * init
   * bind the clicks and insert the current id into the javascript var
   */
  init: function() {
    
    Movers.current = $('#mover h2').attr('id').replace('s','');

    Movers.bindClicks();

  },

  /**
   * current
   * holds the current shaker id
   */
  current: 0,

  /**
   * url
   * the url of the shaker data
   */
  url: 'ajax/movers/',

  /**
   * bindClicks
   * bind clicks to the buttons
   */
   bindClicks: function() {
    $('#mover .p').bind('click',function() {
      Movers.navigate('p');
      return false;
    });
    $('#mover .n').bind('click',function() {
      Movers.navigate('n');
      return false;
    });
   },

  /**
   * unBindClicks
   * unbind clicks off the buttons
   */
   unBindClicks: function() {
    $('#mover .p').unbind('click');
    $('#mover .n').unbind('click');
   },

  /**
   * navigate
   * navigate between the shakers
   */
  navigate: function( direction ) {
    Movers.unBindClicks();
    var url = Movers.url + '?type=mover&current=' + Movers.current + '&direction=' + direction;
    $('#mover .i img').hide();
    $.getJSON( url, function( data ){
      Movers.current = data.current;
      $('#mover .i img ').attr('src',data.img);
      $('#mover .c h2  ').html(data.name);
      $('#mover .c p   ').html(data.text);
      $('#mover .c span').html(data.functie);
      $('#mover .c .m  ').attr('href',data.link);
      $('#mover .i img ').fadeIn();
      Movers.bindClicks();
    });
  }



}