jQuery(function($){
	$.fn.floatADV = function(options){
		var obj = this;
		var interval = null;
		//Ä¬ÈÏÉèÖÃ
		var setting = {
			delay : 30,
			step : 1,
			xPos : 0,
			yPos : 0,
			x : rand(0, 1),
			y : rand(0, 1)
		};
		if (options) $.extend(setting, options);
		if (!setting.xPos) setting.xPos = rand($(window).scrollLeft(), $(window).width() - $(obj).outerWidth(true));
		if (!setting.yPos) setting.yPos = rand($(window).scrollTop(), $(window).height() - $(obj).outerHeight(true));
		setting.xPos = parseInt(setting.xPos);
		setting.yPos = parseInt(setting.yPos);
		$(obj).css({left:setting.xPos, top:setting.yPos});
		function rand(min, max) {
			return Math.floor(Math.random() * (max - min + 1)) + min;
		}
		function start(){
			if (setting.x){
				setting.xPos += setting.step;
			} else {
				setting.xPos -= setting.step;
			}
				$(obj).css("left", setting.xPos + $(window).scrollLeft());
			if (setting.y){
				setting.yPos += setting.step;
			} else {
				setting.yPos -= setting.step;
			}
				$(obj).css("top", setting.yPos + $(window).scrollTop());
			if ($(obj).position().left >= ($(window).width() - $(obj).outerWidth(true) + $(window).scrollLeft())) setting.x = 0;
			if ($(obj).position().left <= 0 + $(window).scrollLeft()) setting.x = 1;
			if ($(obj).position().top >= ($(window).height() - $(obj).outerHeight(true) + $(window).scrollTop())) setting.y = 0;
			if ($(obj).position().top <= 0 + $(window).scrollTop()) setting.y = 1;
		}
		
		function stop(){
			
		}
		
		this.hover(function(){
			if (interval) clearInterval(interval);
			interval = null;
			$("<div />").attr("id","floatAdv_close").css({"position":"absolute", "width":$(this).width(), "left":0, "top":0, "z-index":"20"}).append("<span style=\"margin: 6px 5px; float: right; clear: none; width: 11px; height: 11px;\"><img src=\"../images/layout/tab-close.gif\" width=\"11\" height=\"11\" border=\"0\" style=\"background-color:#FFF\" /></span>").find("img").hover(function(){
				$(this).attr("src", "http://excaliburhk.gicp.net/images/layout/tab-close-on.gif");
			}, function(){
				$(this).attr("src", "http://excaliburhk.gicp.net/images/layout/tab-close.gif");
			}).click(function(){
				$(obj).remove();
			}).end().appendTo(this);
		}, function(){
			$("div[id=floatAdv_close]", this).remove();
			interval = setInterval(start, setting.delay);
		});
		interval = setInterval(start, setting.delay);
		return this;
	};
});