/*
* BCDC.US - centerMe jQuery plugin
* Examples and documentation at: http://bcdc.us
*
* This Version 1.1 ( Apr-07-2010 )
* [ history - Version: 1.0 ( Jan-09-2010 ) ]
* [ history - Version: 0.9 beta ( Dec-23-2009 ) ]
*
* Copyright (c) 2009 Bruno Correia
* Requires: jQuery v1.3+
*
* Demo at http://bcdc.us/jquery.plugins/jquery.centerMe/demo.html
*
*/

(function($) {
  $.fn.centerMe = function(customOptions) {
      var options = $.extend({},$.fn.centerMe.defaultOptions, customOptions);

      if (options.displayBlock === true) {
      $(this).css({'display':'block'});
      }
      
      function viewport() {
      var documentElement = document.documentElement;
      var pageWidth = window.innerWidth || self.innerWidth || (documentElement && documentElement.clientWidth) || document.body.clientWidth;
      var pageHeight = window.innerHeight || self.innerHeight || (documentElement && documentElement.clientHeight) || document.body.clientHeight;
      var pageSize = [pageWidth, pageHeight];
      // return pageSize;
      return pageSize[1];
      }

      window.onresize = function() {
      center();
      }      

      function center() {
      var currentHeigh = viewport();
      var myPadding = Math.floor((currentHeigh-options.elementHeigh) / 2);
      if ( myPadding < 0 ) { myPadding = 0 } // avoid negative value because of IE7
      $('body').css('padding-top', myPadding + "px");
      } center();
  };
    
  $.fn.centerMe.defaultOptions = {
    elementHeigh: '440', // this value should be total height of the choosen element, include paddings if any.
    displayBlock: true  // default for eldorado stone
  };

})(jQuery);
