function __c() {
	if(typeof console != 'undefined') console.log(arguments);
}

Prototype.Browser.IE6 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 6;

var pph = PhotoPerlHost();
var pch = PhotoContentHost();
var isfav = spHash['album_id'] == '_favorites' ? true : false;
/*
function incook(param,user_email,album_id,noadd) {
	var cookie = GetGlobalCookie();
	var photo_id = document.getElementById('photoid').value;
	var arr = [photo_id];

	if (!noadd) {
		if (param) {//add
			var obj_photo = get_photo_count();
			if (obj_photo.count_photo < Max_photo) {
				cookie = PrepareCookie(cookie,0,photo_id,user_email,album_id);//add
	            if(typeof spot == 'undefined'){
					if (gebi("blockForPhotoId")) gebi("blockForPhotoId").className = "block_photo2 for_print";
					if (gebi("blockForPhotoId2")) gebi("blockForPhotoId2").className = "for_print2";
				} else {
					if (gebi("blockForPhotoId")) gebi("blockForPhotoId").className = "block_photo2 for_print";
					if (gebi("blockForPhotoId2")) gebi("blockForPhotoId2").className = "for_print2";
				    if (gebi("addin_cook")) gebi("addin_cook").style.display = "none";
					if (gebi("delfrom_cook")) gebi("delfrom_cook").style.display = "";
				}
				if (gebi("addin_cook")) gebi("addin_cook").style.display = "none";
				if (gebi("delfrom_cook")) gebi("delfrom_cook").style.display = "";
				add_photo(user_email,album_id,arr);
			} else {
				alert(alert_photo_limit);
			}
		} else {//del
			cookie = PrepareCookie(cookie,1,photo_id,user_email,album_id);//del
			if(typeof spot == 'undefined'){
				if (gebi("blockForPhotoId")) gebi("blockForPhotoId").className = "block_photo2";
				if (gebi("blockForPhotoId2")) gebi("blockForPhotoId2").className = "";
			} else {
				if (gebi("blockForPhotoId")) gebi("blockForPhotoId").className = "block_photo2";
				if (gebi("blockForPhotoId2")) gebi("blockForPhotoId2").className = "";
				if (gebi("addin_cook")) gebi("addin_cook").style.display = "";
				if (gebi("delfrom_cook")) gebi("delfrom_cook").style.display = "none";
			}
			if (gebi("addin_cook")) gebi("addin_cook").style.display = "";
			if (gebi("delfrom_cook")) gebi("delfrom_cook").style.display = "none";
			delete_photo(user_email,arr);
		}
	}
	set_cookie('photoprint',cookie,null,'/',cookie_domain);
	show_menu();
	return false;
}


function incook_fromcookie(user_email,album_id,noadd) {
    var cookie = GetGlobalCookie();
	if (cookie != null) {
		var user = new Array;
		user = cookie.split(user_delimiter);
		var photo_id =  document.getElementById('photoid').value;
		for (var i=0;i<user.length;i++) {			
			var photo = new Array;
			photo = user[i].split(photo_delimiter);
			if(photo[0]!=user_email) continue;

			for (var j=1;j<photo.length;j++) {
				if(photo[j]=='') continue;
				var prop = new Array;
				prop = photo[j].split(property_delimiter);
				//album,photoid,count,format,paper[0-glossy,1-mat],fields[0-no,1-yes]
				if (prop[1]==photo_id) {
				   incook(true,user_email,album_id,noadd);
				   if (gebi("blockForPhotoId")) gebi("blockForPhotoId").className = "block_photo2 for_print";
				   if (gebi("blockForPhotoId2")) gebi("blockForPhotoId2").className = "for_print2";
				   if (gebi("addin_cook")) gebi("addin_cook").style.display = "none";
				   if (gebi("delfrom_cook")) gebi("delfrom_cook").style.display = "";
				   break;
				}
				else {
					if(typeof spot != 'undefined') {
						incook(false,user_email,album_id,noadd);
						if (gebi("blockForPhotoId")) gebi("blockForPhotoId").className = "block_photo2";
						if (gebi("blockForPhotoId2")) gebi("blockForPhotoId2").className = "";
						if (gebi("addin_cook")) gebi("addin_cook").style.display = "";
						if (gebi("delfrom_cook")) gebi("delfrom_cook").style.display = "none";
					}
				}					
			}
		}
	}
}
*/
function newFotoNameCallback (newname,imageid) {
	if (imageid) {
		if (newname == undefined || newname == null || newname == '') {
			newname = 'Без названия';
		}
		gebi('imageTitle').innerHTML = newname ;
		if (gebi('path_image_title')) gebi('path_image_title').innerHTML = newname;
		hideFotoNameDialog('imageTitle', 'Name');
		if (gebi('ExtAuthor')) {gebi('ExtAuthor').style.display='';}
	} else {
		alert ('Ошибка');
	}
	setTooltip("imageTitle",newname); 
	
	if(typeof spot != 'undefined') {
		t2hash[curHash.ImgId]['Title'] = newname;
		curHash['Title'] = newname;
	}
}

function addVote(mark, image_id, album_id) {
	//var block_vote = BlockVote();
	var block_vote = false;
	var activeUserDomain = ActiveUserMail();
	if ((curHash.OwnerItem && !spHash.FotoComm && !spHash.extfoto) || (spHash.FotoComm && (curHash.Owner == activeUserDomain))) {
		block_vote = true;
	}
	
	rating+=mark;
	
	if(typeof spot == 'undefined') {
		if (voted) {
			alert('Вы уже проголосовали за фото');
			return;
		}
	}else {
		if (curHash.Voted) {
		alert('Вы уже проголосовали за фото');
		return;
		}
	}
	
	if (block_vote) {
		alert('Вы не можете голосовать за собственное фото');
		return;
	}

	var answer='';
	if(need_capcha){
		capcha_mark = mark;
		answer=gebi('security_image_answer').value;
		if(answer == '' || check_capcha_result != 1){
			var st = FreshVoteCapcha(mark);
		}
		return;
	}

	ClearCapchaParams();

	var st=ajax_call('perl_add_vote',mark,image_id,album_id,capcha_id,answer,addVoteCallback);
	if (!st) {
		alert('Проголосовать не получилось');
	} else {
		hideObject(gebi('image_Rate_Vote_Access'));
		gebi('vote_message').style.display='block';
		gebi('vote_message').innerHTML=vote_message_process;
	}
}


function addVoteCallback (st,newrating,votescount,errorcode,errortext) {
	if (st==1) {
		if(typeof spot == 'undefined') voted=true; else t2hash[curHash.ImgId].Voted = true;
		gebi('image_Rate').innerHTML=newrating;

		if (gebi('image_VotesCount'))
		gebi('image_VotesCount').innerHTML=votescount;

		gebi('vote_message').innerHTML=vote_message_thank;
		
		if(typeof spot != 'undefined') {
			curHash.Rate = newrating;
			curHash.Votes = votescount;
		}
		
	} else {
		if (errorcode==2 || errorcode==4 || errorcode==9 || errorcode==11) {
			if(typeof spot == 'undefined') voted=true; else t2hash[curHash.ImgId].Voted = true;
			gebi('vote_message').innerHTML = errortext;
		}else if (errorcode==3) {
			alert('Неверно введён код защиты');
			ClearCapchaParams();
			var mark = capcha_mark;
			var st = FreshVoteCapcha(mark);
		}else{
			if(typeof spot == 'undefined') voted=true; else t2hash[curHash.ImgId].Voted = true;
			gebi('vote_message').innerHTML=errortext;
		}
	}
}

function AddCommentCallback(st,errorcode,errortext,ref,page)
{
	if (st==1)
	{
		last_userapprove = 0;

		
			if(ref != undefined && ref != ''){ 
//					window.location.replace(ref);
				if(typeof spot == 'undefined') 
					document.location = ref;
				else 
					document.location = 'http://' + pph + spHash.CurBox + spHash.album_id + '/' + curHash.ImgId;
//					window.location.href = ref;	
				return;
			}
			else window.location.reload(true);
		
	}
	else
	{
		if(errorcode == 2 || errorcode == 3)
		{
			FreshCapchaComment();
			if(errorcode == 3){	alert(errortext); };
			return;
		}
		if(errorcode == 4) {
			if(confirm(errortext)) {
				last_userapprove = 1;
				var ob = gebi('sub_but');
				if(ob){
					ob.onclick();
				}else{
					FreshCapchaComment();
				}
				return;
			}else{
				commentRepHide()
			};
			return;
		}
		if(errorcode == 5) {
			alert(errortext);
			commentRepHide()
			return;
		}
		alert('Добавить комментарий не получилось: '+errortext);
		ShowSendButton('sub_but');
		ClearTempVars();
	}
}


var _getSkinId = function(link){
	var _m = link.match(/^http:\/\/img.imgsmail.ru\/mail\/ru\/css\/skins\/([0-9a-zA-Z]+).css.*$/);
	if(_m != null){
		return _m[1];
	} else {
		return -1;
	}
}

var _isSkinId = function(id){
	var _head = document.getElementsByTagName('head')[0];
	var _links = _head.getElementsByTagName('link');
	for (var i = 0; i < _links.length; i++){
		var _link = $(_links[i]);
		var _rel = _link.readAttribute('rel');
		var _href = _link.readAttribute('href');
		if(_link && _rel && _rel == 'stylesheet' && _href && _getSkinId(_href) == id){
			return true;
		}
	}
	return false;
}

var _removeSkins = function(){
	if(arguments.length > 0){
		var _except = arguments[0];
	} else {
		var _except = -1;
	}

	var _head = document.getElementsByTagName('head')[0];
	var _links = _head.getElementsByTagName('link');
	for (var i = 0; i < _links.length; i++){
		var _link = $(_links[i]);
		var _rel = _link.readAttribute('rel');
		var _href = _link.readAttribute('href');
		if(_link && _rel && _rel == 'stylesheet' && _href && _getSkinId(_href) != -1){
			if(_except == -1 || _getSkinId(_href) != _except){
				_head.removeChild(_link);
			}
		}
	}
}

var _addSkin = function(i){
	_removeSkins(i);
	if(!_isSkinId(i)){
		var _head = document.getElementsByTagName('head')[0];
		var _link = document.createElement('link');
		_link.rel = 'stylesheet';
		_link.type = 'text/css';
		_link.href = 'http://img.imgsmail.ru/mail/ru/css/skins/' + i + '.css';
		_head.appendChild(_link);
	}
}

function checkImmunity(i) {
	if (spHash.immunity == '1') { 
		if(spHash.photomoderator == '1') 
			alert('Пользователь защищен'); 
		else 
			CommentComplainCallback([1,i])
		
		return false;
	}
	else return true;
}

function spot2_envUpdate() {
	/* _fav bug */
	if(typeof window['addedtofav'] != 'undefined'){
		addedtofav = false;
	}

	var cid = curHash['ImgId'];
	if (typeof curHash['Title'] == 'undefined' || curHash['Title'] == '') { curHash['Title'] = "Без названия"; }

	/*imageTitle*/
	if (curHash.OwnerItem && !spHash.extfoto && !isfav) {
		$('imageTitle')
			.update(curHash['Title'])
			.stopObserving('click')
			.observe('click', function() {
				showFotoNameDialog(cid,'imageTitle', 'Name');
				gebi('fotoNameFormId').elements['edit'].focus();
			}
			.bind(this));
		$$('#fotoNameFormId input[name=image_id]')[0].value = cid;
		$$('#fotoNameFormId input[name=edit]')[0].value = curHash.Title;
		if(typeof curHash['Title'] != 'undefined') setTooltip("imageTitle", curHash['Title']);
		hideFotoNameDialog('imageTitle', 'Name');
		if (spHash.FotoComm) {
			$('spot2-title').hide();
			$('imageTitle').show();
		}
	}
	else {
		$('spot2-title').update(curHash['Title']);
		if (spHash.FotoComm) {
			$('imageTitle').hide();
			$('spot2-title').show();
		}
	}

	/*фото в альбоме автора*/
	if (isfav) {
		$$('#spot2-fav-album a')[0].writeAttribute('href', 'http://' + pph + '/' +  curHash['FavPath'] + '/' + curHash['FavId'] + '.html');
	}

	/*автор ext фото*/
	if (spHash.extfoto) {
		$('spot2-ext-agent')
			.writeAttribute('href', 'http://www.mail.ru/agent?message&to=' + curHash.ExtEmail)
			.select('img')[0].writeAttribute('src', 'http://status.mail.ru/?' + curHash.ExtEmail);
		$('ExtAuthor').hide();
	}

	/*автор фото сообщества*/
	if (spHash.FotoComm && ($('spot2-comm-agent'))) {
		$('spot2-comm-agent')
			.writeAttribute('href', 'http://www.mail.ru/agent?message&to=' + curHash.Owner)
			.select('img')[0].writeAttribute('src', 'http://status.mail.ru/?' + curHash.Owner);
		$('CommAuthor').hide();
	}

	/*fub menu*/
	var editMenu = $$('.s-fub-menu .spr_medit a')[0];
	if(editMenu) editMenu.href = editMenu.href.replace(/id=[0-9]+/gi,"id="+cid);
	var delMenu = $$('.s-fub-menu .spr_mdelete a')[0];
	if(delMenu)delMenu.href = delMenu.href.replace(/id=[0-9]+/gi,"id="+cid);

	if (spHash.FotoComm) {
		var medit = $('spr_medit');
		var mdelete = $('spr_mdelete');
		if (curHash.OwnerItem) {
			medit.show();
			mdelete.show();
		}
		else {
			medit.hide();
			mdelete.hide();
		}
	}

	if(spHash.immunity != '1') {
		if (!((spHash.FotoComm && curHash.OwnerItem) || curHash.myExtFoto)) {
			var complain = $('PhotoComplainLink');
			if (complain) {
				complain
					.writeAttribute('onclick', '')
					.stopObserving('click')
					.observe('click', function() {
						ajax_call('perl_photo_complain', cid, PhotoComplainCallback);
						return false;
					}.bind(this));
			}
			else {
				var complainBlock = $$('.complainBlock')[0];
				if(complainBlock) 
					complainBlock
						.update('')
						.insert(
							new Element('a', { 'id' : 'PhotoComplainLink', 'class' : 'spr spr_complain', 'href' : 'javascript:void(0)'})
								.update('Сообщить о нарушении')
								.observe('click', function() {
									ajax_call('perl_photo_complain', cid, PhotoComplainCallback);
									return false;
								}.bind(this))
						)
			}
			var mmoder = $('spr_mmoder');
			if (mmoder) {
				if (!curHash.OwnerItem && !curHash.myExtFoto) {
					mmoder.show();
				} else {
					mmoder.hide();
				}
			}
		}
	}

	/*arrows*/
	var prevArr = $('previous_page');
	if(prevArr) {
		if(t2Array.indexOf(cid) == 0)
			prevArr.hide();
		else {
				prevArr.show();
				if(Prototype.Browser.IE6) {
					prevArr.style.height = curHash.Height + 'px';
					prevArr.style.height = curHash.Height + 'px';
				}
			}
	}
	
	var nextArr = $('next_page');
	if(nextArr) {
		if(t2Array.indexOf(cid) == t2Array.length - 1)
			nextArr.hide();
		else {
				nextArr.show();
				if(Prototype.Browser.IE6)  {
					nextArr.style.height = curHash.Height + 'px';
					nextArr.style.height = curHash.Height + 'px';
				}
			}
	}
	
	/*main img*/
	if(Prototype.Browser.IE6)  {
		$('imgwrap2').style.width = curHash.Width + 'px';
	}
	
	/*fotoinfo*/
	$('spot2-fotoinfo-link')
		.stopObserving('click')
		.observe('click', spot.getinfo);
	$('ft_info').hide();
	$('PhotoInfoBlock').update('');
	
	/*skins*/
	
	var _pSkin = -1;
	if(spHash['getstyle'] != '' && spHash['ownerItem'] == true){
		_pSkin = spHash['getstyle'];
	} else if (typeof curHash['ContestId'] == 'string' && curHash['ContestId'] == '310'){
		_pSkin = 'Lays';
	} else if (typeof curHash['Skin'] != 'undefined' && curHash['Skin'] != ''){
		_pSkin = curHash['Skin'];
	} else if (typeof spHash['albumskin'] != 'undefined' && spHash['albumskin'] != ''){
		_pSkin = spHash['albumskin']
	}

	if(_pSkin != -1){
		$('div_skin').writeAttribute('class', 'skin_foto skin_foto' + _pSkin);
		_addSkin(_pSkin);
		$('blockForPhotoId').setStyle({'paddingBottom' : '0'});
	} else {
		$('blockForPhotoId').setStyle({'paddingBottom' : ''});
		$('div_skin').writeAttribute('class', '');		
	}
	
	if($('image_skin')) $('image_skin').setValue = _pSkin;	
	

	/*photoprint*/
	/*
	$('photoid').setValue(cid);
	
	if(spHash.activeuserid != '' && spHash.album_id != "_favorites" && spHash.album_id != "_animated" && spHash.album_id != "_animateddialog") {
		incook_fromcookie(spHash.photouser + '@' + spHash.photodomain,spHash.album_id,'1');
	}
	*/
	
	/*persons*/
	$$('.allocation').each(function(a) {if(a.id.match(/pers_/)) a.remove();});
	
	/*megavote*/
	if(typeof curHash['DoubleVotes'] != 'undefined' && curHash['DoubleVotes'] != '') {
		$('MegaVoteIco').show();
		megavoters.remove();
		megavoters.init((typeof curHash['ExtId'] != 'undefined' && curHash['ExtId'] != '') ? curHash['ExtId'] : curHash['ImgId'], spHash.activeuser, spHash.CurBox);
		
		
		
		$('LeftMenu').setStyle({'marginTop': '80px'});
	}
	else {
		$('MegaVoteIco').hide();
		megavoters.remove();
		$('LeftMenu').setStyle({'marginTop': ''});
	}
	
	/*sizes*/
	if(!(curHash.Width != '' && curHash.Height != '')) $$('#LeftMenu .i1')[0].setStyle({'height' : '22px'}); else $$('#LeftMenu .i1')[0].setStyle({'height' : ''});
	if(curHash.SSize != 0 && curHash.SWidth != 0 && curHash.Width < curHash.SWidth) {
		$$('#LeftMenu .i1 a')[0].writeAttribute('href', 'http://' + pph + spHash.CurBox + spHash.album_id + '/s-' + curHash.ImgId + '.' + (curHash.Ext != '' ? curHash.Ext : "jpg") + (curHash.Rnd != '' ? curHash.Rnd : ''))
		$$('#LeftMenu .i1 span')[0].update(curHash.SWidth + '<br/>x<br/>' + curHash.SHeight);
		$$('#LeftMenu .i1')[0].show();
	}else {
		$$('#LeftMenu .i1 a')[0].writeAttribute('href', '')
		$$('#LeftMenu .i1 span')[0].update('');
		$$('#LeftMenu .i1')[0].hide();
	}
	
		
	/*rating*/
	$('image_Rate').update(curHash.Rate);
	if(spHash.viewvoteaccess) {
		if(curHash.Votes != 0) {
			$('image_VotesCount')
				.update(curHash.Votes)
				.writeAttribute('href', $('image_VotesCount').href.replace(/id=\d*$/, "id=" + curHash.ImgId));
			$('total_voted').show();
		}
		else 
			$('total_voted').hide();
	}else {}
	
	/*awards*/
	if(curHash.Awards && $('Awards')) {
		$('Awards').show();
		if(curHash.Rate > 500) { //медали
			var awardId, awardTitle;
			
			if(curHash.Rate > 2500) 		{awardId = 0; awardTitle = "Золотой фонд Фото@Mail.Ru"}
			else if(curHash.Rate > 1000)	{awardId = 1; awardTitle = "Серебряный фонд Фото@Mail.Ru"}
			else if(curHash.Rate > 500) 	{awardId = 2; awardTitle = "Бронзовый фонд Фото@Mail.Ru"};
			
			$('spot2-medal').show();
			$$('#spot2-medal a')[0]
				.writeAttribute('title', awardTitle)
				.writeAttribute('onclick', '')
				.stopObserving('click')
				.observe('click', awardHelp.bindAsEventListener(this, $$('#spot2-medal a')[0], awardId ,'','', ''))
				.select('img')[0]
					//.writeAttribute('src','http://img.imgsmail.ru/r/foto2/award_rate'+(awardId+1)+'.gif')
					.removeClassName('spr_awrate1')
					.removeClassName('spr_awrate2')
					.removeClassName('spr_awrate3')
					.addClassName('spr_awrate' + (awardId+1))
					.writeAttribute('alt', awardTitle);
		}else {$('spot2-medal').hide();}
		
		if(curHash.AvgMark > 4.5) { //блестяшки
			var avgId, avgTitle;
			
			if(curHash.AvgMark > 4.9) 		 { avgId = 3; avgTitle = "Великолепное фото";}
			else if(curHash.AvgMark > 4.8) 	 { avgId = 4; avgTitle = "Прекрасное фото";}
			else if(curHash.AvgMark > 4.5) 	 { avgId = 5; avgTitle = "Отличное фото";}
			
			$('spot2-avgmark').show();
			
			$$('#spot2-avgmark a')[0]
				.writeAttribute('title', avgTitle)
				.writeAttribute('onclick', '')
				.stopObserving('click')
				.observe('click', awardHelp.bindAsEventListener(this,$$('#spot2-avgmark a')[0], avgId ,'','', curHash.AvgMark))
				.select('img')[0]
					//.writeAttribute('src','http://img.imgsmail.ru/r/foto2/award_mark'+(avgId-2)+'.gif')
					.removeClassName('spr_awmark1')
					.removeClassName('spr_awmark2')
					.removeClassName('spr_awmark3')
					.addClassName('spr_awmark' + (avgId - 2))
					.writeAttribute('alt', avgTitle);
			
			
		}else {$('spot2-avgmark').hide();}
		
		if(curHash.DayphotoWinnerpos != 0) { //фото дня
			var medal, medalTitle;			
			
			if(curHash.DayphotoWinnerpos == 1)		 	{medal = "gold"; medalTitle = curHash.DayphotoWinnerpos + "-е место &laquo;Фото дня&raquo;";}
			else if(curHash.DayphotoWinnerpos == 2) 	{medal = "silver";medalTitle = curHash.DayphotoWinnerpos + "-е место &laquo;Фото дня&raquo;";}
			else if(curHash.DayphotoWinnerpos == 3) 	{medal = "bronze";medalTitle = curHash.DayphotoWinnerpos + "-е место &laquo;Фото дня&raquo;";}
			else if(curHash.DayphotoWinnerpos > 3 && curHash.DayphotoWinnerpos < 21) 	{medal = "honour";medalTitle = curHash.DayphotoWinnerpos + "Лучшая двадцатка &laquo;Фото дня&raquo;";}
			
			$$('#spot2-dayphotowin a')[0]
				.writeAttribute('href', $$('#spot2-dayphotowin a')[0].href.replace(/ymd=\d*/gi, "ymd=" + curHash.DayphotoYMD))
				.select('img')[0]
					//.writeAttribute('src', 'http://img.imgsmail.ru/r/foto2/sign_medal_' + medal + '.gif')
					.removeClassName('spr_awgold')
					.removeClassName('spr_awsilver')
					.removeClassName('spr_awbronze')
					.removeClassName('spr_awhonour')
					.addClassName('spr_aw' + medal)
					.writeAttribute('alt', avgTitle);
				
			
			$('spot2-dayphotowin').show();

		}else {$('spot2-dayphotowin').hide();}
		
		if(curHash.WasSMSLast != 0) $('spot2-smslast-ico').show(); else $('spot2-smslast-ico').hide()
		if(curHash.WasLeader != 0) $('spot2-wasleader-ico').show(); else $('spot2-wasleader-ico').hide()	
	}
	
	/*sms игры*/
	InfoBlock.initSMSHelp(pph,spHash.photouserid,spHash.activeuserid, (curHash.ExtId ? curHash.ExtId : curHash.ImgId), spHash.album_id);
	
	/*голосование*/
	if(spHash.muchestimate) {
		$$('.estimate a').each(function(a) {a.writeAttribute('href',a.href.replace(/id=\d*$/, 'id=' + curHash.ImgId))});
	}
	else if(!spHash.contestnovote && spHash.voteaccess) { 
		$('vote_message')
			.hide()
			.update('');
		
		$('image_Rate_Vote_Access')
			.setStyle({'visibility' : 'visible'})
			.show();
			
			$$('.spot2-vote a').each(function(a, i){ 
				a.writeAttribute('onclick', '')
				 .stopObserving('click')
				 .observe('click', function() {hide2x();addVote(i+1, curHash.ImgId, spHash.album_id);return false});
			});
	}
	
	/*comments*/
	$('place_bottom').update('');
	$('spot2-comments').update('');
	
	/*like photos*/
	$('ft_liked').hide();
	if(imgpre.getObject('likePhoto').inited) showLikePhoto('likePhoto');
	imgpre.getObject('likePhoto').inited = false;
	image_id_createLikePhoto = curHash.ImgId;
	
	/*dayphoto*/
	curHash.dayphotobegintime  = parseInt(curHash.dayphotobegintime);
	curHash.dayphotoendtime = parseInt(curHash.dayphotoendtime);
	curHash.dayphotopos = parseInt(curHash.dayphotopos);
	curHash.dayphotoposdelta = parseInt(curHash.dayphotoposdelta);
	
	if(
		(!!curHash.dayphotoendtime && curHash.dayphotoendtime > spHash.currenttime) && 
		(!!curHash.dayphotobegintime && curHash.dayphotobegintime < spHash.currenttime || curHash.dayphotobegintime == spHash.currenttime) && 
		(!!curHash.dayphotopos && curHash.dayphotopos != 0) 	
	){
		$('spot2-dayphoto-link').writeAttribute('href', $('spot2-dayphoto-link').href.replace(/pos=\d*\&image_id=\d*/gi, 'pos=' + curHash.dayphotopos + '&image_id=' + curHash.ImgId));
		
		var sign_growth = 0;
		
		if(!!curHash.dayphotoposdelta) {
			if(curHash.dayphotoposdeltaimg == 'down')  sign_growth = 'sign_growth_down';
			if(curHash.dayphotoposdeltaimg == 'up') sign_growth = 'sign_growth_up';
		}
		
		if(curHash.dayphotoposdeltaimg == 'new') directionGrowth = 'new';
		
		if(!!curHash.dayphotopos) $('spot2-dayphoto-pos').update(curHash.dayphotopos + '-е место').show();
		if(!!curHash.dayphotoposdelta && !!sign_growth) {
			$('spot2-dayphoto-growth').writeAttribute('src', 'http://img.imgsmail.ru/r/foto2/' + sign_growth + '.gif').show();
			$('spot2-dayphoto-delta').update(curHash.dayphotoposdelta).show();
		}
		if(curHash.dayphotoposdeltaimg == 'new') $('spot2-dayphoto-new').show();
		
		$('spot2-dayphoto').show();
	}
	else {
		$('spot2-dayphoto-pos').hide();
		$('spot2-dayphoto-growth').hide();
		$('spot2-dayphoto-delta').hide();
		$('spot2-dayphoto-new').hide();
		$('spot2-dayphoto').hide();
	}
	
		
	/*mainmenu*/
	
	//m1
	if(spHash.album_id != '_favorites' && spHash.album_id != '_animated' && spHash.album_id != '_animateddialog')
		if($('txtarForAddToFavorId')) $('txtarForAddToFavorId').setValue('');
	else {}
	
	//m2
	if(spHash.album_access == 2) {
		if(spHash.activeuser) {
			CurrentImageId = function() {
				return cid;
			}
		}
		else $('link_addFriend_li').writeAttribute('href', 'http://' + pph + '/cgi-bin/login?noclear=1&amp;page=http%3A%2F%2F' + pph + spHash.CurBox + spHash.album_id + '%2F' + curHash.ImgId + '%3Fshow_addfriend%3D1');
	
	
	var sendlink = $$('#SendCard a')[0];
	if(spHash.album_id != '_quarantine' && curHash.Theme != 4 && curHash.Theme != 35) {
		$('SendCard').show();
		sendlink.writeAttribute('href', sendlink.href.replace(/i\-(\d*)\.(jpg|gif)/gi, function(s,i,r) {return 'i-' + cid + '.' + r})); 
	}else {
		$('SendCard').hide();
		sendlink.writeAttribute('href', '');
	}
		
	}
		
	
	
	//m3
	var _href = "http://" + pph + spHash.CurBox + spHash.album_id + "/" + curHash.ImgId + ".html";
	var _pjpg = "http://" + pph + spHash.CurBox + spHash.album_id + "/" + "p-" + curHash.ImgId + ".jpg";
	var _email = spHash.photouser + "@" + spHash.photodomain;
	var _agent = spHash.FotoComm ? '' : '<a href="http://www.mail.ru/agent?message&amp;to=' + _email + '"><img src="http://status.mail.ru/?' + _email + '" align="absmiddle" width="13" height="13" border="0" alt="Агент@Mail.Ru" /></a>';
	fotoPreview = '<br clear="all" style="line-height:1px;" /><div style="padding-right: 7px; padding-left: 7px; padding-bottom: 7px; padding-top: 17px;"><table cellspacing="0" cellpadding="0" class="fotopre" style="margin:20px 0"><tr><td style="padding:0"><a href="' + _href + '" target="_blank"><img src="' + _pjpg + '" width="' + curHash.PWidth + '" height="' + curHash.PHeight + '" border="0" alt="Увеличить" /></a></td></tr><tr><td class="enlarge" style="padding:0 0 2px 0;background-color:#003B75;font-size:65%;text-align:center"><a href="' + _href + '" target="_blank" style="color:#FFFFFF;font-family:Tahoma">Увеличить</a></td></tr></table>Автор: ' + _agent + '<a href="http://' + pph + spHash.CurBox + '" target="_blank">' + spHash.fio + '</a><br />Альбом: <a href="http://' + pph + spHash.CurBox + spHash.album_id + '" target="_blank">' + spHash.album_name + '</a></div>';
	
	imgurl= isfav ? "http://" + pch + "/" + curHash['FavPath'] + "/i-" + curHash['FavId'] + ".jpg" : "http://" + pch + spHash.CurBox + spHash.album_id + "/i-" + curHash.ImgId + "." + spHash.ext;
	jsimgurl= isfav ? "http%3A%2F%2F" + pch + "%2F" + curHash['FavPath'] + "%2Fi%2D" + curHash['FavId'] + ".jpg" : "http%3A%2F%2F" + pch + spHash.CurBox + spHash.album_id + "%2Fi%2D" + curHash.ImgId + "." + spHash.ext;
	

	if(!!$('html-code')) $('html-code').setValue(fotoPreview);
	if(!!$('url-code')) $('url-code').setValue(imgurl);
	if(!!$('bb-code')) $('bb-code').setValue("[img=" +imgurl + "]");

	//m4
	if ($('spot2-menu-m4')) {
		var isero = (curHash.Theme == '4' || curHash.Theme == '16') ? true : false;
		if (isero) {
			$('spot2-menu-m4').hide();
		} else {
			$('spot2-menu-m4').show();
		}
	}

	//m5
	if ($('spot2-menu-m5')) {
		if (spHash.activeuser != '') 
			$('cropToggle').writeAttribute('href', 'http://' + pph + spHash.CurBox + spHash.album_id + '/' + curHash.ImgId + '?allocationFriends=1'); 
		else 
			$('cropToggle').writeAttribute('href', 'http://' + pph + '/cgi-bin/login?noclear=1&amp;page=http%3A%2F%2F' + pph + spHash.CurBox + spHash.album_id + '%2F' + curHash.ImgId + '%3FallocationFriends%3D1'); 
		try{formNameFriendNameReset()}catch(e){};
	}

	//m6

	//m7
	if ($('spot2-menu-m7')) {
		var mobile_link = "http://www.smsonline.ru/mail/s.cgi?id=4" + (curHash.Theme == 4 ? "&ero=1" : "") + "&f=" + jsimgurl;
		$('spot2-getmobile')
			.writeAttribute('onclick', '')
			.stopObserving('click')
			.observe('click', function() {window.open(mobile_link,'smsonline'+parseInt(Math.random()*10000), 'width=780, height=580, titlebar=no, resizable=no, status=yes, scrollbars=no'); return false}.bind(this));
	}

	//m8
	if(spHash.albumskinaccess != '') {
		if(spHash.ownerItem || curHash.Skin != '' || spHash.albumskin != '') {
			if(spHash.ownerItem) {
                        	$('spot2-skinphoto-link').writeAttribute('href', $('spot2-skinphoto-link').href.replace(/id=[0-9]+/gi,"id="+cid));
				if(!spHash.getstyle && (curHash.Skin || spHash.albumskin)) {
                                	$('spot2-skinphoto-link').update('Изменить оформление');
				} else {
                                	$('spot2-skinphoto-link').update('Оформить<br />фото');
				}
			} else {
			        if($('spot2-skinphoto-same')){
					$('spot2-skinphoto-same').writeAttribute('href', $('spot2-skinphoto-same').href.replace(/skinid=[0-9]+/gi,"skinid="+(curHash.Skin ? curHash.Skin : spHash.albumskin)));
				}
			}
		}	
	}
	
	//m9
	if(spHash.ownerItem && !spHash.FotoComm && !spHash.extfoto) {
		image_ContestId = curHash.ContestId;
		
		if(curHash.ContestId != '') { 
			$('spot2-notnominate-link')
				.writeAttribute('onclick', '')
				.stopObserving('click')
				.observe('click', function() {notNominate(curHash.ImgId, (curHash.Contest ? " «" + curHash.Contest + "»" : "")); return false;});
			
			$('notnominate_li').show();
			$('nominate_li').hide();
		}
		else  { 
			$('notnominate_li').hide();
			$('nominate_li').show();
		}
	}else {}
	
	
	centerMenu();
}
