$(function(){$('.form_error').fadeIn();});function showLoginPopup()
{var offset=$('#loginButton').offset();$('#loginPopup')
.css('left', offset.left - 155)
.css('top', offset.top+18)
.show();$('#loginButton').attr('src', HOST_BASE+'img/photo/button_login_toggle.gif');$(window).scrollTop(0);}
function hideLoginPopup()
{$('#loginPopup').hide();$('#loginButton').attr('src', HOST_BASE+'img/photo/button_login.gif');}
function toggleLoginPopup()
{if ($('#loginPopup').css('display')=='none')
showLoginPopup();else
hideLoginPopup();}
var photo_rotate_block=false;function postPhotoRotate(post_id, direction)
{if (!photo_rotate_block)
{photo_rotate_block=true;$('.photo_rotate_arrow').fadeTo('fast', 0.5);var params=new Object;params.action='PhotoEdit';params.post_id=post_id;params.edit='rotate';params.direction=direction;$('#photoRorateProgress_'+post_id).show();$('#photoLarge_'+post_id).load(function(){$('#photoRorateProgress_'+post_id).hide();photo_rotate_block=false;$('.photo_rotate_arrow').fadeTo('fast', 1);});$.post(script_url, params, postPhotoRotateCallback,'json');}}
function postPhotoRotateCallback(response)
{if (response.status=='ok')
{$('#photoSlider_'+response.post.post_id).attr('src', response.post.photo_slider);$('#photoLarge_'+response.post.post_id).attr('src', response.post.photo_large);$('#photoXLarge_'+response.post.post_id).attr('href', response.post.photo_xlarge);}}
function postPhotoRemove(post_id, redirect)
{var params=new Object;params.action='PhotoEdit';params.post_id=post_id;params.edit='remove';params.redirect=redirect;$.post(script_url, params, postPhotoRemoveCallback,'json');}
function postPhotoRemoveCallback(response)
{if (response.status=='ok')
location.href=response.redirect;}
function postPhotoDeclined(post_id, value)
{var params=new Object;params.action='PhotoEdit';params.post_id=post_id;params.edit='declined';params.value=value;params.noresponse=1;$.post(script_url, params, reloadCallback);}
function postPhotoModerateAdult(post_id, value)
{var params=new Object;params.action='PhotoEdit';params.post_id=post_id;params.edit='moderate_adult';params.value=value;params.noresponse=1;$.post(script_url, params, reloadCallback);}
function postPhotoModerateAuthor(post_id, value)
{var params=new Object;params.action='PhotoEdit';params.post_id=post_id;params.edit='moderate_author';params.value=value;params.noresponse=1;$.post(script_url, params, reloadCallback);}
function postPhotoModerateRating(post_id, value)
{var params=new Object;params.action='PhotoEdit';params.post_id=post_id;params.edit='moderate_rating';params.value=value;params.noresponse=1;$.post(script_url, params, reloadCallback);}
function postPhotoComplainsRemove(post_id)
{var params=new Object;params.action='PhotoEdit';params.post_id=post_id;params.edit='complains_remove';params.noresponse=1;$.post(script_url, params, reloadCallback);}
function postPhotoRateRemove(user_id, object_id)
{var params=new Object;params.action='PhotoRateRemove';params.user_id=user_id;params.object_id=object_id;params.noresponse=1;$.post(script_url, params, reloadCallback);}
function toggleTitleForm(post_id, anchor)
{var offset=$(anchor).offset();$('#labelForm').hide();$('#categoriesList').hide();$('#photoTextForm').hide();$('#photoTitleForm')
.css('top', offset.top+18)
.toggle();$('#photoPostTitleStatus_'+post_id).html('');if ($('#photoTitleForm').css('display')=='block')
document.getElementById('photoPostTitle_'+post_id).focus();}
function postPhotoTitle(post_id, title)
{var params=new Object;params.action='PhotoEdit';params.post_id=post_id;params.edit='title';params.title=title;$.post(script_url, params, postPhotoTitleCallback,'json');$('#photoPostTitle_'+post_id).attr('disabled', true);$('#photoPostTitleStatus_'+post_id)
.html('<img src="'+HOST_BASE+'img/progress.gif" width="12" height="12" align="absmiddle" /> Сохранение названия...')
.show();}
function postPhotoTitleCallback(response)
{if (response.status=='ok')
{$('#photoPostTitleStatus_'+response.post.post_id).html('Название сохранено');$('#photoTitle h1').html(decodeURIComponent(response.post.title_html));$('#photoTitleForm').hide();}else{$('#photoPostTitleStatus_'+response.post.post_id).html('Недопустимое название!');}
$('#photoPostTitle_'+response.post.post_id)
.val(decodeURIComponent(response.post.title))
.attr('disabled', false);}
function toggleTextForm(post_id, anchor)
{var offset=$(anchor).offset();$('#labelForm').hide();$('#categoriesList').hide();$('#photoTitleForm').hide();$('#photoTextForm')
.css('top', offset.top+18)
.toggle();$('#photoPostTextStatus_'+post_id).html('');if ($('#photoTextForm').css('display')=='block')
document.getElementById('photoPostText_'+post_id).focus();}
function postPhotoText(post_id, text, reload)
{var params=new Object;params.action='PhotoEdit';params.post_id=post_id;params.edit='text';params.text=text;$.post(script_url, params, function(response){postPhotoTextCallback(response, reload)},'json');$('#photoPostText_'+post_id).attr('disabled', true);$('#photoPostTextStatus_'+post_id)
.html('<img src="'+HOST_BASE+'img/progress.gif" width="12" height="12" align="absmiddle" /> Сохранение описания...')
.show();}
function postPhotoTextCallback(response, reload)
{if (response.status=='ok')
{if (reload)
{reloadCallback('');return;}else{$('#photoPostTextStatus_'+response.post.post_id).html('Описание сохранено');}}else{$('#photoPostTextStatus_'+response.post.post_id).html('Недопустимое описание!');}
$('#photoPostText_'+response.post.post_id).attr('disabled', false);}
function postPhotoGalleryRemove(gallery_id, photos, new_gallery_id, redirect)
{var params=new Object;params.action='PhotoGalleryEdit';params.gallery_id=gallery_id;params.edit='remove';params.photos=photos;params.new_gallery_id=new_gallery_id;params.redirect=redirect;$.post(script_url, params, postPhotoGalleryRemoveCallback,'json');$('#galleryRemove').html('<img src="'+HOST_BASE+'img/progress.gif" width="12" height="12" align="absmiddle" /> Удаление альбома...');$('#galleryRemoveConfirm').hide();}
function postPhotoGalleryRemoveCallback(response)
{if (response.status=='ok')
location.href=response.redirect;else
reloadCallback('');}
function postPhotoGalleryDefault(gallery_id, default_post_id)
{var params=new Object;params.action='PhotoGalleryEdit';params.gallery_id=gallery_id;params.edit='default';params.default_post_id=default_post_id;$('#photoDefaultPostDiv_'+default_post_id)
.append('<img src="/img/progress.gif" width="12" height="12" align="absmiddle" />');$.post(script_url, params, postPhotoGalleryDefaultCallback,'json');}
function postPhotoGalleryDefaultCallback(response)
{if (response.status=='ok')
{$('#photoGalleryDefaultSmall_'+response.gallery.gallery_id).attr('src', response.gallery.default_post_small);$('#photoDefaultPostDiv_'+response.gallery.old_default_post_id)
.html('<a class="ajax text" onclick="postPhotoGalleryDefault('+response.gallery.gallery_id+', '+response.gallery.old_default_post_id+')">Сделать обложкой</a>');$('#photoDefaultPostDiv_'+response.gallery.default_post_id)
.html('Обложка альбома');}}
function toggleCategoriesList(anchor)
{var offset=$(anchor).offset();$('#labelForm').hide();$('#photoTitleForm').hide();$('#photoTextForm').hide();$('#categoriesList')
.css('top', offset.top+18)
.toggle();$('#categoriesList input[type="checkbox"]').attr('checked', false);$('#categoriesList .checked').attr('checked', true);}
function postPhotoCategories(post_id)
{var categories='';$('#photoCategories_'+post_id+' input[type="checkbox"]')
.each(function(){if (this.checked)
categories=categories+((categories=='')?'':',')+this.value;});var params=new Object;params.action='PhotoCategories';params.post_id=post_id;params.categories=categories;$('#photoCategories_'+post_id)
.html('Рубрика: <img src="'+HOST_BASE+'img/progress.gif" align="absmiddle" width="12" height="12" /> обновление списка')
.load(script_url, params);}
function toggleLabelForm(anchor)
{var offset=$(anchor).offset();$('#categoriesList').hide();$('#photoTitleForm').hide();$('#photoTextForm').hide();$('#labelForm')
.css('top', offset.top+18)
.toggle();$('#labelFormInput').val('');if ($('#labelForm').css('display')=='block')
document.getElementById('labelFormInput').focus();}
function postPhotoLabel(post_id, operation, label)
{var params=new Object;params.action='PhotoLabels';params.post_id=post_id;params.operation=operation;params.label=label;$('#photoLabels_'+post_id)
.html('Теги: <img src="'+HOST_BASE+'img/progress.gif" align="absmiddle" width="12" height="12" /> обновление списка')
.load(script_url, params);}
function loadRatingAuthors(rating, period, anchor)
{if ($('#ratingAuthorsSelected_'+rating).html()!=$(anchor).html())
{$('#ratingAuthorsSelected_'+rating).html($(anchor).html());$('#ratingAuthorsPeriod_'+rating+' a').removeClass('text');$(anchor).addClass('text');$('#ratingAuthorsPeriod_'+rating).hide();var params=new Object;params.action='PhotoRatingAuthors';params.rating=rating;params.period=period;$('#ratingAuthorsList_'+rating)
.load(script_url, params);}}
function postPhotoUserBan(user_id, apply)
{var params=new Object;params.action='PhotoUserBan';params.user_id=user_id;params.apply=apply;params.noresponse=1;$.post(script_url, params, reloadCallback);}
function loadPhotoAuthorStats()
{var params=new Object;params.action='PhotoAuthorStats';$('#photoAuthorStats').load(script_url, params);}
function loadPhotoLastRates()
{var current_time=new Date;if (LOAD_TIME.getTime()+USER_ONLINE_INTERVAL * 1000>current_time.getTime())
{var params=new Object;params.action='PhotoLastRates';$.post(script_url, params, loadPhotoLastRatesCallback);}}
function loadPhotoLastRatesCallback(response)
{if (response)
{$('#photoLastRates').prepend(response);$('#photoLastRates').scrollLeft(95);$('#photoLastRates img').load(function(){$('#photoLastRates').animate({scrollLeft:0}, 1000,'swing');});}}
function postPhotoLabelRemove(label)
{var params=new Object;params.action='PhotoLabelRemove';params.label=label;params.noresponse=1;$.post(script_url, params, reloadCallback);}
function loadPhotoContext(context_id)
{$('#photoContext').hide();var params=new Object;params.action='PhotoContext';$('#photoContext').load(script_url, params, function(response){$('#photoContext').show();});}