var rootLocation, globalSort, skipItems;
var loading = false,
lastScrollTop = 0,
defaultTexts = {
title: 'Название',
email: 'E-mail для связи',
imprText : 'Описание'
};
var handler = null;
function loadFullImpression(imprId, sortPopularity) {
$('#impression_popup #loadArea').html('
');
$('#impression_popup').show();
$('#impression_popup #loadArea').load('/contest/more/impression', {impressionId : imprId, sort: (sortPopularity ? "popular" : "")}, function(response, status, xhr) {
if(status == "success") {
if(response == '') {
alert('Отзыв не найден!');
} else {
$('body').addClass('noscroll');
}
$('#af_RIGHT_240x400').attr('src', $('#af_RIGHT_240x400').attr('src'));
var url = rootLocation + '/' + imprId;
if (globalSort != '') url += "?sort=" + globalSort;
if ("pushState" in history)
history.pushState("", document.title, url);
else {
window.location.href = url;
}
}
});
}
function revertUrl() {
var url = rootLocation;
if (globalSort != '') url += "?sort=" + globalSort;
if("pushState" in history)
history.pushState("", document.title, url);
else {
window.location.href = url;
}
}
$(function() {
InputHelper.Create("#title", defaultTexts.title);
InputHelper.Create("#impressionText", defaultTexts.imprText);
InputHelper.Create("#email", defaultTexts.email);
$('#title, #impressionText, #email').bind('change keypress', function() {
$(this).removeClass('error_input');
});
$('.fileUploadInput').bind('change', function() {
$('.file_wrap').css('color', '');
});
$('#menu li').click(function(){
$('#menu li.act').removeClass('act');
$('.menu_cnt').hide();
var el = $(this);
el.toggleClass('act');
$('#' + el.attr('id') + '_cnt').toggle();
});
var headerFixed = false;
$(window).bind('scroll', function(){
var top = $(window).scrollTop(),
maxStep = parseInt(1550 - $(this).height()),
n = parseInt(top / 2);
if(n >= 310 && !headerFixed){
headerFixed = true;
$("#header_wrap").addClass('fixed');
$('#up').show();
$('#layout').css('margin-top', '150px');
}else if(n < 310 && headerFixed){
headerFixed = false;
$("#header_wrap").removeClass('fixed');
$('#up').hide();
$('#layout').css('margin-top', '0');
}
if(n > maxStep)
n = maxStep;
$('#more_bg').css('background-position','center -' + n + 'px');
onScroll();
});
$('#up').click(function(){
$('body,html').animate({scrollTop: 0}, 300);
return false;
});
$('#impression_popup .modal_wrapper').bind('click', function(e){
var obj = e.target;
if(obj && ($(obj).parents('.impression_frame').size() == 0 || $(obj).parent('.close').size() == 1 )) {
hide_popup();
}
});
var options = {
autoResize: true, // This will auto-update the layout when the browser window is resized.
container: $("#impressions_list"), // Optional, used for some extra CSS styling
offset: 20, // Optional, the distance between grid items
itemWidth: 281 // Optional, the width of a grid item
};
// Call the layout function.
handler = $('#impressions_list .impression');
handler.wookmark(options);
// Destination suggest
impression_suggester.init();
InputHelper.Create("#impression_suggest", 'Где было сделано фото');
$('#impression_suggest').focus(function(){
$(this).css('color', '#000');
});
})
function hide_popup(){
$('#impression_popup').hide();
$('#impression_popup_img').attr('src','');
$('body').removeClass('noscroll');
revertUrl();
}
function onScroll(event) {
var options = {
autoResize: true, // This will auto-update the layout when the browser window is resized.
container: $("#impressions_list"), // Optional, used for some extra CSS styling
offset: 20, // Optional, the distance between grid items
itemWidth: 281 // Optional, the width of a grid item
};
// Check if we're within 100 pixels of the bottom edge of the broser window.
var closeToBottom = ($(window).scrollTop() + $(window).height() > $(document).height()-300);
if(closeToBottom) {
var st = $(window).scrollTop();
if (st > lastScrollTop){
if(!loading && skipItems) {
loading = true;
$.ajax({
url : '/contest/more/loadmore',
type : 'POST',
data : { skip: skipItems, sort : globalSort },
success: function(data, textStatus, jqXHR) {
loading = false;
if(data.result.skip == -1)
skipItems = false;
if(data.result && data.result.items && data.result.items.length > 0) {
for(idx in data.result.items) {
$("#impressionItemTemplate").template("impressionItem");
$.tmpl("impressionItem", data.result.items[idx]).appendTo("#impressions_list");
}
if(data.result.skip) {
skipItems = data.result.skip;
}
}
// Clear our previous layout handler.
if(handler) handler.wookmarkClear();
// Create a new layout handler.
handler = $('#impressions_list .impression');
handler.wookmark(options);
}
});
}
}
lastScrollTop = st;
}
}