
var pb_animation_ParallaxNode = Class.create(pb_core_Node,{
	
	minDepth: 0,
	maxDepth: 24,
	originX: 0,
	originY: 0,
	
	ParallaxNode: function(identifier){
		this.Node(identifier);

		var resizeAction = this.resizeEvent.bind(this);
		var scrollAction = this.scrollEvent.bind(this);
		
		this.originX = this.htmlContainer.offsetLeft;
		this.originY = this.htmlContainer.offsetTop;
		
		Event.observe(document.onresize ? document : window, "resize", resizeAction);
		Event.observe(window, "scroll", scrollAction);
		
	},
	
	initialize: function(identifier){
		this.ParallaxNode(identifier);
	},

	resizeEvent: function(event){
		
	},
	
	
	scrollEvent: function(event){
		var posX = (document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : window.pageXOffset;
    	var posY = (document.documentElement.scrollTop) ? document.documentElement.scrollTop : window.pageYOffset;

		var left = this.htmlContainer.offsetLeft;
		var top = this.htmlContainer.offsetTop;
		var zIndex = (this.htmlContainer.style.zIndex)||0;
		
		var xParallax = this.calculateXParallax(posX,left,zIndex);
		var yParallax = this.calculateYParallax(posY,top,zIndex);
		
		
		var duration = Math.abs(1/(top-yParallax));
		
		new Effect.Move(this.htmlContainer, { x: left,y: yParallax, mode: 'absolute', duration: duration });
		
		//if (xParallax!=left) this.htmlContainer.style.left = xParallax + 'px';
		// if (yParallax!=top) {
		// 		//this.htmlContainer.style.top = yParallax + 'px';
		// 		//this.htmlContainer.childNodes[0].style.backgroundPosition = '0 0';
		// 	}
	},
	
	calculateXParallax: function(scroll,pos,zIndex){
		return this.originX;
	},

	calculateYParallax: function(scroll,pos,zIndex){
		return parseInt(this.originY + scroll*((12-zIndex)/12));
		
		//return parseInt(this.originY + scroll);

		// scroll=0 -> this.originY
				
		// zIndex=0		-> scroll
		// zIndex=12	-> 0
		// zIndex=24	-> -scroll
		
	}
	
}); // pb_animation_ParallaxNode