var page = require('webpage').create();
var system = require('system');

page.paperSize = {
  width: '29cm',
  height: '21cm',
  margin: {
    top: '1cm', left: '1cm', right: '1cm', bottom: '1cm'
  }
};

page.open(system.args[1], function() {
  x = page.evaluate(function() {
    $('#top, #header, #sidebar, #sidebar-toggle, #breadcrumb, a.back').hide();
    $('#sidepage, #main').removeClass('sidepage-expanded');
    $('html').css('background', 'white').css('font-size', '8pt');
    $('div#main').css('width', '95%');
    $('div#main-content').css('width', '95%').css('border', 'none');
    $('#statistics .criterias').css('display', 'block');
    $('div#main-content > h2').css({
            'border-bottom': '1px solid #666',
            'font-weight': 'bold'});
    var date = $('<p>' + new Date().toLocaleString() + '</p>').appendTo('div#main-content');
    date.css({
            'position': 'absolute',
            'top': '2ex',
            'right': '1em'});
  });
  page.render(system.args[1] + '.pdf');
  phantom.exit();
});
