;
 (function($) {
    // What does the pluginName plugin do?
		$.fn.scroll_top = function(){
			this.click(
				function(){
					var hash = this.hash;
					var top = $(document).scrollTop();
					var hash_top = $(hash).offset().top;
					var scroll_width = hash_top > top ? "+=50" :"-=50"; 
					$('body, html').animate({scrollTop:scroll_width,opacity:0.6},300,function(){
							$('body,html').scrollTop(hash_top).animate({opacity:1},100);
						});
					return false;
				}
			);
		};
    $.fn.rollover = function(options) {
        return this.each(function() {
            var $this = $(this);
            var src = $this.attr("src");
            if(src.match("_on\.(.*)")){
							var img_ro = $('<img />');
							img_ro.attr('src',src);
						}
						else{
						var dot = src.lastIndexOf('.');
            var imgsrc_ro = src.substr(0, dot) + '_on' + src.substr(dot, 4);
            var img_ro = $('<img />');
            img_ro.attr("src", imgsrc_ro);
						}
            img_ro.attr("width", this.width);
            img_ro.attr("height", this.height);
            img_ro.css({
                position: "absolute",
                display: "block",
                top: 0,
                left: 0,
                zIndex: -1
            }).insertAfter($this);
            var parent = $this.parent("div,li,a").css({
                "position": "relative",
                display: "block",
				zIndex:1
            });
	
            if(src.match("_on\.(.*)")){
							return;
						}
            $this.hover(
            function() {
                $this.stop().animate({
                    opacity: 0
                },
                600);
            },
            function() {
                $this.stop().animate({
                    opacity: 1
                },
                400);
            }
            );

        });
        // private function for debugging
        function debug($obj) {
            if (window.console && window.console.log) {
                window.console.log($obj);
            }
        }
    };

    $.fn.dropEffect = function() {
        return this.each(function() {

            var $this = $(this);
            var child = $this.children("ul");

            if (child.length) {
                var h_child = child.height() + "px";
                child.css({
                    overflow: "hidden",
                    height: "1px",
                    paddingBottom: 0,
					opacity:0
                });
                child.hover(
                function() {
                    $this.find("img:eq(0):not(img[src*=_on])").stop().animate({
                        opacity: 0
                    },
                    600);
                },
                function() {
                    $this.find("img:eq(0)").stop().animate({
                        opacity: 1
                    },
                    600);
                }
                );
                $this.hover(
                function() {
                    child.stop().animate({
                        opacity: 1,
                        height: h_child,
                        paddingBottom: "10px"
                    },
                    600);
                },
                function() {
                    child.stop().animate({
                        opacity: 0,
                        height: 0
                    },
                    600).css({}).css({
                        height: 0,
                        paddingBottom: 0
                    });
                    $this.find("img:eq(0)").stop().animate({
                        opacity: 1
                    },
                    600);
                }
                );
            }
        })

    };
	$.fn.muscle_height = function(){
		var height = [];
				var elt = this;
		elt.each(function() {
			var $this = $(this);
			height.push($this.height());
		});
		var max_height = Math.max.apply( {}, height )
		var min_height = Math.min.apply( {}, height )
		elt.css({height:max_height});
	
		
	};
	
	$.fn.scroll_fade = function(){
		this.each(function(){
			var elt = $(this);
			var offset = elt.offset();
			var win = $(window);
			var flag = true;
			
			if($(window).height() < offset.top){
			elt.css({opacity:0.1});
			win.scroll(function () {
				var top = win.scrollTop()
				var win_height = win.outerHeight();
				var bottom = top + win.height();
				if(flag && offset.top < bottom){
					flag = false;
					elt.animate({opacity:1}, 3000);
				}
			});
			}
			
		});
	};
	

})(jQuery);


$(document).ready(function() {
		$(".global-navi > li > a").current_web();
    $(".global-navi li a img").rollover();
    $(".global-navi li,.plan-box").dropEffect();
		$("a[href^=#]").scroll_top();
    $(".main img:not(.menu-bottom img,.menu-last img,.corner img),.staff-item").scroll_fade();
		$(window).unload();
});


