// JavaScript Document
// float ad javascript
var MoveAd = MoveAd || {
	
	width : 100,
	marginTop : 40, 
	marginLeft : 1,
	frequency : 30,
	speed : 8,
	elementL : null,
	elementR : null,
	hanle : null, 

	init : function(adLeftId, adRightId, width){
		if(width = parseInt(width)){
			this.width = width;
		}
		this.elementL = this.initElement(adLeftId);
		this.elementR = this.initElement(adRightId, 1);
	},
	
	initElement : function(elementId, type){
		var element, position, stype = typeof(elementId);
		if((stype != "object") && (stype == "string")){
			element = document.getElementById(elementId);
		}
		if(typeof(element) != "object" || element == null){
			return null;
		}
		position = (type == 1) ? "right" : "left";
		with(element){
			style.position = 'absolute';
			style.width = this.width;
			style.top = this.marginTop + 'px';
			//eval("style." + position + ' = this.marginLeft');
            if(position == 'right'){
                this.marginLeft += 100;
            }
            style[position] = this.marginLeft + 'px';

			style.textAlign = position;
		}
		element.y = this.marginTop;
		return element;
	},
	
	start : function (){
		if(this.elementL){
			this.setTop(this.elementL);
		}
		if(this.elementR){
			this.setTop(this.elementR);
		}
		this.hanle = setTimeout("MoveAd.start();", this.frequency);
	},
	
	setTop : function(element){
		var top = document.body.scrollTop 
			? document.body.scrollTop 
			: document.documentElement.scrollTop;
		var step = (top + this.marginTop - element.y)/this.speed;
		if(Math.abs(step) > 0.1){
			element.y += step;
			element.style.top = element.y + 'px';
		}
		//window.status = element.y;
	}
}

