(function($){

var ns = 'SinglePage';

window[ns] = function ( id ) {
  this.ajax_url = AJAX_BASE + 'page/?id=' + id;
  
  this.prepare();
  this.load();
};

window[ns].prototype = {
  
  prepare: function () {
    this.root = $('<div>').addClass('single-page')
                          .appendTo('body')
                          .hide()
                          .css({
                              position: 'absolute',
                              top: 0, left: 0
                            });
    
    new FullWindow(this.root, {overflow: 'auto'});
  },
  
  load: function () {
    $.get( this.ajax_url, $.proxy( this.done, this ) );
  },
  
  done: function ( data ) {
    this.root.html(data).fadeIn();
    if ( appleDevice() ) {
      this.touchScroll = new TouchScroll( this.root, this.root.find('.ajax-page-content').get(0) );
    }
  },
  
  exit: function () {
    if ( appleDevice() ) {
      this.touchScroll.exit();
    }
    this.root.fadeOut( function(){$(this).remove();} );
  }

}

})(jQuery);
