﻿/***7
 *	RBM (Right Bottom Move)
 *	Created by Moky @ 2006/12/14;
 */
RBM_sImageName		= "addedvalueservices.gif";
RBM_sClickUrl		= "https://member.yong-online.com.tw/AddedValueServices/index.aspx";
RBM_sImageUrl		= "/img/addedvalueservices.gif";
RBM_iImageWidth		= parseInt("$width$");
if (isNaN(RBM_iImageWidth)) RBM_iImageWidth = 100;
RBM_iImageHeight	= parseInt("$height$");
if (isNaN(RBM_iImageHeight)) RBM_iImageHeight = 125;
RBM_iRight = 10;
RBM_iBottom = 10;
RBM_iMinTop = 335;	/* avoid conflicts with double images */
RBM_iTimeout = 50;
/*---- common codes begin ----*/
var __bs__ = navigator.userAgent.indexOf("MSIE") > 0 ?
	"MSIE" : navigator.userAgent.indexOf("Safari") > 0 ?
	"Safari" : "others";
var __dt__ = (document.documentElement.clientHeight > 0) &&
	(__bs__ == "MSIE" || document.body.clientHeight > document.documentElement.clientHeight) ?
	"W3C" : "undefined";
function MK_pageY() {
	if (__bs__ == "MSIE") {
		if (__dt__ == "W3C")
			return document.documentElement.scrollTop;
		else
			return document.body.scrollTop;
	} else {
		return window.pageYOffset;
	}
}
function MK_pageX() {
	if (__bs__ == "MSIE") {
		if (__dt__ == "W3C")
			return document.documentElement.scrollLeft;
		else
			return document.body.scrollLeft;
	} else {
		return window.pageXOffset;
	}
}
function MK_pageH() {
	if (__bs__ == "Safari")
		return window.innerHeight;
	else if (__dt__ == "W3C")
		return document.documentElement.clientHeight;
	else
		return document.body.clientHeight;
}
function MK_pageW() {
	if (__bs__ == "Safari")
		return window.innerWidth;
	else if (__dt__ == "W3C")
		return document.documentElement.clientWidth;
	else
		return document.body.clientWidth;
}
function MK_posY(o, v) {
	if (!o || !o.style) return ;
	if (v) {
		o.style.top = parseInt(v) + "px";
	} else {
		return o.style.top;
	}
}
function MK_posX(o, v) {
	if (!o || !o.style) return ;
	if (v) {
		o.style.left = parseInt(v) + "px";
	} else {
		return o.style.left;
	}
}
function MK_makeAdFodderHTML(sImageUrl, sImageName, iWidth, iHeight) {
	var _src = sImageUrl == "" ? sImageName : sImageUrl;
	return (!_src.match(/\.swf$/gi)? '<img src="$src$" mce_src="$src$" height="$height$" width="$width$" border="0" />' :
		'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' +
		' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0"' +
		' height="$height$" width="$width$">\n' +
		'<param name="movie" value="$src$" />\n' +
		'<param name="quality" value="high" />\n' +
		'<param name="wmode" value="opaque" />\n' +
		'<embed height="$height$" width="$width$"' +
		' src="$src$" mce_src="$src$" quality="high" wmode="opaque"' +
		' type="application/x-shockwave-flash" pluginspace="http://www.macromedia.com/go/getflashplayer">' +
		'</embed>' +
		'</object>')
	.replace(/\$src\$/gi, _src).replace(/\$height\$/gi, iHeight).replace(/\$width\$/gi, iWidth);
}
function atoi(s) {
	var r = parseInt(s);
	return isNaN(r) ? 0 : r;
}
function magic_locus(x1, x2, n) {
	x1 = atoi(x1);
	x2 = atoi(x2);
	n = atoi(n);
	var d = Math.abs(x1 - x2);
	if (d < n) return magic_locus(x1, x2, d / 2);
	return n <= 1 ? x1 : (x1 + (n-1) * x2) / n ;
}
/*---- common codes end ----*/
function RBM_Load() {
	var style_class ;
/*	try {
		if (__bs__ == "MSIE")
			document.styleSheets[0].addRule('.div_floating_ad', 'position:absolute');
		else
			document.styleSheets[0].insertRule('.div_floating_ad {position:absolute}', document.styleSheets[0].cssRules.length);
		style_class = 'class="div_floating_ad"';
	} catch(e) {*/
		style_class = 'style="position: absolute; "';
/*	}*/
	var _temp = '<div id="RBM_Div" ' + style_class + '>' +
		'<a href="$js_ad_click$" mce_href="$js_ad_click$" target="_blank">$js_ad_content$</a>' +
		'</div>';
	var _con = MK_makeAdFodderHTML(RBM_sImageUrl, RBM_sImageName, RBM_iImageWidth, RBM_iImageHeight);
	var _str = _temp.replace(/\$js_ad_click\$/gi, RBM_sClickUrl).replace(/\$js_ad_content\$/gi, _con);
	document.writeln(_str);
	setInterval("RBM_Move();", RBM_iTimeout);
}
function RBM_Move() {
	try {
		var _div = document.getElementById('RBM_Div');
		
		var _left = MK_pageX() + MK_pageW() - RBM_iRight - RBM_iImageWidth;
		var _top = MK_pageY() + MK_pageH() - RBM_iBottom - RBM_iImageHeight;
		/*-- magic locus begin, add by moky @ 2006/12/29 --*/
		_top = magic_locus(_top, MK_posY(_div), 4);
		var max_y = MK_pageY() + MK_pageH();
		if (_top > max_y) _top = max_y;
		/*-- magic locus end,   add by moky @ 2006/12/29 --*/
		if (_top < RBM_iMinTop) _top = RBM_iMinTop;
		
		MK_posY(_div, _top);
		MK_posX(_div, _left);
	} catch(e) {}
}
/* start */
RBM_Load();
