/**
 *  jQuery Fixed Position Plugin
 *  @requires jQuery v1.3
 *  http://www.socialembedded.com/labs
 *
 *  Copyright (c)  Hernan Amiune (hernan.amiune.com)
 *  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.0
 */
(function($){ $.fn.fixedPosition = function(options){

	var defaults = {
	  vpos: null,    // posible values: "top", "middle", "bottom". if it is null the original position is taken
	  hpos: null     // posible values: "left", "center", "right". if it is null the original position is taken
	};
	
	var options = $.extend(defaults, options);

	function initialize(that) {
		var top = parseInt(that.offset().top);
		var left = parseInt(that.offset().left);
		
		that.css("top",top+$(document).scrollTop()).css("left",left+$(document).scrollLeft());
		
		if(options.vpos === "top"){
		    that.css("top","0");
		}
		else if(options.vpos === "middle"){
		    that.css("top",((parseInt($(window).height())/2)-(that.height()/2))+"px");
		}
		else if(options.vpos === "bottom"){
		    that.css("bottom","0");
		}
		
		if(options.hpos === "left"){
		    that.css("left","0");
		}
		else if(options.hpos === "center"){
		    that.css("left",((parseInt($(window).width())/2)-(that.width()/2))+"px");
		}
		else if(options.hpos === "right"){
		    that.css("right","0");
		}
		that.initialized=true;
		that.fixedTop=top;
		that.fixedLeft=left;
	}


	
	return this.each(function(index) {
		var $this = $(this);

		if ($this.css("position")!="fixed") return;
		$this.initialized=false;
		$this.css("position","absolute");
		if ($this.is(":visible")) {
			initialize($this);
		}

		$(window).scroll(function () {
			if (!$this.initialized && $this.is(":visible")) {
				initialize($this);
			}
			if ($this.initialized) {
				$this.css("top",$this.fixedTop+$(document).scrollTop()).css("left",$this.fixedLeft+$(document).scrollLeft());
			}
		});
	});

	}

	

	$(document).ready(function() {
		if ($.browser.msie && $.browser.version=="6.0") {
//			$("*").fixedPosition(); // search all elements
			$("div").fixedPosition(); // search limited set of elements only
		}
	});

  
})(jQuery);
