$(document).ready(function() {
  /* drawer */
  $('div.drawer_handle').click(function() {
    if ($('div.drawer_handle').css('right') == '165px') { //close drawer
      if (new String(location.pathname).indexOf('2009/index.php') >= 0) {
        $('div.drawer_handle').animate({"right" : "-1px"}, "fast");
        $('div.drawer_menu').animate({"right" : "-190px"}, "fast", function() {
          $('div.drawer_handle').css('top', '-657px');
          $('div#drawer').css('top', '135px');
          $('div#drawer').css('height', '96px');
          $('div#drawer').css('width', '65px');
        });
      }
      else {
        $('div.drawer_handle').animate({"right" : "-1px"}, "fast");
        $('div.drawer_menu').animate({"right" : "-190px"}, "fast", function() {
          $('div.drawer_handle').css('top', '-657px');
          $('div#drawer').css('top', '85px');
          $('div#drawer').css('height', '96px');
          $('div#drawer').css('width', '65px');
        });
      }
    }
    else { //open drawer
      if (new String(location.pathname).indexOf('2009/index.php') >= 0) {
        $('div.drawer_handle').css('top', '-522px');
        $('div#drawer').css('top', '0px');
        $('div#drawer').css('height', '663px');
        $('div#drawer').css('width', '223px');
        $('div.drawer_handle').animate({"right" : "165px"}, "fast");
        $('div.drawer_menu').animate({"right" : "0px"}, "fast");
      }
      else {
        $('div.drawer_handle').css('top', '-572px');
        $('div#drawer').css('top', '0px');
        $('div#drawer').css('height', '663px');
        $('div#drawer').css('width', '223px');
        $('div.drawer_handle').animate({"right" : "165px"}, "fast");
        $('div.drawer_menu').animate({"right" : "0px"}, "fast");
      }
    }
  })

  
  /* quarterly reports blockui */
  $('span.quarter_blockui').click(function() {
    var path_php = location.pathname.substring(location.pathname.lastIndexOf('/') + 1);
    $.ajax({ 
        url: 'http://' + location.hostname + new String(location.pathname).replace(path_php, '') + 'drawer/data.php?q=' + $(this).find('a').attr('class'),
        cache: true, 
        success: function(data) { 
          $('div#drawer_payload').html(data);
          var offset = $('div#wrap').offset();
          var offsetTop = ($(window).height() - 495) / 2
          var offsetLeft = ($(window).width() - 830) / 2;
          $.blockUI({ message: $('div#drawer_payload'), overlayCSS: { cursor: 'default', backgroundColor: '#666', opacity: 0.7 }, css: { width: '830px', left: offsetLeft + 'px', top: offsetTop + 'px', height: '495px', background: 'none', border: 'none', cursor: 'default' } }); 
        } 
    });     
  });
  
  $('div.drawer_close').click(function() {
    $.unblockUI();
  })

  /* window resize handler */
    $(window).resize(function() {
      var offset = $('div#wrap').offset();
      var offsetTop = ($(window).height() - 495) / 2
      var offsetLeft = ($(window).width() - 830) / 2;
      $('div.blockPage').css('left', offsetLeft + 'px');
      $('div.blockPage').css('top', offsetTop + 'px');
    });
  
  
  
});

