jQuery.extend( jQuery.easing,
{
    def: 'easeOutExpo',
    easeInExpo: function (x, t, b, c, d) {
        return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
    },
    easeOutExpo: function (x, t, b, c, d) {
        return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
    },
    easeInOutExpo: function (x, t, b, c, d) {
        if (t==0) return b;
        if (t==d) return b+c;
        if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
        return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
    }
});

$.fn._hover = function () {
    return this.each(function(){
        $(this).hover(
            function(){ $(this).stop().animate({ opacity: 0.7 }, 200 ); },
            function(){ $(this).stop().animate({ opacity: 1 }, 200 ); }
        );
    });
}

$.fn.imgchange = function(options){
    var m = $.extend({
        name:  "-o",
        reverse: false
    }, options);

    return this.each(function(){
        if (!this) return false;
        var src     = $(this).attr("src");
        var hheight = $(this).attr("height");
        var hwidth  = $(this).attr("width");
        var ftype = src.substring(src.lastIndexOf('.'), src.length);
        var hsrc  = src.replace(ftype, m.name + ftype);
        var img = new Image();
        img.src = hsrc;
        if(!hheight)
            hheight = img.height;
        if(!hwidth)
            hwidth  = img.width;
        $(this).parent()
        .css({
           display: 'block',
           backgroundImage: 'url(' + img.src + ')',
           backgroundRepeat: 'no-repeat',
           //margin: 0,
           padding: 0,
           lineHeight: 0,
           fontSize: 0,
           width: hwidth + 'px',
           height: hheight + 'px'
        });
        if(!m.reverse){
                $(this).hover(
                    function(){ $(this).stop().animate({ opacity: 0 }, 300 ); },
                    function(){ $(this).stop().animate({ opacity: 1 }, 300 ); }
                );
            }
            else {
                $(this).css({ opacity: 0 });
                $(this).hover(
                    function(){ $(this).stop().animate({ opacity: 1 }, 300 ); },
                    function(){ $(this).stop().animate({ opacity: 0 }, 300 ); }
                );
            }
    });
    //return this;
}


$.fn.scrollPage = function (){
    var _url  = location.href.split('#')[0];
    var _hash = location.hash;
    $('a', this ).each(function() {
        if (this.href.indexOf(_url + '#') == 0) {
            var _id = this.href.split('#')[1];
            $(this).click(function(){
                    var _top = $('#' + _id).offset().top;
                    $($.browser.safari?'body':'html').animate({scrollTop:_top-20},1500,'easeInOutExpo');
            });

            if(!($.browser.msie && $.browser.version==6))
                $(this).removeAttr('href');
            $(this).css('cursor','pointer');
        }

    });
    if(_hash != ('undefined'|''|null)){
        var _target = $(_hash);
        if(_target.length){
            var _top = _target.offset().top;
            $($.browser.safari?'body':'html').animate({scrollTop:_top-20},1500,'easeInOutExpo');
        }
    }
}

var cache = [];
$.preLoadImages = function() {
	var args_len = arguments.length;
	for (var i = args_len; i--;) {
	  var cacheImage = document.createElement('img');
	  cacheImage.src = arguments[i];
	  cache.push(cacheImage);
	}
}

//flashからスクロール用
function scrollFromFl(t){
	var t = $(t);
	var _t = t.offset().top;
	$($.browser.safari?'body':'html').stop().animate({ scrollTop: _t-20 },1500,'easeInOutExpo');
}

var _body = $('body');
function init(){
    $(".over",_body).imgchange();
	$(".hover",_body)._hover();
}
function comp(){
	//galleryページ以外はスクロールon
	if(!$(".page-gallery",_body).length) {
    	$(_body).scrollPage();	
	}
}

$(init);
$(window).load(comp);
