// 按钮展开缩放
function ScrollValue(){
	
	if (document.body && document.body.scrollTop ){
		this.msg="body";
		this.scrollTop=document.body.scrollTop;
		this.scrollLeft=document.body.scrollLeft;
	}else if(document.documentElement && document.documentElement.scrollTop){
		this.msg="documentElement";
		this.scrollTop=document.documentElement.scrollTop;
		this.scrollLeft=document.documentElement.scrollLeft;
	}
	else{
		this.msg="none";
		this.scrollTop=0;
		this.scrollLeft=0;
	}

}

(function($){
$.fn.float = function(options){
	var defaults={
		time:500,
		animate:true,
		deviant:20,
		direction:"top"
	}
	options=$.extend(defaults,options);
	var timeOut;
	var obj=$(this);
	var cHeight=document.documentElement.clientHeight;
	var oHeight=obj.height();
	var temp=0;
	
	function dif(){
		obj.css("display","none");
		obj.stop(false,true);
		clearTimeout(timeOut);
		timeOut=setTimeout(show,1000);
	}

	function show(){
		sv=new ScrollValue();
		obj.css("top",sv.scrollTop+cHeight-oHeight);
		obj.fadeIn();

	}
		
	function move2(){
		sv=new ScrollValue();
		obj.stop(false,true);
		obj.animate({top:(options.deviant+sv.scrollTop+150)},options.time);
		timeOut=setTimeout(move2,options.time+200);
	}
	function move3(){
		sv=new ScrollValue();
		obj.stop(false,true);
		obj.animate({bottom:(options.deviant+sv.scrollTop)},options.time);
		timeOut=setTimeout(move2,options.time+200);
	}
	
	if(options.animate){
		
		switch(options.direction){
			case "top":
				move2();
			break;
			case "bottom":
				move3();
			break;
		}
		
	}else{
	
		switch(options.direction){
			case "top":
				$(window).scroll( function() {
					dif();
				});
			break;
			case "bottom":
				dif();
			break;
		}
		
	}
	
};
})(jQuery);
