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

/**
 * Magazine
 * Author:  Frank Broersen
 * Created: 9  - 12 - 09
 */
var Magazine = {

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

    Magazine.bindClicks();

  },

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

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

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

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

  /**
   * navigate
   * navigate between the shakers
   */
  navigate: function( direction ) {
    Magazine.unBindClicks();
    var url = Magazine.url + '?type=magazine&current=' + Magazine.current + '&direction=' + direction;
    $('#magazine .big img').hide();
    $('#magazine .small img').hide();
    $.getJSON( url, function( data ){
      Magazine.current = data.current;
      $('#magazine .big img ').attr('src',data.img);
      $('#magazine .big img ').fadeIn();
      $('#magazine .small img ').attr('src',data.nextimg);
      $('#magazine .c h2 span').html(data.titel);
      //$('#magazine .count strong').html(data.editie);
      $('#magazine .m').html('Lees hier ' + data.titel + ' gratis online');
      $('#magazine .m').attr('href','magazine/' + data.url);
      $('#magazine .small img ').fadeIn();
      Magazine.bindClicks();
    });
  }



}