(function(window){

function Position(){
	this.initialize.apply(this,arguments);
}
var p = Position.prototype;
	p.itemAry = null;
	p.initialize = function(){
		this.itemAry = [];
	}
	p.scroll = function(value){
		var l = this.itemAry.length;
		for(var i = 0; i < l ; i++)
		{
			 this.itemAry[i].setPosition(value);
		}
	}
	p.add = function(element,rate,limit)
	{
		this.itemAry.push(new Item(element,rate,limit));
	}

function Item(){
	this.initialize.apply(this,arguments);
}
var p = Item.prototype;
	p.element = null;
	p.rate = 0;
	p.baseTop = 0;
	p.min = 0;
	p.max = 0;

	p.initialize = function(element,rate,limit)
	{
		this.min = limit[0];
		this.max = limit[1];
		this.element = element;
		this.rate = rate;
		this.baseTop = parseInt(this.element.offsetTop);
	}
	p.setPosition = function(to){
		//var value = (to - this.baseTop + getWindowSize().height/2) * (1-this.rate);
		var value = (to - this.baseTop ) * (1-this.rate);
		
		value = Math.min(this.max,value);
		value = Math.max(this.min,value);
		this.element.style.top = value + "px";
	}

function getWindowSize(){
	var size = {width:0,height:0};
	if ( window.innerWidth ) {
		size.width = window.innerWidth;
		size.height = window.innerHeight;
	}
	else if ( document.documentElement && document.documentElement.clientWidth != 0 ) {
		size.width = document.documentElement.clientWidth;
		size.height = document.documentElement.clientHeight;
	}
	else if ( document.body ) {
		size.width = document.body.clientWidth;
		size.height = document.body.clientHeight;
	}
	return size;
}

window.Position = Position;

}(window))
