var PhotoTagger = function() {
	var that = this;
	var tagging = 0, dragging = 0;
	var photoarea, photoarea_style;
	var photo, photo_w, photo_h, photo_x = -1, photo_y = -1;
	var tagframe = null, tagframe_style;
	var tagframe_x, tagframe_y, tagframe_w, tagframe_h, tagframe_whalf, tagframe_hhalf;
	var tagframe_min_w = 30, tagframe_min_h = 30, new_frame_w = 100, new_frame_h = 100;
	var tagframespy = null, tagframespy_style, tagframespy_need_init = 1, frame_created = false;
	var nw_style, n_style, ne_style, w_style, e_style, sw_style, s_style, se_style;
	var fadedphoto = null, fadedphoto_style, fadedphoto_need_init = 1;
	var selector, selector_style;
	var onmove_func = null;
	var tact, tajax;
	var url = 'ajax/tagger.php';
	
	this.init = function(){
		photoarea = ge('photoarea');
		photoarea_style = photoarea.style;
		photo = ge('myphoto');
		photo_w = photo.width;
		photo_h = photo.height;
		photoarea_style.width  = photo_w + 'px';
		photoarea_style.height = photo_h + 'px';
		var xy = getXY(photoarea);
		photo_x = xy[0];
		photo_y = xy[1];
		selector = ge('selector');
		selector_style = selector.style;
		if(!tajax){
			tajax = new Ajax(that.onDone, that.onFail);
		}
	}
	this.scrollTop = function(){
		document.body.scrollTop = '545';
		document.documentElement.scrollTop = '545';
	}
	this.beginTagging = function(e){
		//that.scrollTop();
		ge('photomsgwrap').innerHTML = '<div id="photomsg"><div id="message"><table id="tagging_message"><tr><td width="480">Нажмите на область, где изображен человек, и он будет подписан на фотографии.<br />Вы можете добавлять любое количество друзей на фотографию.</td><td valign="middle"><b class="nc"><b class="nc1"><b></b></b><b class="nc2"><b></b></b></b><span class="ncc"><a href="javascript:tagger.endTagging();">Готово</a></span><b class="nc"><b class="nc2"><b></b></b><b class="nc1"><b></b></b></b></td></tr></table></div></div>';
		show('photomsgwrap');
		that.init();
		photoarea_style.cursor = 'crosshair';
		ge('photolink').style.cursor = 'crosshair';
		addEvent(photoarea, "mousedown", that.beginCreateFrame);
		ge('photolink').onclick = function(e){return false;};
		if(!tagframe){
			tagframe = ge('tagframe');
			tagframe_style = tagframe.style;
			addEvent(tagframe, "mousedown", that.frameMouseDown);
			addEvent(ge('nw'), "mousedown", that.frameMouseDown);
			addEvent(ge('ne'), "mousedown", that.frameMouseDown);
			addEvent(ge('n'), "mousedown", that.frameMouseDown);
			addEvent(ge('w'), "mousedown", that.frameMouseDown);
			addEvent(ge('e'), "mousedown", that.frameMouseDown);
			addEvent(ge('sw'), "mousedown", that.frameMouseDown);
			addEvent(ge('s'), "mousedown", that.frameMouseDown);
			addEvent(ge('se'), "mousedown", that.frameMouseDown);
			addEvent(tagframe, "mouseup", that.frameMouseUp);
			addEvent(ge('nw'), "mouseup", that.frameMouseUp);
			addEvent(ge('ne'), "mouseup", that.frameMouseUp);
			addEvent(ge('n'), "mouseup", that.frameMouseUp);
			addEvent(ge('w'), "mouseup", that.frameMouseUp);
			addEvent(ge('e'), "mouseup", that.frameMouseUp);
			addEvent(ge('sw'), "mouseup", that.frameMouseUp);
			addEvent(ge('s'), "mouseup", that.frameMouseUp);
			addEvent(ge('se'), "mouseup", that.frameMouseUp);
			nw_style = ge('nw').style;
			n_style = ge('n').style;
			ne_style = ge('ne').style;
			w_style = ge('w').style;
			e_style = ge('e').style;
			sw_style = ge('sw').style;
			s_style = ge('s').style;
			se_style = ge('se').style;
		}
		if(!tagframespy){
			tagframespy = ge('tagframespy');
			tagframespy_style = tagframespy.style;
		}
		//if(tagframespy_need_init){
			tagframespy.src = photo.src;
			//tagframespy_need_init = 0;
		//}
		//that.fillSelector();
		tagging = 1;
	}
	
	this.endTagging = function(){
		if(!tagging){
			return;
		}
		hide('photomsgwrap');
		photoarea_style.cursor = '';
		ge('photolink').style.cursor = '';
		//ge('photolink').style.cursor = 'poiner';
		ge('photolink').onclick = photoAction.next;
		addEvent(ge('photolink'),'onclick', 'javascript:photoAction.next();');
		removeEvent(photoarea, "mousedown", that.beginCreateFrame);
		tagframe_style.display = 'none';
		that.hideHelpers();
		that.hideSelector();
		if(fadedphoto_style) {
			fadedphoto_style.display = 'none';
		}
		frame_created = false;
		//tagframespy_need_init = 1;
		tagging = 0;
		// Изменение списка отмеченных
		photoAction.mark();
	}

	this.beginCreateFrame = function(e){
		if (e.button != 0 && e.button != 1) {
			return true;
		}
		was_created = 0;
		begin_create_x = that.mousePosX(e);
		begin_create_y = that.mousePosY(e);
		addEvent(photoarea, 'mousemove', that.creatingFrame);
		addEvent(photoarea, 'mouseup', that.endCreateFrame);
		return cancelEvent(e)
	}
	this.creatingFrame = function(e){
		if (!was_created) {
			var x = that.mousePosX(e), y = that.mousePosY(e);
			var handle = '', delta_x = x - begin_create_x, delta_y = y - begin_create_y, new_x, new_y;
			if (delta_x <= -5 && delta_y <= -5) {
				handle = 'nw';
				new_x = x; new_y = y;
			} else if (delta_x <= -5 && delta_y >= 5) {
				handle = 'sw';
				new_x = x; new_y = begin_create_y;
			} else if (delta_x >= 5 && delta_y <= -5) {
				handle = 'ne';
				new_x = begin_create_x; new_y = y;
			} else if (delta_x >= 5 && delta_y >= 5) {
				handle = 'se';
				new_x = begin_create_x; new_y = begin_create_y;
			}
			if (handle) {
				that.createFrame(e, new_x, new_y, Math.abs(x - begin_create_x), Math.abs(y - begin_create_y));
				that.frameMouseDown(e, handle);				
				was_created = 1;
			}
		}
		return false;
	}
	this.endCreateFrame = function(e){
		if (!was_created) {
			that.createFrame(e);
			was_created = 1;
		}
		return false;
	}
	this.createFrame = function(e, x, y, w, h){
		var mouse_x = x || that.mousePosX(e);
		var mouse_y = y || that.mousePosY(e);
		that.showFadedPhoto();
		that.updateFrameSize(w || Math.min(new_frame_w, photo_w), h || Math.min(new_frame_h, photo_h));
		that.updateFramePosition(mouse_x - photo_x - tagframe_whalf, mouse_y - photo_y - tagframe_hhalf);
		that.updateHelpers();
		tagframe_style.display = 'block';
		that.showHelpers();
		that.updateSelectorPosition();
		that.showSelector();
		removeEvent(photoarea, 'mousemove', that.creatingFrame);
		removeEvent(photoarea, 'mouseup', that.endCreateFrame);
		frame_created = true;
		return false;
	}
	this.updateFrameSize = function(w, h) {
		if (w > -1) {
			tagframe_w = w;	tagframe_whalf = w / 2 | 0;
			tagframe_style.width = w + 'px';
		}
		if (h > -1) {
			tagframe_h = h; tagframe_hhalf = h / 2 | 0;		
			tagframe_style.height = h + 'px';
		}
	}

	this.fixFrameSize = function() {
		var new_w = -1, new_h = -1, new_x = -1, new_y = -1;
		if (tagframe_w < tagframe_min_w) {
			new_w = Math.min(tagframe_min_w, photo_w);
		}
		if (tagframe_h < tagframe_min_h) {
			new_h = Math.min(tagframe_min_h, photo_h);
		}
		that.updateFrameSize(new_w, new_h);
		that.updateFramePosition(tagframe_x, tagframe_y);
		that.updateHelpers();
	}
	this.updateSelectorPosition = function(){
		//selector_style.left = tagframe_x + tagframe_w + 10 + 'px';
		//selector_style.top = tagframe_y + 'px';
	}
	this.showSelector = function(){
		selector_style.display = 'block';
	}
	this.hideSelector = function(){
		selector_style.display = 'none';
	}
	this.updateFramePosition = function(x, y) {
		if (x != -1) {
			x = Math.min(photo_w - tagframe_w, Math.max(0, x));
			tagframe_x = x;
			tagframe_style.left = x + "px";
			tagframespy_style.left = -x + "px";
		}
		if (y != -1) {
			y = Math.min(photo_h - tagframe_h, Math.max(0, y));
			tagframe_y = y;
			tagframe_style.top = y + "px";
			tagframespy_style.top = -y + "px";
		}
	}
	this.showHelpers = function() {
		nw_style.display = 'block'; 
		n_style.display  = 'block'; 
		ne_style.display = 'block'; 
		w_style.display  = 'block'; 
		e_style.display  = 'block'; 
		sw_style.display = 'block'; 
		s_style.display  = 'block'; 
		se_style.display = 'block';
	}	
	this.updateHelpers = function() {
		nw_style.left = tagframe_x - 5 + 'px';
		nw_style.top  = tagframe_y - 5 + 'px';		
		n_style.left  = tagframe_x + tagframe_whalf - 5 + "px";
		n_style.top   = tagframe_y - 5 + 'px';
		ne_style.left = tagframe_x + tagframe_w - 5 + 'px';
		ne_style.top  = tagframe_y - 5 + 'px';
		w_style.left  = tagframe_x - 5 + "px";
		w_style.top   = tagframe_y + tagframe_hhalf - 5 + "px";
		e_style.left  = tagframe_x + tagframe_w - 5 + "px";
		e_style.top   = tagframe_y + tagframe_hhalf - 5 + "px";
		sw_style.left = tagframe_x - 5 + 'px';
		sw_style.top  = tagframe_y + tagframe_h - 5 + 'px';		
		s_style.left  = tagframe_x + tagframe_whalf - 5 + "px";
		s_style.top   = tagframe_y + tagframe_h - 5 + 'px';
		se_style.left = tagframe_x + tagframe_w - 5 + 'px';
		se_style.top  = tagframe_y + tagframe_h - 5 + 'px';
	}
	this.hideHelpers = function() {
		nw_style.display = 'none'; 
		n_style.display  = 'none'; 
		ne_style.display = 'none'; 
		w_style.display  = 'none'; 
		e_style.display  = 'none';
		sw_style.display = 'none'; 
		s_style.display  = 'none'; 
		se_style.display = 'none'; 
	}
	this.showFadedPhoto = function() {
		if (!fadedphoto) {
			fadedphoto = ge('fadedphoto');
			fadedphoto_style = fadedphoto.style;
		}
		fadedphoto.style.width = photo_w + 'px';
		fadedphoto.style.height = photo_h + 'px';
		//fadedphoto_need_init = 0;
		fadedphoto_style.display = "block";
	}
	var w_stub = 0, h_stub = 0;
	var saved_tagframe_x, saved_tagframe_y;
	var saved_tagframe_w, saved_tagframe_h;
	
	this.frameMouseDown = function(e, target_id){
		if (e.button != 0 && e.button != 1) {
			return true;
		}
		var target = null;
		if (!target_id) {
			target = (e.srcElement) ? e.srcElement : e.target;
			target_id = target.id == '' ? target.parentNode.id : target.id;
		}
		saved_tagframe_x = tagframe_x, saved_tagframe_y = tagframe_y;
		saved_tagframe_w = tagframe_w, saved_tagframe_h = tagframe_h;
		switch(target_id) {
			case 'tagframespy': case 'nw': case 'n': case 'ne':
			case 'w': case 'e': case 'sw': case 's': case "se":
			that.hideHelpers();
			that.hideSelector();
			that.setMoveFunction(target_id, e);
			removeEvent(photoarea, 'mousedown', that.beginCreateFrame);
			addEvent(document.body, 'mouseup', that.frameMouseUp);
			addEvent(document.body, 'dragend', that.frameMouseUp);
			dragging = 1;
		}
		return cancelEvent(e);
	}
	var preonmove_functions = {
		'tagframespy': function(e) {
				x_offset = tagframe_x - that.mousePosX(e);
				y_offset = tagframe_y - that.mousePosY(e);
				photoarea_style.cursor = "move";
				onmove_func = that.frameMouseMove;
			},
		'nw': function(e) {
				if (e) {
					x_offset = tagframe_x + photo_x - that.mousePosX(e);
					y_offset = tagframe_y + photo_y - that.mousePosY(e);
				}
				tagframe_style.cursor = photoarea_style.cursor = 'nw-resize';
				onmove_func = function (e) {
					var no_change = true;
					var x = that.mousePosX(e) - photo_x + x_offset;
					var y = that.mousePosY(e) - photo_y + y_offset;
					var x_norm = Math.min(tagframe_x + tagframe_w - w_stub, Math.max(0, x));
					var y_norm = Math.min(tagframe_y + tagframe_h - h_stub, Math.max(0, y));
					if (x > x_norm) {
						that.updateFrameSize(0, saved_tagframe_h + saved_tagframe_y - y_norm);
						that.updateFramePosition(x_norm, y_norm);
						that.setMoveFunction('ne');
						no_change = false;
					}
					if (y > y_norm) {
						that.updateFrameSize(saved_tagframe_w + saved_tagframe_x - x_norm, 0);
						that.updateFramePosition(x_norm, y_norm);
						that.setMoveFunction('sw');
						no_change = false;
					}
					if (no_change) {
						that.updateFrameSize(saved_tagframe_w + saved_tagframe_x - x_norm, saved_tagframe_h + saved_tagframe_y - y_norm);	
						that.updateFramePosition(x_norm, y_norm);
					}
					return cancelEvent(e); 		
				};
		},
		'n': function(e) {
				if (e) {
					y_offset = tagframe_y + photo_y - that.mousePosY(e);
				}
				tagframe_style.cursor = photoarea_style.cursor = 'n-resize';
				onmove_func = function (e) {
					var y = that.mousePosY(e) - photo_y + y_offset;
					var y_norm = Math.min(saved_tagframe_y + saved_tagframe_h, Math.max(0, y));
					if (y > y_norm) {
						that.updateFrameSize(-1, 0);	
						that.updateFramePosition(-1, saved_tagframe_h + saved_tagframe_y); 		
						that.setMoveFunction('s');
					} else {						
						that.updateFrameSize(-1, saved_tagframe_h + saved_tagframe_y - y_norm);	
						that.updateFramePosition(-1, y_norm);
					}
					return cancelEvent(e); 		
				};
			},
		'ne': function(e) {
				if (e) {
					x_offset = tagframe_x + photo_x + tagframe_w - that.mousePosX(e);
					y_offset = tagframe_y + photo_y - that.mousePosY(e);
				}
				tagframe_style.cursor = photoarea_style.cursor = 'ne-resize';
				onmove_func = function (e) {
					var no_change = true;
					var x = that.mousePosX(e) - photo_x + x_offset;
					var y = that.mousePosY(e) - photo_y + y_offset;
					var x_norm = Math.min(photo_w, Math.max(tagframe_x + w_stub, x));
					var y_norm = Math.min(saved_tagframe_y + saved_tagframe_h - h_stub, Math.max(0, y));
					if (x < x_norm) {
						that.updateFrameSize(0, saved_tagframe_h + saved_tagframe_y - y_norm);	
						that.updateFramePosition(-1, y_norm); 		
						that.setMoveFunction('nw');
						no_change = false;
					}
					if (y > y_norm) {
						that.updateFrameSize(x_norm - saved_tagframe_x, saved_tagframe_h + saved_tagframe_y - y);	
						that.updateFramePosition(-1, saved_tagframe_y + saved_tagframe_h); 		
						that.setMoveFunction('se');
						no_change = false;
					}
					if (no_change) {
						that.updateFrameSize(x_norm - saved_tagframe_x, saved_tagframe_h + saved_tagframe_y - y_norm);	
						that.updateFramePosition(-1, y_norm); 		
					}
					return cancelEvent(e); 		
				};
			}, 
		'w': function(e) {
				if (e) {
					x_offset = tagframe_x + photo_x - that.mousePosX(e);
				}
				tagframe_style.cursor = photoarea_style.cursor = 'w-resize';
				onmove_func = function (e) {
					var x = that.mousePosX(e) - photo_x + x_offset;
					var x_norm = Math.min(saved_tagframe_x + saved_tagframe_w - w_stub, Math.max(0, x));
					if (x > x_norm) {
						that.updateFrameSize(0, -1);	
						that.updateFramePosition(saved_tagframe_x + saved_tagframe_w, -1); 		
						that.setMoveFunction('e');
					} else {
						that.updateFrameSize(saved_tagframe_w + saved_tagframe_x - x_norm, -1);	
						that.updateFramePosition(x_norm, -1); 		
					}
					return cancelEvent(e); 		
				};
			},
		'e': function(e) {
				if (e) {
				x_offset = tagframe_x + photo_x + tagframe_w - that.mousePosX(e);
				}
				tagframe_style.cursor = photoarea_style.cursor = 'e-resize';
				onmove_func = function (e) {
					var x = that.mousePosX(e) - photo_x + x_offset;
					var x_norm = Math.min(photo_w, Math.max(saved_tagframe_x + w_stub, x));
					if (x < x_norm) {
						that.updateFrameSize(0, -1);	
						that.setMoveFunction('w');
					} else {
						that.updateFrameSize(x_norm - saved_tagframe_x, -1);	
					}
					return cancelEvent(e); 		
				};
			},
		'sw': function(e) {
				if (e) {
					x_offset = tagframe_x + photo_x - that.mousePosX(e);
					y_offset = tagframe_y + photo_y + tagframe_h - that.mousePosY(e);
				}
				tagframe_style.cursor = photoarea_style.cursor = 'sw-resize';
				onmove_func = function (e) {
					var no_change = true;
					var x = that.mousePosX(e) - photo_x + x_offset;
					var y = that.mousePosY(e) - photo_y + y_offset;
					var x_norm = Math.min(saved_tagframe_x + saved_tagframe_w - w_stub, Math.max(0, x));
					var y_norm = Math.min(photo_h, Math.max(tagframe_y + h_stub, y));
					if (x > x_norm) {
						that.updateFrameSize(0, y_norm - saved_tagframe_y);	
						that.updateFramePosition(saved_tagframe_x + saved_tagframe_w, -1); 		
						that.setMoveFunction('se');
						no_change = false;
					} 
					if (y < y_norm) {
						that.updateFrameSize(saved_tagframe_x - x_norm + saved_tagframe_w, 0);	
						that.updateFramePosition(x_norm, -1); 		
						that.setMoveFunction('nw');
						no_change = false;
					}
					if (no_change) {
						that.updateFrameSize(saved_tagframe_x - x_norm + saved_tagframe_w, y_norm - saved_tagframe_y);
						that.updateFramePosition(x_norm, -1); 		
					}
					return cancelEvent(e); 		
				};
			},
		's': function(e) {
				if (e) {
					y_offset = tagframe_y + photo_y + tagframe_h - that.mousePosY(e);	
				}
				tagframe_style.cursor = photoarea_style.cursor = 's-resize';
				onmove_func = function (e) {
					var y = that.mousePosY(e) - photo_y + y_offset;
					var y_norm = Math.min(photo_h, Math.max(saved_tagframe_y, y));
					if (y < y_norm) {
						that.updateFrameSize(-1, 0);	
						that.updateFramePosition(-1, saved_tagframe_y);	
						that.setMoveFunction('n');
					} else {
						that.updateFrameSize(-1, y_norm - saved_tagframe_y);	
					}
					return cancelEvent(e); 		
				};
			},
		'se': function(e) {
				if (e) {
					x_offset = tagframe_x + photo_x + tagframe_w - that.mousePosX(e);
					y_offset = tagframe_y + photo_y + tagframe_h - that.mousePosY(e);
				}
				tagframe_style.cursor = photoarea_style.cursor = 'se-resize';
				onmove_func = function (e) {
					var no_change = true;
					var x = that.mousePosX(e) - photo_x + x_offset;
					var y = that.mousePosY(e) - photo_y + y_offset;
					var x_norm = Math.min(photo_w, Math.max(tagframe_x + w_stub, x));
					var y_norm = Math.min(photo_h, Math.max(tagframe_y + h_stub, y));
					if (x < x_norm) {
						that.updateFrameSize(0, y_norm - saved_tagframe_y);	
						that.setMoveFunction('sw');
						no_change = false;
					}
					if (y < y_norm) {
						that.updateFrameSize(x_norm - saved_tagframe_x, 0);	
						that.setMoveFunction('ne');
						no_change = false;
					}
					if (no_change) {
						that.updateFrameSize(x_norm - saved_tagframe_x, y_norm - saved_tagframe_y);	
					}
					return cancelEvent(e); 		
				};
			}
	};
	this.setMoveFunction = function(index, e) {
		saved_tagframe_x = tagframe_x, saved_tagframe_y = tagframe_y;
		saved_tagframe_w = tagframe_w, saved_tagframe_h = tagframe_h;
		if (onmove_func) {
			removeEvent(document.body, 'mousemove', onmove_func);
			removeEvent(document.body, 'drag', onmove_func);
		}
		preonmove_functions[index](e);
		addEvent(document.body, 'mousemove', onmove_func);
		addEvent(document.body, 'drag', onmove_func);
	}
	this.frameMouseMove = function(e) {
		var mouse_x = that.mousePosX(e);
		var mouse_y = that.mousePosY(e);
		that.updateFramePosition(mouse_x + x_offset, mouse_y + y_offset);
		return cancelEvent(e);		
	}
	this.frameMouseUp = function(e){
		if(dragging){
			tagframe_style.cursor = '';
			photoarea_style.cursor = 'crosshair';
			removeEvent(document.body, 'mousemove', onmove_func);
			removeEvent(document.body, 'drag', onmove_func);
			removeEvent(document.body, 'mouseup', that.frameMouseUp);
			removeEvent(document.body, 'dragend', that.frameMouseUp);
			setTimeout(function(){
				addEvent(photoarea, 'mousedown', that.beginCreateFrame);
			});
			that.fixFrameSize();
			that.updateHelpers();
			that.showHelpers();
			that.updateSelectorPosition();
			that.showSelector();
			dragging = 0;
		}
		return cancelEvent(e);
	}
	/*
	* Ajax
	*/	
	/*this.onDone = function(xml, text){
		//alert(text);
		if(tact == 'fillSelector'){
			var str = xml.getElementsByTagName('flist')[0].firstChild.nodeValue;
			ge('userlist').innerHTML = str;
		}
		if(tact == 'submitTag'){
			//var status = xml.getElementsByTagName('status')[0].firstChild.nodeValue;
			//alert(status);
			tagframe_style.display = 'none';
			that.hideHelpers();
			that.hideSelector();
			if (fadedphoto_style) {
				fadedphoto_style.display = 'none';
			}
			frame_created = false;
			that.fillSelector();
			photoAction.mark();
		}
		if(tact == 'markdel'){
			var status = xml.getElementsByTagName('status')[0].firstChild.nodeValue;
			if(status == 1){
				photoAction.mark();
			}
		}
		if(tact == 'invitationTag'){
			var status = xml.getElementsByTagName('status')[0].firstChild.nodeValue;
			if(status == '1'){
				hide(ge("photomsgwrap"));
			}
		}
		if(tact == 'removeTag'){
			var status = xml.getElementsByTagName('status')[0].firstChild.nodeValue;
			if(status == '1'){
				hide(ge("photomsgwrap"));
				photoAction.mark();
			}
		}
	}
	this.onFail = function(){
	
	}
	this.fillSelector = function(){
		tact = 'fillSelector';
		tajax.post(url, {'act':'frends'});
	}
	this.submitTag = function(uid){
		tact = 'submitTag';
		var pid = ge('photoid').value;
		var cid = ge('catid').value;
		var x = String(tagframe_x), y = String(tagframe_y), w = String(tagframe_w), h = String(tagframe_h);
		tajax.post(url, {'uid':uid, 'pid':pid, 'cid':cid, 'x':x, 'y':y, 'w':w, 'h':h, 'act':'addTag'});
		that.scrollTop();
	}
	this.invitationTag = function(id){
		if(!tajax){
			tajax = new Ajax(that.onDone, that.onFail);
		}
		tact = 'invitationTag';
		tajax.post(url, {'id':id, 'act':'invitationTag'});
	}
	this.removeTag = function(id){
		if(!tajax){
			tajax = new Ajax(that.onDone, that.onFail);
		}
		tact = 'removeTag';
		tajax.post(url, {'id':id, 'act':'removeTag'});
	}
	var tagBox = 0, tagboxspy, tagboxspy_style;
	this.showTag = function(x, y, w, h){
		if(tagBox){
			return;
		}
		if((x == 0) && (y == 0) && (w == 0) && (h == 0)){
			return;
		}
		that.init();
		tagBox = 1;
		ge('tagbox').style.left   = x + 'px'; 
		ge('tagbox').style.top    = y + 'px';
		ge('tagbox').style.width  = w + 'px';
		ge('tagbox').style.height = h + 'px';
		ge('tagbox').style.display = 'block';
		that.showFadedPhoto();
		that.showTagBox(x, y);
	}
	this.hideTag = function(){
		if(!tagBox){
			return;
		}
		tagBox = 0;
		ge('tagbox').style.display = 'none';
		fadedphoto_style.display = 'none';
	}
	this.showTagBox = function(x, y){
		tagboxspy = ge('tagboxspy');
		tagboxspy_style = tagboxspy.style;
		tagboxspy.src = photo.src;
		tagboxspy_style.left = -x - 1 + 'px';
		tagboxspy_style.top  = -y - 1 + 'px';
	}
	this.hideTagBox = function(){
		
	}
	this.markdel = function(markid){
		if(!tajax){
			tajax = new Ajax(that.onDone, that.onFail);
		}
		tact = 'markdel';
		tajax.post(url, {'markid':markid, 'act':'markdel'});
	}*/
	
	this.mousePosX = function(e){ return e.pageX; }
	this.mousePosY = function(e){ return e.pageY; }
}
tagger = new PhotoTagger;
