	/**
	
		Copyright by Markus Funke
		
		If you want to use this script on your website, please ask me.
		I don't want to get money for that, but I just want to know who uses it and in what kind of way it is used.
		
	**/

	var editversion = false;
	var ieversion = false;

	var imageClass = 'marks-image';
	var imageMarkID = 'image-mark';
	var imageMarkClass = 'image-mark';
	var imageMarkHoverClass = 'image-mark-hover';
	var imageMarkSelectableClass = 'image-mark-selectable';
	var imageMarkSelectableHoverClass = 'image-mark-selectable-hover';
	
	var toolbarID = 'imagemark-toolbar';
	var toolbarClass = 'imagemark-toolbar';
	var toolbarAddClass = 'imagemark-add';
	var toolbarAddAltText = 'Markierung hinzufügen';
	var toolbarAddIcon = 'fileadmin/templates/img/mark-add.jpg';
	var toolbarAddIconGrey = 'fileadmin/templates/img/mark-add-grey';
	var toolbarEditClass = 'imagemark-edit';
	var toolbarEditAltText = 'Markierung ändern';
	var toolbarEditIcon = 'fileadmin/templates/img/mark-edit.jpg';
	var toolbarEditIconGrey = 'fileadmin/templates/img/mark-edit-grey.jpg';
	var toolbarDeleteClass = 'imagemark-delete';
	var toolbarDeleteAltText = 'Markierung löschen';
	var toolbarDeleteIcon = 'fileadmin/templates/img/mark-delete.jpg';
	var toolbarDeleteIconGrey = 'fileadmin/templates/img/mark-delete-grey.jpg';
	var toolbarHideClass = 'imagemark-hide';
	var toolbarHideAltText = 'Markierungen aus-/einblenden';
	var toolbarHideIcon = 'fileadmin/templates/img/mark-hide.jpg';
	var toolbarShowIcon = 'fileadmin/templates/img/mark-show.jpg';
	
	var markFormID = 'mark-form';
	var markFormClass = 'mark-form';
	var formTitleName = 'imagemark-title';
	var formTextName = 'imagemark-text';
	var formSubmitName = 'imagemark-submit';
	var formTitleClass = 'imagemark-input';
	var formTextClass = 'imagemark-textarea';
	var imageBoxID = imageClass + '-box';
	var imageBoxClass = imageClass + '-box';
	
	var JPEGHeaderNo = 8;
	var pathToPHP = '/fileadmin/templates/js/picmarks/';
	
	var notAllowedMsg = 'Diese Aktion ist angemeldeten Benutzern vorbehalten.';
	var deleteConfirmMsg = 'Wollen Sie diese Markierung wirklich löschen?';
	var markSaveErrorMsg = 'Die Markierungen konnten nicht gespeichert werden.';
	var labelTitle = 'Titel:';
	var labelText = 'Text:';
	var labelSave = 'Speichern';
	var labelCancel = 'Abbrechen';
	
	var feuserid = 0;
	var feusername = 0;
	var langcode = 'de';
	
	var imageBoxes = Array();
	var markCounter = Array();
	var imageObj = Array();
	
	function markImage(no, image) {
		this.no = no;
		this.markCounter = 0;
		this.boxID = imageBoxID + this.no;
		this.SboxID = '#' + this.boxID;
		this.boxClass = imageBoxClass;
		this.toolbarID = toolbarID + this.no;
		this.StoolbarID = '#' + this.toolbarID;
		this.markFormID = markFormID + this.no;
		this.SmarkFormID = '#' + this.markFormID;
		this.SFormTitle = this.SmarkFormID + ' .' + formTitleClass;
		this.SFormText = this.SmarkFormID + ' .' + formTextClass;
		this.image = image;
		this.mark = Array();
		this.actMark = 0;
		this.editActive = false;
		this.deleteActive = false;
		
		this.createWrapBox = function() {
			imageBox = document.createElement('div');
			imageBox.id = this.boxID;
			imageBox.className = this.boxClass;
			jQuery(this.image).wrap(imageBox);
		};
		
		this.addToolbar = function() {
			toolbarBox = document.createElement('div');
			toolbarBox.id = this.toolbarID;
			toolbarBox.className = toolbarClass;
			
			// make add-button
			toolbarAdd = document.createElement('img');
			toolbarAdd.id = toolbarAddClass + this.no;
			toolbarAdd.alt = toolbarAddAltText;
			toolbarAdd.title = toolbarAddAltText;
			toolbarAdd.className = toolbarAddClass;
			toolbarAdd.src = toolbarAddIcon;
			toolbarBox.appendChild(toolbarAdd);
			
			// make edit-button
			toolbarEdit = document.createElement('img');
			toolbarEdit.id = toolbarEditClass + this.no;
			toolbarEdit.alt = toolbarEditAltText;
			toolbarEdit.title = toolbarEditAltText;
			toolbarEdit.className = toolbarEditClass;
			toolbarEdit.src = toolbarEditIcon;
			toolbarBox.appendChild(toolbarEdit);
			
			// make delete-button
			toolbarDelete = document.createElement('img');
			toolbarDelete.id = toolbarDeleteClass + this.no;
			toolbarDelete.alt = toolbarDeleteAltText;
			toolbarDelete.title = toolbarDeleteAltText;
			toolbarDelete.className = toolbarDeleteClass;
			toolbarDelete.src = toolbarDeleteIcon;
			toolbarBox.appendChild(toolbarDelete);
			
			// make delete-button
			toolbarHide = document.createElement('img');
			toolbarHide.id = toolbarHideClass + this.no;
			toolbarHide.alt = toolbarHideAltText;
			toolbarHide.title = toolbarHideAltText;
			toolbarHide.className = toolbarHideClass;
			toolbarHide.src = toolbarHideIcon;
			toolbarBox.appendChild(toolbarHide);
			
			jQuery(this.SboxID).before(toolbarBox);
			
			this.activateToolbarButtonAdd();
			this.activateToolbarButtonEdit();
			this.activateToolbarButtonDelete();
			this.activateToolbarButtonHide();
		};
		
		this.activateToolbarButtonAdd = function() {
			if(editversion) {
				jQuery(this.StoolbarID+' .'+toolbarAddClass).click(function() { imageObj[this.id.replace(/.*([0-9]+)$/, '$1')].addNewMark(); });
				jQuery(this.StoolbarID+' .'+toolbarAddClass).attr('src', toolbarAddIcon);
			} else {
				jQuery(this.StoolbarID+' .'+toolbarAddClass).click(function() { alert(notAllowedMsg); });
				jQuery(this.StoolbarID+' .'+toolbarAddClass).attr('src', toolbarAddIconGrey);
			}
		};
		
		this.activateToolbarButtonEdit = function() {
			this.editActive = false;
			if(editversion) {
				jQuery(this.StoolbarID+' .'+toolbarEditClass).click(function() { imageObj[this.id.replace(/.*([0-9]+)$/, '$1')].onToolbarEditClick(); });
				jQuery(this.StoolbarID+' .'+toolbarEditClass).attr('src', toolbarEditIcon);
			} else {
				jQuery(this.StoolbarID+' .'+toolbarEditClass).click(function() { alert(notAllowedMsg); });
				jQuery(this.StoolbarID+' .'+toolbarEditClass).attr('src', toolbarEditIconGrey);
			}
		};
		
		this.activateToolbarButtonDelete = function() {
			this.deleteActive = false;
			if(editversion) {
				jQuery(this.StoolbarID+' .'+toolbarDeleteClass).click(function() { imageObj[this.id.replace(/.*([0-9]+)$/, '$1')].onToolbarDeleteClick(); });
				jQuery(this.StoolbarID+' .'+toolbarDeleteClass).attr('src', toolbarDeleteIcon);
			} else {
				jQuery(this.StoolbarID+' .'+toolbarDeleteClass).click(function() { alert(notAllowedMsg); });
				jQuery(this.StoolbarID+' .'+toolbarDeleteClass).attr('src', toolbarDeleteIconGrey);
			}
		};
		
		this.activateToolbarButtonHide = function() {
			jQuery(this.StoolbarID+' .'+toolbarHideClass).click(function() { imageObj[this.id.replace(/.*([0-9]+)$/, '$1')].hideMarks(); });
			jQuery(this.StoolbarID+' .'+toolbarHideClass).attr('src', toolbarHideIcon);
		};
		
		this.deactivateToolbarButtonAdd = function() {
			jQuery(this.StoolbarID+' .'+toolbarAddClass).unbind('click');
			jQuery(this.StoolbarID+' .'+toolbarAddClass).attr('src', toolbarAddIconGrey);
		};
		
		this.deactivateToolbarButtonEdit = function() {
			jQuery(this.StoolbarID+' .'+toolbarEditClass).unbind('click');
			jQuery(this.StoolbarID+' .'+toolbarEditClass).attr('src', toolbarEditIconGrey);
		};
		
		this.deactivateToolbarButtonDelete = function() {
			jQuery(this.StoolbarID+' .'+toolbarDeleteClass).unbind('click');
			jQuery(this.StoolbarID+' .'+toolbarDeleteClass).attr('src', toolbarDeleteIconGrey);
		};
		
		this.deactivateToolbarButtonHide = function() {
			jQuery(this.StoolbarID+' .'+toolbarHideClass).unbind('click');
// 			jQuery(this.StoolbarID+' .'+toolbarHideClass).attr('src', toolbarHideIconGrey);
		};
		
		this.addMark = function(top, left, width, height, title, text, creator, creatorName, createdon, editor, editorName, editedon) {
			this.markCounter = this.markCounter + 1;
			this.mark[this.markCounter] = new mark(this.markCounter, this, top, left, width, height, title, text, creator, creatorName, createdon, editor, editorName, editedon);
		};
		
		this.addNewMark = function() {
			this.markCounter = this.markCounter + 1;
			this.mark[this.markCounter] = new mark(this.markCounter, this);
			this.mark[this.markCounter].activate();
			this.deactivateToolbarButtonAdd();
			this.deactivateToolbarButtonEdit();
			this.deactivateToolbarButtonDelete();
			this.deactivateToolbarButtonHide();
		};
		
		this.saveMarks = function() {
			var xml = '';
			for(var i=1;i<this.mark.length;i++) {
				if(this.mark[i] != 0) {
					xml += this.mark[i].getXML();
				}
			}
			jQuery.post(pathToPHP+'saveHeader.php', { lang: langcode, headerNo: JPEGHeaderNo, imagePath: this.image.src, headerContent: xml }, function(data) { if(data != '1') { alert(markSaveErrorMsg); } });
		};
		
		this.importMarks = function() {
			jQuery.post(pathToPHP+'readHeader.php', { lang: langcode, imageNo: this.no, headerNo: JPEGHeaderNo, imagePath: this.image.src }, function(data) { var resultArray = data.split('|||'); imageObj[resultArray[0]].doImportMarks(resultArray[1]); });
		};
		
		this.doImportMarks = function(data) {
			if(!ieversion) {
		
				// Firefox-Version
				jQuery(data).find('mark').each(function() {
					var markItem = jQuery(this);
					var markImageObj = imageObj[markItem.attr('imageno')];
					var markCreator = markItem.find('creator').text();
					if(markCreator == feuserid) {
						var markCreatorName = feusername;
					} else {
						var markCreatorName = markItem.find('creatorname').text();
					}
					var markEditor = markItem.find('editor').text();
					if(markEditor == feuserid) {
						var markEditorName = feusername;
					} else {
						var markEditorName = markItem.find('editorname').text();
					}
					markImageObj.addMark(markItem.attr('top'), markItem.attr('left'), markItem.attr('width'), markItem.attr('height'), markItem.find('title').text(), markItem.find('text').text(), markCreator, markCreatorName, markItem.find('createdon').text(), markEditor, markEditorName, markItem.find('editedon').text());
					var markObj = markImageObj.mark[markImageObj.markCounter];
					markObj.isNew = false;
				});
				
			} else {
			
				// IE-Version
				var markItems = data.match(/<mark ([^<>]*)>(.*?)<\/mark>/g);
				
				if(markItems) {
					for(var j=0; j<markItems.length;j++) {
						var markItem = markItems[j].match(/<mark ([^<>]*)>(.*?)<\/mark>/);
						
						var markAttributes = markItem[1];
						var markNo = markAttributes.match(/no="([0-9]+)"/)[1];
						var markImageNo = markAttributes.match(/imageno="([0-9]+)"/)[1];
						var markTop = markAttributes.match(/top="([0-9]+)"/)[1];
						var markLeft = markAttributes.match(/left="([0-9]+)"/)[1];
						var markWidth = markAttributes.match(/width="([0-9]+)"/)[1];
						var markHeight = markAttributes.match(/height="([0-9]+)"/)[1];
						
						var markNodes = markItem[2];
						var markTitle = markNodes.match(/<title>(.+)<\/title>/)[1];
						var markText = markNodes.match(/<text>(.+)<\/text>/)[1];
						var markCreator = markNodes.match(/<creator>([0-9]+)<\/creator>/)[1];
						if(markCreator == feuserid) {
							var markCreatorName = feusername;
						} else {
							var markCreatorName = markNodes.match(/<creatorname>(.+)<\/creatorname>/)[1];
						}
						var markCreatedOn = markNodes.match(/<createdon>(.+)<\/createdon>/)[1];
						var markEditor = markNodes.match(/<editor>([0-9]+)<\/editor>/)[1];
						if(markEditor == feuserid) {
							var markEditorName = feusername;
						} else {
							var markEditorName = markNodes.match(/<editorname>(.+)<\/editorname>/)[1];
						}
						var markEditedOn = markNodes.match(/<editedon>(.+)<\/editedon>/)[1];
						
						var markImageObj = imageObj[markImageNo];
						
						markImageObj.addMark(markTop, markLeft, markWidth, markHeight, markTitle, markText, markCreator, markCreatorName, markCreatedOn, markEditor, markEditorName, markEditedOn);
						var markObj = markImageObj.mark[markImageObj.markCounter];
						markObj.isNew = false;
					}
				}
			
			}
			return true;
		};
		
		this.hideMarks = function() {
			for(var i=1;i<this.mark.length;i++) {
				if(this.mark[i] != 0) {
					this.mark[i].hide();
				}
			}
			jQuery(this.StoolbarID+' .'+toolbarHideClass).unbind('click');
			jQuery(this.StoolbarID+' .'+toolbarHideClass).click(function() { imageObj[this.id.replace(/.*([0-9]+)$/, '$1')].showMarks(); });
			jQuery(this.StoolbarID+' .'+toolbarHideClass).attr('src', toolbarShowIcon);
			this.deactivateToolbarButtonAdd();
			this.deactivateToolbarButtonEdit();
			this.deactivateToolbarButtonDelete();
		};
		
		this.showMarks = function() {
			for(var i=1;i<this.mark.length;i++) {
				if(this.mark[i] != 0) {
					this.mark[i].show();
				}
			}
			jQuery(this.StoolbarID+' .'+toolbarHideClass).unbind('click');
			jQuery(this.StoolbarID+' .'+toolbarHideClass).click(function() { imageObj[this.id.replace(/.*([0-9]+)$/, '$1')].hideMarks(); });
			jQuery(this.StoolbarID+' .'+toolbarHideClass).attr('src', toolbarHideIcon);
			this.activateToolbarButtonAdd();
			this.activateToolbarButtonEdit();
			this.activateToolbarButtonDelete();
		};
		
		this.makeMarksEditSelectable = function() {
			for(var i=1;i<this.mark.length;i++) {
				if(this.mark[i] != 0) {
					this.mark[i].makeEditSelectable();
				}
			}
		};
		
		this.makeMarksDeleteSelectable = function() {
			for(var i=1;i<this.mark.length;i++) {
				if(this.mark[i] != 0) {
					this.mark[i].makeDeleteSelectable();
				}
			}
		};
		
		this.makeMarksNonSelectable = function() {
			for(var i=1;i<this.mark.length;i++) {
				if(this.mark[i] != 0) {
					this.mark[i].makeNonSelectable();
				}
			}
		};
		
		this.createMarkForm = function() {
			markForm = document.createElement('div');
			markForm.id = this.markFormID;
			markForm.className = markFormClass;
			jQuery(this.SboxID).after(markForm);
			jQuery(this.SmarkFormID).css('display', 'none');
			jQuery(this.SmarkFormID).html('<form class="imagemark-editform" action="#" onsubmit="imageObj['+this.no+'].onFormSubmit(); return false;"><label>'+labelTitle+'</label><input type="text" name="'+formTitleName+'" class="'+formTitleClass+'" value="" /><br class="clear-both" /><label>'+labelText+'</label><textarea name="'+formTextName+'" class="'+formTextClass+'"></textarea><br class="clear-both" /><input type="submit" class="imagemark-submit" name="'+formSubmitName+'" value="'+labelSave+'" /><input type="reset" class="imagemark-reset" value="'+labelCancel+'" onclick="imageObj['+this.no+'].onFormCancel(); return false;" /><br class="clear-both" /></form>');
		};
		
		this.showMarkForm = function() {
			jQuery(this.SmarkFormID).css('display', 'block');
		};
		
		this.emptyMarkForm = function() {
			jQuery(this.SFormTitle).val('');
			jQuery(this.SFormText).val('');
		};
		
		this.fillMarkForm = function(title, text) {
			jQuery(this.SFormTitle).val(title);
			jQuery(this.SFormText).val(text);
		};
		
		this.hideMarkForm = function() {
			jQuery(this.SmarkFormID).css('display', 'none');
		};
		
		this.onFormSubmit = function() {
			this.mark[this.actMark].save();
			
			this.mark[this.actMark].deactivate();
			
			this.saveMarks();
			
			this.activateToolbarButtonAdd();
			this.activateToolbarButtonEdit();
			this.activateToolbarButtonDelete();
			this.activateToolbarButtonHide();
		};
		
		this.onFormCancel = function() {
			this.mark[this.actMark].reposition();
			this.mark[this.actMark].resize();
			if(this.mark[this.actMark].isNew) {
				this.mark[this.actMark].remove();
			} else {
				this.mark[this.actMark].deactivate();
			}
			this.activateToolbarButtonAdd();
			this.activateToolbarButtonEdit();
			this.activateToolbarButtonDelete();
			this.activateToolbarButtonHide();
		};
		
		this.onToolbarEditClick = function() {
			if(this.editActive) {
				this.editActive = false;
				this.activateToolbarButtonAdd();
				this.activateToolbarButtonDelete();
				this.activateToolbarButtonHide();
				this.makeMarksNonSelectable();
			} else {
				this.editActive = true;
				this.deactivateToolbarButtonAdd();
				this.deactivateToolbarButtonDelete();
				this.deactivateToolbarButtonHide();
				this.makeMarksEditSelectable();
			}
		};
		
		this.onToolbarDeleteClick = function() {
			if(this.deleteActive) {
				this.deleteActive = false;
				this.activateToolbarButtonAdd();
				this.activateToolbarButtonEdit();
				this.activateToolbarButtonHide();
				this.makeMarksNonSelectable();
			} else {
				this.deleteActive = true;
				this.deactivateToolbarButtonAdd();
				this.deactivateToolbarButtonEdit();
				this.deactivateToolbarButtonHide();
				this.makeMarksDeleteSelectable();
			}
		};
		
		this.deactivateForm = function() {
			this.emptyMarkForm();
			this.hideMarkForm();
		};
		
		this.initImage = function() {
			this.createWrapBox();
			this.addToolbar();
			this.importMarks();
			this.createMarkForm();
		};
		
		this.initImage();
	}
	
	function mark(no, markImage, top, left, width, height, title, text, creator, creatorName, createdon, editor, editorName, editedon) {
		this.no = no;
		this.markImage = markImage;
		this.ID = imageMarkID + this.markImage.no + '-' + no;
		this.SID = '#' + this.ID;
		this.infoID = this.ID + 'info';
		this.SinfoID = '#' + this.infoID;
		this.isInfo = false;
		this.isNew = true;
		if(creator) {
			this.creator = creator;
		} else {
			this.creator = 0;
		}
		if(creatorName) {
			this.creatorName = creatorName;
		} else {
			this.creatorName = 0;
		}
		if(createdon) {
			this.createdon = createdon;
		} else {
			this.createdon = 0;
		}
		if(editor) {
			this.editor = editor;
		} else {
			this.editor = 0;
		}
		if(editorName) {
			this.editorName = editorName;
		} else {
			this.editorName = 0;
		}
		if(editedon) {
			this.editedon = editedon;
		} else {
			this.editedon = 0;
		}
		this.top = parseInt(top);
		this.left = parseInt(left);
		this.width = parseInt(width);
		this.height = parseInt(height);
		if(title) {
			this.title = title;
		} else {
			this.title = '';
		}
		if(text) {
			this.text = text;
		} else {
			this.text = '';
		}
		
		this.hide = function() {
			jQuery(this.SID).css('display', 'none');
			this.hideInfo();
		};
		
		this.show = function() {
			jQuery(this.SID).css('display', 'block');
		};
		
		this.activate = function() {
			this.markImage.actMark = this.no;
			this.makeEditable();
			this.markImage.emptyMarkForm();
			this.markImage.fillMarkForm(this.title, this.text);
			this.markImage.showMarkForm();
			jQuery(this.SID).unbind('mouseenter');
			jQuery(this.SID).unbind('mouseleave');
		};
		
		this.deactivate = function() {
			this.markImage.actMark = 0;
			this.makeNonEditable();
			this.markImage.deactivateForm();
			this.setHover();
			this.mouseLeave();
		};
		
		this.reposition = function() {
			jQuery(this.SID).css('top', this.top+'px');
			jQuery(this.SID).css('left', this.left+'px');
		};
		
		this.resize = function() {
			jQuery(this.SID).css('width', this.width+'px');
			jQuery(this.SID).css('height', this.height+'px');
		};
		
		this.setHover = function() {
			jQuery(this.SID).mouseenter(function() { imageObj[this.id.replace(/.*([0-9]+)\-([0-9]+)$/, '$1')].mark[this.id.replace(/.*([0-9]+)\-([0-9]+)$/, '$2')].mouseEnter(); });
			jQuery(this.SID).mouseleave(function() { imageObj[this.id.replace(/.*([0-9]+)\-([0-9]+)$/, '$1')].mark[this.id.replace(/.*([0-9]+)\-([0-9]+)$/, '$2')].mouseLeave(); });
		};
		
		this.mouseEnter = function() {
			this.showInfo();
			jQuery(this.SID).addClass(imageMarkHoverClass);
		};
		
		this.mouseLeave = function() {
			this.hideInfo();
			jQuery(this.SID).removeClass(imageMarkHoverClass);
		};
		
		this.getXML = function() {
			var xml = '<mark no="'+this.no+'" imageno="'+this.markImage.no+'" top="'+this.top+'" left="'+this.left+'" width="'+this.width+'" height="'+this.height+'">';
			xml += '<title>'+this.title+'</title>';
			xml += '<text>'+this.text+'</text>';
			xml += '<creator>'+this.creator+'</creator>';
			xml += '<creatorname>'+this.creatorName+'</creatorname>';
			xml += '<createdon>'+this.createdon+'</createdon>';
			xml += '<editor>'+this.editor+'</editor>';
			xml += '<editorname>'+this.editorName+'</editorname>';
			xml += '<editedon>'+this.editedon+'</editedon>';
			xml += '</mark>';
			return xml;
		};
		
		this.updatePos = function(top, left) {
			this.setPos(top, left);
			this.updateInfo();
		};
		
		this.setPos = function(top, left) {
			this.top = top;
			this.left = left;
		};
		
		this.updateSize = function(width, height) {
			this.setSize(width, height);
			this.updateInfo();
		}
		
		this.setSize = function(width, height) {
			this.width = width;
			this.height = height;
		};
		
		this.setData = function(title, text) {
			this.title = title;
			this.text = text;
		};
		
		this.create = function() {
			var mark = document.createElement('div');
			mark.id = this.ID;
			mark.className = imageMarkClass;
			mark.style.top = this.top + 'px';
			mark.style.left = this.left + 'px';
			mark.style.width = this.width + 'px';
			mark.style.height = this.height + 'px';
			jQuery(this.markImage.image).before(mark);
			this.isInfo = true;
		};
		
		this.makeEditable = function() {
			jQuery(this.SID).css('z-index', '1000');
			jQuery(this.SID).draggable({ containment: 'parent' });
			jQuery(this.SID).resizable({ containment: 'parent' });
// 			jQuery(this.SID).draggable({ containment: 'parent', stop: function(event, ui) { imageObj[this.id.replace(/.*([0-9]+)\-([0-9]+)$/, '$1')].mark[this.id.replace(/.*([0-9]+)\-([0-9]+)$/, '$2')].updatePos(ui.position.top, ui.position.left); } });
// 			jQuery(this.SID).resizable({ containment: 'parent', stop: function(event, ui) { imageObj[this.id.replace(/.*([0-9]+)\-([0-9]+)$/, '$1')].mark[this.id.replace(/.*([0-9]+)\-([0-9]+)$/, '$2')].updateSize(jQuery(this).width(), jQuery(this).height()); } });
		};
		
		this.makeNonEditable = function() {
			jQuery(this.SID).css('z-index', '100');
			jQuery(this.SID).draggable('destroy');
			jQuery(this.SID).resizable('destroy');
		};
		
		this.makeEditSelectable = function() {
			jQuery(this.SID).addClass(imageMarkSelectableClass);
			jQuery(this.SID).mouseenter(function() { jQuery(this).addClass(imageMarkSelectableHoverClass); });
			jQuery(this.SID).mouseleave(function() { jQuery(this).removeClass(imageMarkSelectableHoverClass); });
			jQuery(this.SID).click(function() { imageObj[this.id.replace(/.*([0-9]+)\-([0-9]+)$/, '$1')].mark[this.id.replace(/.*([0-9]+)\-([0-9]+)$/, '$2')].select(); });
		};
		
		this.makeDeleteSelectable = function() {
			jQuery(this.SID).addClass(imageMarkSelectableClass);
			jQuery(this.SID).mouseenter(function() { jQuery(this).addClass(imageMarkSelectableHoverClass); });
			jQuery(this.SID).mouseleave(function() { jQuery(this).removeClass(imageMarkSelectableHoverClass); });
			jQuery(this.SID).click(function() { imageObj[this.id.replace(/.*([0-9]+)\-([0-9]+)$/, '$1')].mark[this.id.replace(/.*([0-9]+)\-([0-9]+)$/, '$2')].deleteIt(); });
		};
		
		this.makeNonSelectable = function() {
			jQuery(this.SID).removeClass(imageMarkSelectableClass);
			jQuery(this.SID).unbind('click');
			jQuery(this.SID).unbind('mouseenter');
			jQuery(this.SID).unbind('mouseleave');
			this.setHover();
		};
		
		this.select = function() {
			this.markImage.deactivateToolbarButtonEdit();
			jQuery(this.SID).removeClass(imageMarkSelectableHoverClass);
			this.markImage.makeMarksNonSelectable();
			this.activate();
		};
		
		this.deleteIt = function() {
			this.markImage.deleteActive = false;
			this.markImage.activateToolbarButtonAdd();
			this.markImage.activateToolbarButtonEdit();
			jQuery(this.SID).removeClass(imageMarkSelectableHoverClass);
			this.markImage.makeMarksNonSelectable();
			this.removeConfirm();
		};
		
		this.removeConfirm = function() {
			if(confirm(deleteConfirmMsg)) {
				this.remove();
			}
		};
		
		this.remove = function() {
			this.markImage.actMark = 0;
			this.markImage.deactivateForm();
			jQuery(this.SinfoID).remove();
			jQuery(this.SID).remove();
			this.markImage.mark[this.no] = 0;
			this.markImage.saveMarks();
		};
		
		this.createInfo = function() {
			var info = document.createElement('div');
			info.id = this.infoID;
			info.className = imageMarkClass + 'info';
			info.style.top = (this.top + this.height) + 'px';
			info.style.left = this.left + 'px';
			headline = document.createElement('h3');
			headline.innerHTML = this.title;
			paragraph = document.createElement('p');
			paragraph.innerHTML = nl2br(this.text);
			span = document.createElement('span');
			if(this.editorName != 0) {
				if(langcode == 'de') {
					span.innerHTML = 'erstellt von: '+this.creatorName+', zuletzt geändert von: '+this.editorName;
				} else {
					span.innerHTML = 'created by: '+this.creatorName+', lastly edited by: '+this.editorName;
				}
			} else {
				if(langcode == 'de') {
					span.innerHTML = 'erstellt von: '+this.creatorName;
				} else {
					span.innerHTML = 'created by: '+this.creatorName;
				}
			}
			info.appendChild(headline);
			info.appendChild(paragraph);
			info.appendChild(span);
			jQuery(this.SID).after(info);
		};
		
		this.updateInfo = function() {
			if(!this.isInfo) {
				this.createInfo();
				this.hideInfo();
			} else {
				jQuery(this.SinfoID).css('top', (this.top + this.height) + 'px');
				jQuery(this.SinfoID).css('left', this.left + 'px');
				
				jQuery(this.SinfoID + ' h3').text(this.title);
				jQuery(this.SinfoID + ' p').text(nl2br(this.text));
				if(this.editorName != 0) {
					jQuery(this.SinfoID + ' span').text('erstellt von: '+this.creatorName+', zuletzt geändert von: '+this.editorName);
				} else {
					jQuery(this.SinfoID + ' span').text('erstellt von: '+this.creatorName);
				}
			}
		}
		
		this.showInfo = function() {
			jQuery(this.SinfoID).css('display', 'block');
		};
		
		this.hideInfo = function() {
			jQuery(this.SinfoID).css('display', 'none');
		};
		
		this.save = function() {
			var actDate = new Date();
			var actDay = actDate.getDate();
			var actMonth = actDate.getMonth()+1;
			var actYear = actDate.getFullYear();
			var actHour = actDate.getHours();
			var actMinute = actDate.getMinutes();
			var theDate = actDay+'.'+actMonth+'.'+actYear+' '+actHour+':'+actMinute;
			if(this.creator == 0) {
				this.creator = feuserid;
				this.creatorName = feusername;
				this.createdon = theDate;
			} else {
				this.editor = feuserid;
				this.editorName = feusername;
				this.editedon = theDate;
			}
			this.title = jQuery(this.markImage.SFormTitle).val().replace(/[<>]/g, '');
			this.text = jQuery(this.markImage.SFormText).val().replace(/[<>]/g, '');
			this.setPos(jQuery(this.SID).position().top, jQuery(this.SID).position().left);
			this.setSize(jQuery(this.SID).width(), jQuery(this.SID).height());
			this.isNew = false;
			this.updateInfo();
		};
		
		if(!top || !left) { this.setPos(100, 100); }
		if(!width || !height) { this.setSize(100, 100); }
		
		this.create();
		this.createInfo();
		this.hideInfo();
		this.setHover();
	}
	
	function nl2br(str) {
 		if(typeof(str)=="string") return str.replace(/(\r\n)|(\n\r)|\r|\n/g,"<br />");
 		else return str;
 	}

	jQuery(document).ready(function() {
		var userid = jQuery('#feuserid').text();
		if(userid != '') {
			feuserid = userid;
		}
		var username = jQuery('#feusername').text();
		if(username != '') {
			feusername = username;
		}
		var languagecode = jQuery('#langcode').text();
		if(languagecode == '1') {
			langcode = 'en';
		}
		var markImages = jQuery('.'+imageClass);
		var imageCounter = 0;
		markImages.each(function(indexNo) {
			imageCounter = imageCounter + 1;
			imageObj[imageCounter] = new markImage(imageCounter, this);
		});
	});

