function mImage(container,imageid,imagetype,callaftercrop,showwhilewaiting){
	var self = this;
	
	this.container	= container;
	this.imageid	= imageid;
	this.imagetype	= imagetype;
	this.quarterturn = 0;
	this.imagearea = new Array(0,0,0,0);
	this.croparea = new Array(0,0,0,0);
	
	this.workingimageDimensions = new Object();
	this.workingimageDimensions.width=0;
	this.workingimageDimensions.height=0;
	
	this.doAction($H({'action':'init'}));
	this.callaftercrop = callaftercrop;
	this.showwhilewaiting = showwhilewaiting;
	this.cropper = null;
}

mImage.prototype.onEndCrop = function(coords, dimensions){
	this.croparea = new Array(coords.x1,coords.x2,coords.y1,coords.y2);
	if (typeof(this.callaftercrop)=='function'){
		this.callaftercrop.bind(this)(coords, dimensions);
	}
}

mImage.prototype.sucesshandler = function(callafter,transport){
	if( this.cropper != null ) {
		this.cropper.remove();
	}
	result = transport.responseText.evalJSON();
	if (result.fehler){
		alert(result.fehler);
	}else{
		// wenn vorheriges vorhanden -> entfernen
		$(result.container).update('');
		var workingimagecontainer = document.createElement('div');
		$(workingimagecontainer).setStyle(result.workingimagecontainerstyle);
		var workingimage = document.createElement('img');
		workingimage.width = result.workingimageDimensions.width;
		workingimage.height = result.workingimageDimensions.height;
		workingimage.src = '/images/working/' + this.imageid + '.jpg?zufall='+Math.floor(Math.random()*1000000);
		workingimagecontainer.appendChild(workingimage);
		$(result.container).appendChild(workingimagecontainer);		
		// init des croppers
		this.cropper = new Cropper.Img(
			$(workingimage),
			{
				minWidth: 10,
				minHeight: 10,
				ratioDim: {
					x: 927,
					y: 1200
				}
				,displayOnInit: true
				,onEndCrop : this.onEndCrop.bind(this)
			}
		);
		// und noch die Infos zum bild aktuallisieren
		this.quarterturn = result.quarterturn;
		this.imagearea = result.imagearea;
		this.actualimagesize = result.actualimagesize;
		this.workingimageDimensions = result.workingimageDimensions;
		if($(this.showwhilewaiting)){
			$(this.showwhilewaiting).style.display = 'none';
		}
		if (typeof(callafter) == 'function'){
			callafter()
		}
	}
}

mImage.prototype.doAction = function(additional,call_after,quality){
	new Ajax.Request(
		'/ajax.php',{
			method:'post',
			parameters : $H({
				'action'		: 'mImage',
				'container'		: this.container,
				'working_id'	: this.imageid,
				'working_type'	: this.imagetype,
				'quarterturn'	: this.quarterturn,
				'imagearea[]'	: this.imagearea,
				'croparea[]'	: this.croparea,
				'rand'			: Math.floor(Math.random()*1000000),// ich weiß, eklig - aber die einzige möglichkeit mit der ich mir sicher sein kann das immer neu geladen wird!
				'quality'		: (quality?quality:50)
			}).toQueryString()+
			'&'+
			additional.toQueryString(),
			onSuccess: this.sucesshandler.bind(this,call_after)
		}
	);
	
	if($(this.showwhilewaiting)){
		$(this.showwhilewaiting).style.display = 'block';
	}
	
}

mImage.prototype.reset = function(call_after,quality){
	this.doAction($H({'doaction':'reset'}),call_after,quality);
}

mImage.prototype.rotateleft = function(call_after,quality){
	this.doAction($H({'doaction':'rotateLeft'}),call_after,quality);
}
mImage.prototype.rotateright = function(call_after,quality){
	this.doAction($H({'doaction':'rotateRight'}),call_after,quality);
}

mImage.prototype.crop = function(call_after,quality){
	this.doAction($H({'doaction':'crop'}),call_after,quality);
}
