/*
 * jQuery Floating Widget plugin v0.9.1
 * http://terkel.jp/archives/2011/05/jquery-floating-widget-plugin/
 *
 * Copyright (c) 2011 Takeru Suzuki
 * Dual licensed under the MIT and GPL licenses.
 */
//ちょこっと修正

(function ($) {
    $.fn.floatingWidget = function () {
        return this.each(function () {
			//add 2011 10 31
			var $LockTarget = $(".contLeft");

			var $this             = $(this),
				$parent           = $this.offsetParent(),
				$window           = $(window),

				//top               = $this.offset().top - parseFloat($this.css('marginTop').replace(/auto/, 0)),
				top	=	$LockTarget.offset().top - parseFloat($LockTarget.css('marginTop').replace(/auto/, 0)),

				floatingClass     = 'floating',
				pinnedBottomClass = 'pinned-bottom';

			//if ($parent.height() > $this.outerHeight(true)) {

			if ($LockTarget.height() > $this.outerHeight(true)) {
				$window.scroll(function () {
					var y      = $window.scrollTop(),
					bottom = $LockTarget.offset().top + $LockTarget.height() - $this.outerHeight(true);
					if (y > top) {
						$this.css("top","");
						$this.addClass(floatingClass);
						if (y > bottom) {
							$this.css("top",bottom|0);
							$this.removeClass(floatingClass).addClass(pinnedBottomClass);
						}else{
							$this.css("top","");
							$this.removeClass(pinnedBottomClass);
						}
					}else{	
						$this.css("top","");
						$this.removeClass(floatingClass);
					}
				});
			}
		});
	};
})(jQuery);

