$(function () {

  $('#background').cycle({
    fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
    timeout: 8000
  });

  $('#content').jScrollPane({
    verticalDragMinHeight: 20,
    verticalDragMaxHeight: 20,
    horizontalDragMinWidth: 20,
    horizontalDragMaxWidth: 20
  });

  var api;

  $("#slider").easySlider({
    auto: true,
    continuous: true,
    nextId: "slider1next",
    prevId: "slider1prev",
    controlsShow: true,
    pause: 10000
  });

});

function showPage(module, page, id) {

  $('#services ul li').removeClass('active');
  $('#'+id).parent().addClass('active');

  if($('#services').css('marginLeft') == '294px') {
    $('#services').animate({
      width: '150px',
      marginLeft: '-=100'
    }, 1000, function() {
      $('#services-page').show();
      $('#services-page').animate({
        width: '420px'
      }, 1000, function() {
        getPage(module, page, '1');
      });
    });
  } else {
    $('#services-page-content').hide();
    getPage(module, page);
  }
  
}

function getPage(module, page, first) {
  $('#services-page-content').show();
  $('#services-page-content').html($('#loading').text());
  $.post("/"+module+"/getPage", { page: page }, function(data) {
    $('#services-page').css('background', 'white url(/images/scrollbar-bg.png) repeat-y right');
    $('#services-page-content').html(data);
    $('#services-page-content').show();
    if(first == '1') {
      api = $('#services-page').jScrollPane({
        verticalDragMinHeight: 20,
        verticalDragMaxHeight: 20,
        horizontalDragMinWidth: 20,
        horizontalDragMaxWidth: 20,
        autoReinitialise: true
      }).data('jsp');
      api.reinitialise();
      api.scrollToY(0);
    } else {
      $('#services-page').css('width', '420px');
      api.reinitialise();
      api.scrollToY(0);
    }
  });
}

