/**
 * floater
 * 
 * @category    jQuery plugin
 * @license     http://www.opensource.org/licenses/mit-license.html  MIT License
 * @copyright   2010 RaNa design associates, inc.
 * @author      keisuke YAMAMOTO <keisukey@ranadesign.com>
 * @link        http://kaelab.ranadesign.com/
 * @version     1.1.2 +R2
 * @date        Jan 17, 2012
 *
 * コンテンツをスクロールに追従させ、ドキュメントの上下に接着させるプラグイン。
 *
 * +R1:WordPress 動作対応(Saya.)
 * +R2:リサイズイベントに対応(Saya.)
 *
 * [オプション]
 * marginTop:     上の余白
 * marginBottom:  下の余白
 * wait:          0～1(初期値 0.5)。0はナビが通り過ぎるまで待つ。1はナビの末端が出るとすぐ動きだす。
 * speed:         アニメーションにかける時間。
 * easing:        イージング
 * fixed:         trueでposition: fixedに切り替え。初期値はfalse。
 *
 */

j$ = jQuery;

(function(j$) {

    j$.fn.extend({

        floater: function(options) {
            var config = {
                marginTop: 0,
                marginBottom: 0,
                wait: 0.5,  // 0-1
                speed: 1000,
                easing: "swing",
                fixed: false
            };
            j$.extend(config, options);
            config.wait = j$(this).outerHeight() - j$(window).height() * config.wait;
            config.marginTop = parseInt(config.marginTop, 10) || 0;
            config.marginBottom = parseInt(config.marginBottom, 10) || 0;

            j$(this).each(function() {
                var self = j$(this);
                var d = j$(document).height();
                var h = self.outerHeight() + config.marginTop + config.marginBottom;

                if (config.fixed === true) {
                    self._fixed(config);
                    return true;
                }

                self.css("position", "absolute");

                j$(window).scroll(function() {
                    var s = j$(window).scrollTop();
                    var w = j$(window).height();

                    if (Math.abs(s - self.offset().top) < config.wait) {
                        return;
                    }

                    self.stop(true).animate({
                        top: (d - h) * s / (d - w) + config.marginTop
                    }, {
                        duration: config.speed,
                        easing: config.easing
                    });
                }).scroll();

                j$(window).resize(function() {
                    var s = j$(window).scrollTop();
                    var w = j$(window).height();

                    if (Math.abs(s - self.offset().top) < config.wait) {
                        return;
                    }

                    self.stop(true).animate({
                        top: (d - h) * s / (d - w) + config.marginTop
                    }, {
                        duration: config.speed,
                        easing: config.easing
                    });
                }).resize();

            });

            return this;
        },
        
        _fixed: function(config) {
            if (j$.browser.msie && j$.browser.version < 7) {
                j$(this).css("position", "absolute");
                this[0].style.cssText = "top: expression(documentElement.scrollTop + " + config.marginTop + " + 'px')";
                document.body.style.background = "url(null) fixed";
            } else {
                j$(this).css("position", "fixed").css("top", config.marginTop);
            }
        }
        
    });

})(jQuery);

jQuery(function() {
		
	j$("#floatMenu").floater({
		marginTop: 150,
		marginBottom: j$("#footer").outerHeight()+60
	});

	j$("#MenuDrop").toggle(
		function() {j$("#floatMenu").animate({left:'-=142'},500)
			j$(this).attr("src", "wp-content/themes/monoclome-forest21/images/menu-icon-on.png") },
		function() {j$("#floatMenu").animate({left:'+=142'},500)
			j$(this).attr("src", "wp-content/themes/monoclome-forest21/images/menu-icon-off.png")
			} );

}) ;


