// Made by Gaurav Mogre, aka Silver.
//Use as directed in html... Usually no need to change this file.
// Requires mootools
	var Movements=new Class({
		//Constructor
		initialize:function(areas,delay,center,divid,markid){
			this.delay=delay;
			this.center=center;
			this.bgdiv=$(divid);
			this.marker=$(markid);
			this.anime=new Fx.Styles(this.marker,{wait: false, duration: this.delay, transition: Fx.Transitions.Quad.easeOut});
			this.bgdiv.addEvent('click',function(ev){ this.clicked(ev); }.bind(this));
			this.oldx=this.bgdiv.getPosition().x;
			this.oldy=this.bgdiv.getPosition().y
			//The oldx and oldy are the current position of the marker.
			//To correctly set the marker now.
			this.marker.setStyle('left',this.oldx);
			this.marker.setStyle('top',this.oldy);
			this.areas=areas;
			for(var i=0;i<this.areas.length;i++){
				this.areas[i].x1+=this.oldx;
				this.areas[i].x2+=this.oldx;
				this.areas[i].y1+=this.oldy;
				this.areas[i].y2+=this.oldy;
			}
			//Get the size of the marker.. required for center positioning
			var markercoords=this.marker.getCoordinates();
			this.markerdim={ width: markercoords.width, height: markercoords.height };
		},
		//Called when the div is clicked on
		clicked:function(ev){
			//Called when clicked
			var clickEvent=new Event(ev);
			var x=clickEvent.page.x;
			var y=clickEvent.page.y;
			if(this.center){
				this.anime.start({'left': [this.oldx, x-(this.markerdim.width/2)],'top': [this.oldy, y-(this.markerdim.height/2)]});
				this.oldx=x-(this.markerdim.width/2);
				this.oldy=y-(this.markerdim.height/2);
			}
			else{
				this.anime.start({'left': [this.oldx, x],'top': [this.oldy, y]});
				this.oldx=x;
				this.oldy=y;
			}
			
			//Check if clicked inside the area:
			for(var i=0;i<this.areas.length;i++){
				if(this.areas[i].x1<x&&x<this.areas[i].x2&&this.areas[i].y1<y&&y<this.areas[i].y2){
					var replacefunc=function(par){ self.location.href=par.parent.areas[par.i].href; }.bind(this);
					replacefunc.delay(this.delay,this,{parent: this,i: i});
				}
			}
		}
	});
