/**
 * @author Andreas Wiemer
 */
function positioner(obj, start_x, start_y, step, pause) {
	this.parent = obj;
	this.timeout = false;
	this.move = move;
	this.pause = pause;
	this.step = step;
	this.step_x = step;
	this.step_y = step;
	this.move_to = move_to;
	this.set_position = set_position;
	this.x = start_x;
	this.y = start_y;
	this.set_position();
}

function set_position() {
	set_style_value(this.parent.obj_id, 'top', this.y + "px");
	set_style_value(this.parent.obj_id, 'left', this.x + "px");
}

function move_to(x, y, style) {
	var diff_x, diff_y;
	this.move_to_x = x;
	this.move_to_y = y;
	if(!isNull(style)) {
		if(style=="prozentual") {
			diff_x = Math.abs(this.x - this.move_to_x);
    		diff_y = Math.abs(this.y - this.move_to_y);
    		this.step_x = diff_x / 100 * this.step;
			this.step_y = diff_y / 100 * this.step;
		}
	} else { // style=="absolute" || null
		this.step_x = this.step;
		this.step_y = this.step;
	}
	this.move();
}

function move() {
    var step_x, step_y, diff_x, diff_y, next;
	var self;
    diff_x = Math.abs(this.x - this.move_to_x);
    diff_y = Math.abs(this.y - this.move_to_y);
	if(diff_x > this.step_x  / 2 || diff_y > this.step_y / 2) {
		if (!wait) {
			step_x = (diff_x > this.step_x) ? this.step_x : diff_x;
			step_y = (diff_y > this.step_y) ? this.step_y : diff_y;
			this.x += (this.move_to_x > this.x) ? step_x : -step_x;
			this.y += (this.move_to_y > this.y) ? step_y : -step_y;
			this.set_position(this.x, this.y);
		}
		self = this;
		if (!this.timeout) {
			this.timeout = setInterval(
				function() {
					self.move();
				}, this.pause
			);
		}
		return true;
   	}
    window.clearInterval(this.timeout);
    this.timeout = false;
	return false;
}