/**
 * jquery.scrollfix - jQuery Function that fixes the sidebar on screen, on scroll.  
 * Only to be used for Nectar website - http://NectarBoutique.com
 * @requires jQuery v1.0.3
 *
 * Copyright (c) 2009 Mike Brenner (http://SunriseDesign.com)
 * Code assistance by Andres Descalzo (http://www.adescalzo.com.ar) - Thank you!
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 * Version: 1.1
 */

(function($) {

  $.fn.myScrollFix = function(options) {
    options = $.extend({
      footer:  "#footer",
      pthis: this,
      doc: $(document),
      win: $(window)
    }, options || {});

    options.footer = $(options.footer);
    options.action = function() {
      var element = options.pthis,
      doc_scroll_top = options.doc.scrollTop(),
      doc_height  = options.doc.height(),
      window_height = options.win.height(),
      element_height = options.pthis.height(),
      footer_height = options.footer.height();
	  var top_height = $(".entry-content").height()+210;
	  var increase_it;
	  
      if (window_height > element_height) {
        if ((doc_scroll_top + element_height) > (doc_height - footer_height - 9)) {
          element 
            .css("position","absolute")
            .css("top", "0");
        } else if (doc_scroll_top > top_height) {
          element
            .css("position","fixed")
            .css("top","9px")
			 .css("right","auto")
            .css("padding-top","0");
        } else {
          element
            .css("position","relative")
            .css("top","auto")
            .css("bottom","auto");    
        }
      } else {
        element
          .css("position","relative")
          .css("top","auto")
          .css("bottom","auto");
      }
    };

    $(window).bind("scroll", options.action);
    $(window).bind("resize", options.action);
	$(".employeePic").click(options.action);

    options.action();
  };
})(jQuery);
