
	function hint_Show(event, data)
	{
		//old data: 0 - author, 1 = title, 2 - views, 3 - comments count, 4 - rating if exists
		//new data: 0 - dirname, 1 = title, 2 - album, 3 - date add
		var foto_hint = document.getElementById("foto_hint");
		var html = "";
		/*
		html += "Отправил: " + data[0] + "<br>";
		html += "Название: " + data[1] + "<br>";
		html += "Просмотров: " + data[2] + "<br>";
		html += "Комментариев: " + data[3] + "<br>";
		if (data[4]) {
			html += "<span class=\"red_text\">Проголосовало: " + data[4] + "</span><br>";
		}
		*/
		html += "Раздел: " + data[0] + "<br>";
		html += "Название: " + data[1] + "<br>";
		html += "Альбом: " + data[2] + "<br>";
		html += "Дата добавления: " + data[3] + "<br>";
		foto_hint.innerHTML = html;
		if (IE) {
			foto_hint.style.left = event.clientX + document.documentElement.scrollLeft + 5 + "px";
			foto_hint.style.top = event.clientY + document.documentElement.scrollTop + 5 + "px";
		} else {
			foto_hint.style.left = event.pageX + 5 + "px";
			foto_hint.style.top = event.pageY + 5 + "px";
		}
		foto_hint.style.display = "block";
	}
	
	function hint_Hide(event)
	{
		var foto_hint = document.getElementById("foto_hint");
		foto_hint.style.display = "none";
	}

	var Photos = {
		
		fotosActions : "/actions/fotos.php",
		dirId : 0,
		albumId : 0,
		albumName : 0,
		name : 0,
		text : 0,
		privacy : 0,
		tags : "",
		
		RateContested : function(id) {
			var vars = "action=rate_contested&photoid=" + id;
			try {
				sendXmlHttpRequest("get", this.fotosActions, vars, this.rateContestedCallback);
			} catch (e) {
				alert(e);
			}
		},
		rateContestedCallback : function(jsHttp) {
			eval("var json = " + jsHttp.responseText);
			if (json.Message.Type == "info") {
				document.getElementById("contest_rating").innerHTML = json.Rating;
				document.getElementById("contest_ratelink").style.display = "none";
			} else {
				alert(json.Message.Type + ":\n" + json.Message.Text);
			}
		},
		
		CheckBeforeUpload : function() {
			if (getValue("dirid") == 0 || getValue("dirid") == "create_new") {
				alert("Выберите раздел для загрузки");
				return false;
			}
			/*if (getValue("album_id") == 0 && getValue("album_new") == "") {
				alert("Укажите альбом для загрузки");
				return false;
			}*/
			if (getValue("album_id") == 0) {
				alert("Укажите альбом для загрузки");
				return false;
			}
			return true;
		},
				
		BeginPhotoEdit : function() {
			switchDisplay("photo_image_div");
			switchDisplay("photo_edit_div");			
			document.getElementById("photo_edit_link_span").className = "photoEditTabAcive";
			document.getElementById("photo_edit_link").onclick = Photos.EndPhotoEdit;						
			Photos.StoreValues();
		},
		
		EndPhotoEdit : function() {
			switchDisplay("photo_image_div");
			switchDisplay("photo_edit_div");			
			document.getElementById("photo_edit_link_span").className = "";
			document.getElementById("photo_edit_link").onclick = Photos.BeginPhotoEdit;			
			//if (!isEdited)
				Photos.RestoreValues();
		},
		
		SavePhotoChanges : function() {
			
			this.EndPhotoEdit();
		},
		
		StoreValues : function() {
			this.dirId = getValue("dir_id");
			//this.albumId = getValue("album_id");
			//this.albumName = getHtml("albums_upload_name");
			this.name = getValue("photo_name");
			this.text = getValue("photo_text");
			//this.privacy = getValue("photo_privacy");
			this.tags = getValue("photo_tags");
		},
		
		RestoreValues : function()
		{
			setValue("dir_id", this.dirId);
			setValue("album_id", this.albumId);
			//setHtml("albums_upload_name", this.albumName);
			setValue("photo_name", this.name);
			setValue("photo_text", this.text);
			//setValue("photo_privacy", this.privacy);
			setValue("photo_tags", this.tags);
		},
		
		SavePhotoEdit : function()
		{
			var vars = "action=save_photo&id=" + getValue("photo_id") + 
				"&dir_id=" + getValue("dir_id") +
				"&album_id=" + getValue("album_id") +
				//"&album_new=" + getValue("album_new") +
				"&photo_name=" + getValue("photo_name").replace("&", "%26")  +
				"&photo_text=" + getValue("photo_text").replace("&", "%26") +
				//"&photo_privacy=" + getValue("photo_privacy") +
				"&tags=" +  getValue("photo_tags");
			try {
				sendXmlHttpRequest("post", this.fotosActions, vars, this.savePhotoCallback);
			} catch (e) {
				alert(e);
			}
		},
		savePhotoCallback : function(jsHttp)
		{
			eval("var json = " + jsHttp.responseText);
			ShowMsg(json.Message.Text, json.Message.Type);
			setTimeout("CloseMsg()", 5000);
			if (json.Message.Type == "info") {
				if (Photos.dirId != getValue("dir_id") || Photos.albumId != getValue("album_id")
					|| Photos.tags != getValue("photo_tags")) {
					location.href = "/?dirid=" + getValue("dir_id") + "&photoid=" + getValue("photo_id");
				} else {
					setHtml("photo_name_div", getValue("photo_name"));
					setHtml("photo_text_div", "Комментарий:<br>"+ getValue("photo_text"));
					//setHtml("photo_tags_div", "Комментарий:<br>"+ getValue("photo_text"));
					Photos.StoreValues();
				}
			}
		},
		
		SetFotoPrivate : function(id) {
			var vars = "action=set_foto_private&photoid=" + id;
			try {
				sendXmlHttpRequest("get", this.fotosActions, vars, this.setFotoPrivateCallback);
			} catch (e) {
				alert(e);
			}
		},
		setFotoPrivateCallback : function(jsHttp) {
			eval("var json = " + jsHttp.responseText);
			if (json.Message.Type == "info") {
				document.getElementById("set_private_img" + json.PhotoId).src = "/img/actions/set_private_"+json.CurrentStatus+".gif";
			} else {
				alert(json.Message.Type + ":\n" + json.Message.Text);
			}
		},
		
		GetCommentsRange : function(photo_id, comment_id)
		{
			var comments_range = document.getElementById("comments_range_"+photo_id);
			if (comments_range.innerHTML.length != 0) {
				comments_range.style.display = "block";
				return;
			}
			var vars = "action=getcommentsrange&photoid=" + photo_id +"&commentid=" + comment_id;
			try {
				sendXmlHttpRequest("post", this.fotosActions, vars, function(jsHttp) {
					eval("var json = " + jsHttp.responseText);
					if (json.Message.Type == "info") {
						comments_range.style.display = "block";
						document.getElementById("comments_range_"+photo_id).innerHTML = json.Html;
					} else {
						alert(json.Message.Type + ":\n" + json.Message.Text);
					}
				} 
				);
			} catch (e) {
				alert(e);
			}
		},
		
		DeletePhoto : function(id, isList) {
			if (confirm("Удалить фотографию?") == false) return false;
			var vars = "action=delete_photo&id=" + id;
			try {
				if (isList)
					sendXmlHttpRequest("post", this.fotosActions, vars, this.deletePhotoListCallback);
				else
					sendXmlHttpRequest("post", this.fotosActions, vars, this.deletePhotoCallback);
			} catch (e) {
				alert(e);
			}
		},
		deletePhotoListCallback : function(jsHttp) {
			eval("var json = " + jsHttp.responseText);
			if (json.Message.Type == "info") {
				document.getElementById("photo_list" + json.deletedid).src = "/img/img_deleted.png";
			} else {
				alert(json.Message.Type + ":\n" + json.Message.Text);
			}
		},
		deletePhotoCallback : function(jsHttp) {
			eval("var json = " + jsHttp.responseText);
			alert(json.Message.Type + ":\n" + json.Message.Text);
			if (json.Message.Type == "info")
				location.href = "/Search?user=" + json.login; 
		}
	
	}
