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