/*
banner_button.js
*/
function ButtonMovement (id) {
	this.id = id;
	this.stillmoving = false
	this.lastmovement = "";
	this.skipframe = 8;
	this.skiptime = 30;
	this.currentTop = 0;
	this.objHeight = 0;
	
	var _self;
	
	this.getObjHeight = function() {
		this.objHeight = this.removepx(document.getElementById(this.id).style.height);	
	}
	
	this.btnMoveUp = function() {	
		if (this.stillmoving) {
			this.lastmovement = "up";
		} else {
			this.movebtnup();
		}		
	}
	
	this.btnMoveDown = function() {
		if (this.stillmoving) {
			this.lastmovement = "down";
		} else {
			this.movebtndown();
		}		
	}
	
	this.removepx = function(str) {
		var pxSeparator = str.indexOf("px");
		return (parseInt(str.substring(0,pxSeparator)));
	}
	
	this.movebtnup = function() {
		var _self = this;
		var top = this.currentTop - this.skipframe;
		if (top >= -1 * this.objHeight) {
			this.stillmoving = true;
			if (top < -1 * this.objHeight) top = -1 * this.objHeight;
			this.currentTop = top;
			document.getElementById(this.id).style.top	= top + "px";	
			setTimeout(function(){_self.movebtnup();},this.skiptime);
		} else {
			this.stillmoving = false;
			if (this.lastmovement == "up") this.lastmovement = "";
			if (this.lastmovement == "down") this.btnMoveDown();
		}
	}	

	this.movebtndown = function () {
		var _self = this;
		var top = this.currentTop + this.skipframe;
		if (top <= 0) {
			this.stillmoving = true;
			if (top > 0) top = 0;
			this.currentTop = top 
			document.getElementById(this.id).style.top	= top + "px";	
			setTimeout(function(){_self.movebtndown();},this.skiptime);
		} else {
			this.stillmoving = false;
			if (this.lastmovement == "down") this.lastmovement = "";
			if (this.lastmovement == "up") this.btnMoveUp();
		}
	}	
}

var bm = new Array();

function bmUp(id) {
	if (typeof bm[id] == "undefined") {
		bm[id] = new ButtonMovement("btn"+id);
		bm[id].getObjHeight();
	}
	bm[id].btnMoveUp();
}

function bmDown(id) {
	if (typeof bm[id] == "undefined") {
		bm[id] = new ButtonMovement("btn"+id);
		bm[id].getObjHeight();
	}	
	bm[id].btnMoveDown();
}

function bmClick(id) {
	window.location.href = location_index[id];
}