// JavaScript Document
(function($){
	var goToTopTime;
	$.fn.goToTop=function(options){
		var opts = $.extend({},$.fn.goToTop.def,options);
		var $window=$(window);
		$body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body'); // opera fix
		//$(this).hide();
		var $this=$(this);
		clearTimeout(goToTopTime);
		goToTopTime=setTimeout(function(){
			var controlLeft;
			if ($window.width() > opts.pageHeightJg * 2 + opts.pageWidth) {
				controlLeft = ($window.width() - opts.pageWidth) / 2 + opts.pageWidth + opts.pageWidthJg;
			}else{
				controlLeft = $window.width()- opts.pageWidthJg-$this.width();
			}
			var cssfixedsupport=$.browser.msie && parseFloat($.browser.version) < 7;//&#336;“F&#503;&#6757;6
			var controlTop=$window.height() - $this.height()-opts.pageHeightJg;
			controlTop=cssfixedsupport ? $window.scrollTop() + controlTop : controlTop;
			var shouldvisible=( $window.scrollTop() >= opts.startline )? true : false;
			
			if (shouldvisible){
				$this.stop().show();
			}else{
				$this.stop().hide();
			}
			
			$this.css({
				position: cssfixedsupport ? 'absolute' : 'fixed',
				top: controlTop,
				left: controlLeft
			});
		},30);
		
		$(this).click(function(event){
			$body.stop().animate( { scrollTop: $(opts.targetObg).offset().top}, opts.duration);
			$(this).blur();
			event.preventDefault();
			event.stopPropagation();
		});
	};
	
	$.fn.goToTop.def={
		pageWidth:910,//&#1203;a&#64374;&#525;
		pageWidthJg:2,//&#3333;Žß&#1203;aÙ²ÁÙ©£&#45898;		pageHeightJg:100,//&#3333;Žß&#1203;aàÇ&#64836;&#51512;ÏÀ+
		startline:30,//&#15759;&#1467;&#1589;&#56741;&#12272;&#16741;ÔÜÑÄ&#821;scrollTop©£&#45898;		duration:200,//&#46645;&#56741;&#12277;&#267;&#1654;&#522;&#7972;
		targetObg:"body"//&#319;&#6798;&#46467;
	};
})(jQuery);
$(function(){
	$('<a href="javascript:;" class="backToTop" title="½ƒ&#1590;¿ù">½ƒ&#1590;¿ù</a>').appendTo("body");
});