$(function(){
if ($("#carousel").length) {
$("#carousel").imagesLoaded(function() {
$('.carouselImg').each(function(){
var origH = $(this).height();
if(origH > 307){
var top = Math.round((origH - 305)/2);
$(this).css('margin-top', '-' + top + 'px');
}
$(this).fadeIn();
});
});
if($('.carouselImg').size() > 1){
$("#carousel").ulslide({
width: 958,
height: 305,
effect: {
type: 'slide', // slide or fade carousel
axis: 'x',
distance: 0
},
statusbar: true,
pager: '#pager span',
autoslide: 4000,
duration: 400
});
}
}
// if($('.carouselImg').length > 0){
// $('.carouselImg').each(function(){
// var origH = $(this).height();
// if(origH > 307){
// var top = Math.round((origH - 305)/2);
// $(this).css('margin-top', '-' + top + 'px');
// }
// });
// }
if($('#poiPhotoGallery') && $('#poiPhotoGallery .photoGalleryImg').length > 1){
$("#poiPhotoGallery").ulslide({
width: 532,
height: 300,
effect: {
type: 'slide', // slide or fade carousel
axis: 'x',
distance: 0
},
statusbar: true,
nextButton: '#next',
prevButton: '#prev',
printCurrentTo: '#currentIndex',
duration: 400,
onAnimateStart: function(i, el){
var source = el.getSlide(this.current).find('.source');
if(source.size() > 0 && source.html().length > 0)
$('#photoGalleryImgSource').html(source.html());
else
$('#photoGalleryImgSource').html('');
}
});
}
if($('#eventPhotoGallery') && $('#eventPhotoGallery .photoGalleryImg').length > 1){
$("#eventPhotoGallery").ulslide({
width: 600,
height: 338,
effect: {
type: 'slide', // slide or fade carousel
axis: 'x',
distance: 0
},
statusbar: true,
nextButton: '#next',
prevButton: '#prev',
printCurrentTo: '#currentIndex',
duration: 400,
onAnimateStart: function(i, el){
var source = el.getSlide(this.current).find('.source');
if(source.size() > 0 && source.html().length > 0)
$('#photoGalleryImgSource').html(source.html());
else
$('#photoGalleryImgSource').html('');
}
});
}
// ответы в викторине
if($('.answer').size() > 0){
$('.answer').click(function(){
var t = $(this);
$('.act.question' + t.data('question')).removeClass('act');
t.addClass('act');
t.find('input').prop('checked', true);
})
}
$('#quizBtn').click(function(){
var answers = $('#quizForm :radio').serializeArray(),
mess = '';
if (answers.length < 10)
mess = '
Для участия в викторине необходимо ответить на все вопросы';
if (!$('#quizAgree').prop('checked'))
mess += 'Вы не подтвердили согласие с правилами проведения викторины';
var essay = $('#quizEssay');
if (essay.val().length == 0) {
mess += 'Поделитесь историей из путешествия';
addErrorEvent(essay);
}
var user = $('#quizUser');
if (user.val().length == 0) {
mess += 'Представьтесь, пожалуйста';
addErrorEvent(user);
}
var email = $('#quizEmail');
if (!$.trim(email.val())) {
mess += 'Укажите email, по которому с вами можно связаться в случае выигрыша';
addErrorEvent(email);
if (mess.length > 0) {
$('#quizMessage').html('').slideDown();
return false;
}
} else {
$.getJSON(
'/visitastrakhan/quiz_answer_check_email',
{email:$('#quizEmail').val()},
function (data) {
if (data.status === 'invalid') {
mess += 'Проверьте правильность email';
addErrorEvent(email);
} else if (data.status === 'duplicate') {
mess = 'Указанный email уже принимает участие в конкурсе';
addErrorEvent(email);
}
if (mess.length > 0) {
$('#quizMessage').html('').slideDown();
return false;
}
$('#quizForm').submit();
}
);
}
return false;
});
//свежие-популярные статьи на главной
$('#articles_last_show').click(function () {
$('#articles_popular_show').removeClass('act');
$('#articles_last_show').addClass('act');
$('#articles_last_container').show();
$('#articles_popular_container').hide();
return false;
});
$('#articles_popular_show').click(function () {
$('#articles_popular_show').addClass('act');
$('#articles_last_show').removeClass('act');
$('#articles_last_container').hide();
$('#articles_popular_container').show();
return false;
});
//статьи - "раскрыть больше"
$('#articles_more').click(function() {
$.get(
$(this).attr('href'),
{"js":1},
function(data) {
$('#articles_container').html(data);
}
);
return false;
});
});
function checkEmail(email){
var emailTest = "^[_.0-9a-z-]+@([0-9a-z][0-9a-z_-]+.)+[a-z]{2,4}$";
var regex = new RegExp(emailTest);
if (regex.test(email.toLowerCase()))
return true;
return false;
}
function addErrorEvent(obj){
obj.parent().addClass('ym-error');
if(!obj.data('error')){
obj.bind('change keyup', function(){
if($(this).val().length > 0){
$(this).parent().removeClass('ym-error');
}else{
$(this).parent().addClass('ym-error');
}
})
obj.data('error', 'addEvent');
}
}