/*
 * jQuery.insideScroll.js
 * Copyright (c) 2010 KEYTON.CO,Ltd.
 * Dual licensed under MIT and GPL.
 * Date: 2010-5-20
 * @author Hayashi Naoki
 * @version 1.0.3
 * http://www.keyton-co.jp/
 */
jQuery(function(a){a.fn.insideScroll=function(e){e=e||{};e.duration=e.duration||800;e.easing=e.easing||"swing";e.replace=e.replace||false;var c=document.URL.split("#")[0];var f=a(window),i=a(document),g={},j={},h,b;var d=window.opera?document.compatMode=="BackCompat"?"body":"html":"html,body";return this.each(function(){var o=a(this);var m=o.attr("href").split("#");var p=m[1];if(m[0]!=""&&m[0]!=c){return}var n=a("#"+p+',[name="'+p+'"]').length?a("#"+p+',[name="'+p+'"]').eq(0):a("body");var l=n;n.parents(":not(html,body)").each(function(){var q=a(this);if(q.css("overflow")!="visible"){o.bind("click",function(){g.t=q.scrollTop();g.l=q.scrollLeft();q.scrollTop(0).scrollLeft(0);j.top=n.offset().top-q.offset().top;j.left=n.offset().left-q.offset().left;q.scrollTop(g.t).scrollLeft(g.l);k(q,j)});l=q;return}});o.bind("click",function(){j=l.offset();h=i.height()-f.height();b=i.width()-f.width();if(j.top>h){j.top=h}if(j.left>b){j.left=b}k(a(d),j,c+"#"+p);return false})});function k(m,n,l){m.animate({scrollTop:n.top,scrollLeft:n.left},{duration:e.duration,easing:e.easing,step:function(){a(this).bind("mousedown mousewheel DOMMouseScroll",function(){a(this).queue([]).stop()})},complete:function(){a(this).queue([]).stop();if(l&&e.replace){window.location.href=l}}})}};
a("a[href*='#']").insideScroll()
});