
var CRingSelector = new Class({
	//
	// Constructor
	//
	initialize : function() {	
		var self = this;
		this.Pi = 3.14159;
		this.LastRing = -1;
		
		this.SetRingInformation = [
			{ "OuterRadius" : 55, "Picture" : "LeistungenE_r0.jpg", "index" : 16 },
			{ "OuterRadius" : 93, "Picture" : "LeistungenE_r1.jpg", "index" : 15 },
			{ "OuterRadius" : 133, "Picture" : "LeistungenE_r2.jpg", "index" : 14 }
		];
		
		window.addEvent("load", this.setup.bindAsEventListener(this));
	}, 
	
	//
	// after Load Initialisierung
	//
	setup : function() {
		var self = this;
		
		this.RingElement = null;
		
		var ImgList = $$("img");
		$each(ImgList, function(itm, idx, obj) {
			if ( self.RingElement != null ) return;
			if ( itm.src.search(/LeistungenE[\w\d_]*.jpg$/) > -1 ) {
				self.RingElement = itm;
				return;
			}
		});
		
		if ( this.RingElement == null ) return;
		
		this.RingDefaultPicture = this.RingElement.src; 
		$each( this.SetRingInformation, function(itm,idx,obj) {
			new Image(1,1).src = self.RingDefaultPicture.replace(/\/[\w\d_]*\.[\w]*$/, "/" + itm.Picture);
		});
		
		var Size = this.RingElement.getSize();
		
		this.RingPosition = this.RingElement.getPosition();
		this.RingMiddlePoint = {
			"width"	: Size.size.x / 2,
			"height"	: Size.size.y / 2
		};
		
		this.RingElement.addEvent("mouseover", this.mouseOver.bindWithEvent(this));
		this.RingElement.addEvent("mousemove", this.mouseMove.bindWithEvent(this));
		this.RingElement.addEvent("click", this.mouseClick.bindWithEvent(this));
	},

	getRing : function( r ) {
		for (i=0; i < this.SetRingInformation.length; i++ ) {
			if ( r < this.SetRingInformation[i].OuterRadius ) return i;
		}
		
		return -1;		
	},
	
	mouseClick : function(e) {
		var evt = new Event(e);
		evt.stop();
		
		window.location.href="index.php?id=" + this.SetRingInformation[ this.LastRing ].index + "&L=1";
	},
	
	//
	//
	//
	mouseMove : function(e) {
		var evt = new Event(e);
		
		var NullPunkt = {
			"x"	: this.RingPosition.x + this.RingMiddlePoint.width, 
			"y" : this.RingPosition.y + this.RingMiddlePoint.height
		};
		
		var a = (evt.page.x - NullPunkt.x);
		var b = (evt.page.y - NullPunkt.y);
		
		var t = -1;
		
		var r = Math.sqrt((a*a) + (b*b));
		var ring = this.getRing(r);

		if ( this.LastRing != ring ) {
			if ( ring == -1 ) {
				this.RingElement.src = this.RingDefaultPicture;
			} else {
				this.RingElement.src = this.RingElement.src.replace(/\/[\w\d_]*\.[\w]*$/, "/"+this.SetRingInformation[ring].Picture);
			}
			this.LastRing = ring;
		}
		
		evt.stop();
	},
	
	//
	// mouseOverfunction
	//
	mouseOver : function(e) {
		var evt = new Event(e);
		evt.stop();
	}
});

// Events addieren
CRingSelector.implement(new Events);

var RingSelector = new CRingSelector();
