/**
 * 右下角广告
 * 
 * @author linxs@35.cn
 */
(function($) { 
	$.fn.cavanAdvertisement = function(o) {
		// 默认参数
		o = $.extend({
		}, o || {});
		
		// 插件扩展
		return this.each(function() {
			var div = $(this);
			var time = 10;
			var timer = setInterval(function() {play();}, time);
			
			div.fadeIn("fast").find("#webdiy_advercontrol a").bind("click", function() {
				clearInterval(timer);
				div.fadeOut("fast");
			});
			
			function play() {
				objX = document.documentElement.clientWidth - div.outerWidth(true) - 2;
				objY = document.documentElement.clientHeight - div.outerHeight(true) - 2;
				if (document.all) {
					scrollArray = $.getPageScroll();
					
					fromY = parseInt(div.css("top"), 10);
					toY = objY + scrollArray[1];
					if (isNaN(fromY) || fromY < 0) {
						fromY = toY;
					}
					offsetY = Math.ceil(Math.abs((toY - fromY)) / time);
					if (toY < fromY) {
						offsetY = -offsetY; 
					}
					div.css({"top": fromY + offsetY + "px", "left": objX + scrollArray[0] + "px"});
				} else {
					div.css({"position":"fixed",  "top":objY + "px", "left":objX + "px"});
				}
			}
		}); // end plugin
	};
})(jQuery);