/*
 * Fixed Bar -  Places a bar non-moving div on the top or bottom of the webpage
 * By Tom LeZotte (http://plugins.jquery.com/project/fixed-bar)
 * Copyright (c) 2009 Tom LeZotte (tlezotte@gmail.com)
 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
*/


(function($){  

   $.fn.fixedBar = function(options) {
      //Set Defaults
      var defaults = {
         position: 'bottom',
         height: this.height()
      };

      //Merge "defaults" and "options"
      $.extend(defaults, options);

      var height = defaults.height * 2 + 20;
      
      //Set CSS styles
      var cssObj = {
         'position' : 'fixed',
         'left' : '0',
         'width' : '100%'
      }
      //Set CSS position style
      var positionObj = (defaults.position == 'bottom') ? {'bottom': '0'} : {'top': '0'};

      //Merge style items
      $.extend(cssObj, positionObj);

      /* ===== Set ===== */
      //Add fixed bar padding to page
      $('body').css("padding-" + defaults.position,defaults.height);
      
      //Apply CSS style to bar
      this.css(cssObj);

      if($.browser.msie && jQuery.browser.version.substr(0,1) <= 6)
      {
         this.css({'position': 'absolute'});
         this[0].style.setExpression('left', "document.body.scrollLeft");
         $('body').css({'background': "url('/any.gif') no-repeat", 'background-attachment': "fixed"});
         var expr =
            "(( document.documentElement && document.documentElement.clientHeight ) ? " +
               "document.documentElement.clientHeight : " +
               "document.body.clientHeight ) + document.documentElement.scrollTop - " + (parseInt(defaults.height));
         
         if(defaults.position == 'top')
            this[0].style.setExpression('top', "document.body.scrollTop");
         else
            this[0].style.setExpression('top', expr);
         
         var t = this;
         document.documentElement.onscroll = function(e){
            if(defaults.position == 'top')
               t[0].style['top'] = document.documentElement.scrollTop + 'px';
            else
               t[0].style['top'] = eval(expr) + 'px';
         };
         document.recalc(true);
      }
   }

})(jQuery); 