;(function($){
	$.viewport=function(){
		var w = (window.innerWidth) ? window.innerWidth : (document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.offsetWidth;
		var h = (window.innerHeight) ? window.innerHeight : (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.offsetHeight;
		return {width:w,height:h};
	}
	$.fn.floatAD=function(options){
		var self=$(this);
		var settings=$.extend({},$.floatAD.defaults,options);
		var pos=getPosition();
		var ie=$.browser.msie;
		var ie7=ie&&($.browser.version<=7.0);
		self.css({position:"absolute","z-index":"300",left:pos.left,top:pos.top});
		function getPosition(){
			var cw=$.viewport().width;
			var ch=$.viewport().height;
			var st=$(document).scrollTop();
			var sl=$(document).scrollLeft();
			var w=self.width();
			var h=self.height();
			var pos={};
			var ml=(cw-$("body").width())/2;
			pos.left=settings.left?sl+settings.left:sl+cw-w-settings.right;
			pos.left=ie7?pos.left-ml:ie?pos.left:pos.left-16;
			pos.top=settings.top?st+settings.top:st+ch-h-settings.bottom;
			
			return pos;
		}
		function setPostion(){
			var pos=getPosition();
			self.animate({left:pos.left,top:pos.top},settings.delay,"swing",function(){
				setPostion();	
			});
		}
		setPostion();
		return self;
	}
	$.floatAD={
		defaults:{
			bottom:0,
			right:0,
			delay:30
		}	
	}
})(jQuery);
$(function(){
	var float=$("#floatQQ"),shrink=$("#floatQQ-shrink"),floatWidth=float.width(),floatHeight=float.height(),shrinkWidth=shrink.width();
	$("#floatQQ-container").css({"width":floatWidth,"height":floatHeight,"visibility":"visible"}).floatAD({top:100,right:0,delay:300});
	shrink.css("display","block").animate({"margin-right":0},100,"swing");
	float.find("h3 span").click(function(){
		float.animate({"margin-right":"-"+floatWidth},100,"swing",function(){
			shrink.css("display","block");
			shrink.animate({"margin-right":0},100,"swing");
		});
	});
	shrink.click(function(){
		shrink.animate({"margin-right":"-"+(shrinkWidth+floatWidth)},100,"swing",function(){
			shrink.css("display","none");
			float.animate({"margin-right":0},100,"swing");
		});
	});
})
