//Parallax
function parallax(container,objects,speed,invert,ballance){
	var objects = $$(objects);
	var container = $(container);
	var containerD = container.getCoordinates();
	var centerx = (containerD.width/2)+containerD.left;
	var centery = (containerD.height/2)+containerD.top;
	var xx = centerx;
	var yy = centery;
	var zx = [xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx+1];
	var zy = [yy,yy,yy,yy,yy,yy,yy,yy,yy,yy,yy,yy,yy,yy,yy,yy,yy,yy,yy,yy+1];

	function mouseX(evt) {if (!evt) evt = window.event; if (evt.pageX) return evt.pageX; else if (evt.clientX)return evt.clientX + (document.documentElement.scrollLeft ?  document.documentElement.scrollLeft : document.body.scrollLeft); else return 0;}
	function mouseY(evt) {if (!evt) evt = window.event; if (evt.pageY) return evt.pageY; else if (evt.clientY)return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop); else return 0;}

	function windowPosition() {
		var centerx = (window.getWidth()/2);
		var centery = ((window.getScrollTop()+window.getHeight())/2);
	}

	function followLocation(evt) {
		xx = parseInt(mouseX(evt));
		yy = parseInt(mouseY(evt));
	}

	function followDelay() {
		if(xx!=Math.round(zx[19])||yy!=Math.round(zy[19])){
		zx.each(function(item, index){
			if(index<1){
				zx[index] = xx;
				zy[index] = yy;
			}else{
				zx[index] = (zx[index]+=(zx[index-1]-zx[index])*speed);
				zy[index] = (zy[index]+=(zy[index-1]-zy[index])*speed);
			}
		});
		objects.each(function(item, index){
			item.set({'styles': {'left': ((centerx - Math.round(zx[19]))*(invert*item.get('title'))*(2-ballance)) + centerx + 'px','top': ((centery - Math.round(zy[19]))*(invert*item.get('title'))*(ballance)) + centery + 'px'}});
		});
		}
	}
	container.onmousemove = followLocation;
	window.onresize = windowPosition;
	var interval = followDelay.periodical(50);
}

//Rotator
var Rotater=new Class({Implements:[Options,Events],options:{slideInterval:4000,transitionDuration:1000,startIndex:0,autoplay:true},initialize:function(B,A){this.setOptions(A);this.slides=$$(B);this.createFx();this.showSlide(this.options.startIndex);if(this.slides.length<2){this.options.autoplay=false}if(this.options.autoplay){this.autoplay()}return this},toElement:function(){return this.container},createFx:function(){if(!this.slideFx){this.slideFx=new Fx.Elements(this.slides,{duration:this.options.transitionDuration})}this.slides.each(function(A){A.setStyle("opacity",0)})},showSlide:function(B){var A={};this.slides.each(function(C,D){if(D==B&&D!=this.currentSlide){A[D.toString()]={opacity:1}}else{A[D.toString()]={opacity:0}}},this);this.fireEvent("onShowSlide",B);this.currentSlide=B;this.slideFx.start(A);return this},autoplay:function(){this.slideshowInt=this.rotate.periodical(this.options.slideInterval,this);this.fireEvent("onAutoPlay");return this},stop:function(){$clear(this.slideshowInt);this.fireEvent("onStop");return this},rotate:function(){current=this.currentSlide;next=(current+1>=this.slides.length)?0:current+1;this.showSlide(next);this.fireEvent("onRotate",next);return this}});

//Calls
window.addEvent('domready', function(){

			var rotater = new Rotater('.slidesh',{ 		//Class of elements that should rotate.
				slideInterval:3000, 					//Length of showing each element, in milliseconds
				transitionDuration:2000 				//Length crossfading transition, in milliseconds
			});
	//Top Menu Slide
	$('menu').addEvents({
		'mouseenter': function(){
			// Always sets the duration of the tween to 1000 ms and a bouncing transition
			// And then tweens the height of the element
			this.set('tween', {
				duration: 1000,
				transition: Fx.Transitions.Bounce.easeOut // This could have been also 'bounce:out'
			}).tween('width', '800px');
		},
		'mouseleave': function(){
			// Resets the tween and changes the element back to its original size
			this.set('tween', {}).tween('width', '60px');
		}
	});	
	
	//Parallax
	
});
