';
for (var i = 0; i < f.fields.length; i++)
{
var l = f.fields[i], t = '', a = '', s = '';
html += '
';
if (l.label) t = '';
if (l.width) a = ' style="width: ' + l.width + '"';
if (l.placeholder) a += ' placeholder="' + l.placeholder + '"';
if (l.template) a += ' data-template="' + l.template + '"';
if (typeof l.value != 'undefined') a += ' value="' + l.value + '"';
if (l.checked) a += ' checked="checked"';
if (l.disabled) a += ' disabled="disabled"';
if (l.rows) a += ' rows="' + l.rows + '"';
if (l.class) a += ' class="' + l.class + '"';
if (l.type == 'text') html += t + '';
if (l.type == 'email') html += t + '';
if (l.type == 'tel') html += t + '';
if (l.type == 'password') html += t + '';
if (l.type == 'hidden') html += '';
if (l.type == 'textarea') html += t + '';
if (l.type == 'checkbox') html += '' + t;
if (l.type == 'select')
{
html += t + '';
}
html += '
';
}
html += '
' + f.submit + '
'
html += '
';
if (style && style.match(/modal/)) {$('body').append(html)} else {document.write(html)}
var o = $('#' + f.id + '-form');
o.find('input, textarea, select').on('focus blur', function() {$(this).removeClass('alert')});
o.find('.submit, .close').tapHighlight();
$('#' + f.id + '-form.modal').show().stop().animate({opacity: 1}, 500).on('tap', function(event)
{
if ($(event.target).is('.form.modal') && !js.touch) $(this).find('.close').trigger('tap');
});
o.find('.close').on('tap', function()
{
var w = $(this).parent().parent();
w.stop().animate({opacity: 0}, 500, function() {w.remove()});
});
o.find('.submit').on('tap', function() {js.form.submit(f, send)});
o.find('input').keypress(function(event)
{
if (event.which == 13) {o.find('.submit').trigger('tap'); return 0}
});
o.find('[data-template]').on('focus', function() {if (!$(this).val()) $(this).val($(this).data('template'))})
.on('blur', function() {if ($(this).val() == $(this).data('template')) $(this).val('')});
js.trigger.resize();
if (js.touch && style.match(/modal/))
{
var w = $('.modal.touch .wrapper'),
t = $(window).scrollTop() + ($(window).height() - w.outerHeight()) / 2;
w.css({top: t >= 20 ? t : 20});
}
if (style.match(/modal/)) $('#' + f.id + '-' + f.fields[0].name).focus();
};
js.form.submit = function(form, send)
{
if (js.busy) return; js.busy = 1;
var f = form, post = {}, a = !1;
for (var i = 0; i < f.fields.length; i++)
{
var l = f.fields[i], o = $('#' + f.id + '-' + l.name);
if (!l.required) continue;
if (l.type == 'checkbox' && !o.is(':checked')) {a = 1; if (l.alert) {js.form.alert(l.alert); js.busy = 0; return}}
else if (l.type == 'email' && !o.val().match(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/) || !o.val())
{
o.addClass('alert'); a = 1;
if (l.alert) {js.form.error(f, l.alert); return}
}
}
if (a) {js.form.alert(f.alert); js.busy = 0; return}
$('#' + f.id + '-form .submit').addClass('disabled');
if (send) {send(form)}
else
{
js.form.send(f, function(html, post)
{
var w = $('#' + f.id + '-form');
if (html == 'success')
{
if (w.is('.modal')) {w.stop().animate({opacity: 0}, 500, function() {js.form.alert(f.success); w.remove(); js.busy = 0})}
else
{
js.form.alert(f.success);
w.find('input, textarea').val('');
w.find('input[type="checkbox"]').prop('checked', !1);
w.find('option:selected').prop('selected', !1);
w.find('option:first').prop('selected', 'selected');
w.find('.submit').removeClass('disabled');
js.busy = 0;
}
}
else if (html.match(/^redirect/)) {window.location = html.replace(/^redirect: /, '')}
else {js.form.error(f, f.error)}
});
}
};
js.form.send = function(form, success)
{
var f = form, post = {};
for (var i = 0; i < f.fields.length; i++)
{
var l = f.fields[i], n = $('#' + f.id + '-' + l.name);
post[l.name] = l.type == 'checkbox' ? n.is(':checked') ? 1 : 0 : n.val();
}
$.ajax({url: f.url, type: 'POST', cache: !1, data: post,
fail: function() {js.form.error(f, f.error)},
error: function() {js.form.error(f, f.error)},
success: function(html) {success(html, post)}});
};
js.form.error = function(form, message)
{
$('#' + form.id + '-form .submit').removeClass('disabled');
js.form.alert(message); js.busy = 0;
};
js.form.alert = function(message)
{
$('body').append('
' + message + '
');
$('body>.alert').stop().animate({opacity: 1}, 500, function()
{
setTimeout(function() {$('body>.alert').stop().animate({opacity: 0}, 500, function() {$('body>.alert').remove()})}, 1000);
});
};
js.resize.push(function(width, height)
{
$('.form.modal.touch').css({height: $('body').outerHeight()});
});
/* ! file */
js.ready.push(function()
{
$('.e-file').each(function()
{
var u = $(this).find('a').attr('href'); if (!u) return;
if (u.match(/\.mp3$/)) {$(this).replaceWith('')}
else if (u.match(/\.mp4$/)) {$(this).replaceWith('')}
else {$(this).prepend('' + u.replace(/.+\./g, '').substring(0, 5).replace(/[^a-z0-9]/gi, '') + '')}
});
});
/* ! link */
js.ready.push(function()
{
$('article a[href^="http"]').addClass('external');
});
/* ! map */
js.map.draw = function(id, key, zoom, x, y, title)
{
window.drawMap = function()
{
if (js.map.core) {google.maps.event.trigger(js.map.core, 'resize'); return}
$('#' + id).addClass('google-map');
var position = new google.maps.LatLng(x, y);
var icon = {url: '/lib/marker.svg', scaledSize: new google.maps.Size(64, 64)};
js.map.options['zoom'] = zoom; js.map.options['center'] = position;
js.map.options['mapTypeId'] = eval('google.maps.MapTypeId.' + js.map.options.mapType);
js.map.core = new google.maps.Map(document.getElementById(id), js.map.options);
if (title) js.map.marker = new google.maps.Marker({position: position, map: js.map.core, title: title, icon: icon});
if (!js.touch) js.map.zoom();
for (var i = 0; i < js.map.ready.length; i++) js.map.ready[i]();
js.trigger.resize();
}
if (!window.google || !google.maps) {$.getScript('//maps.google.com/maps/api/js?key=' + key + '&callback=drawMap')} else {drawMap()}
};
js.map.zoom = function()
{
var i = $(''),
o = $(''), d = $('');
d.append(i); d.append($('')); d.append(o);
js.map.core.controls[eval('google.maps.ControlPosition.' + js.map.options.zoomPosition)].push(d[0]);
google.maps.event.addDomListener(i[0], 'click', function() {js.map.core.setZoom(js.map.core.getZoom() + 1)});
google.maps.event.addDomListener(o[0], 'click', function() {js.map.core.setZoom(js.map.core.getZoom() - 1)});
};
/* ! menu */
js.ready.push(function()
{
if (js.touch)
{
$('.main-menu').on('click', function() {});
$('.main-menu .popup').on('tap', function(event)
{
if ($(window).width() < 1024) return;
if (!$(this).hasClass('hover')) event.preventDefault();
$('.main-menu .hover').removeClass('hover');
$(this).toggleClass('hover');
});
$('body').on('tap', function(event)
{
if ($(event.target).closest('.main-menu').length) return;
$('.main-menu .hover').removeClass('hover');
});
}
$('.main-menu .popup').on('mouseenter', function()
{
if ($(window).width() < 1024) return;
$(this).addClass('hover');
}).on('mouseleave', function()
{
if ($(window).width() < 1024) return;
$(this).removeClass('hover');
});
});
js.resize.push(function(width, height)
{
$('.main-menu .popup ul').each(function() {$(this).css({'min-width': $(this).parent().width()})});
});
/* ! more */
js.ready.push(function()
{
$('.e-more').on('tap', function()
{
$(this).prev('.e-content').removeClass('hidden').addClass('show');
$(this).removeClass('show');
js.trigger.resize();
});
$('.e-more').tapHighlight();
});
js.resize.push(function(width, height)
{
$('.e-content:not(.show)').each(function()
{
if ($(this).height() >= parseInt($(this).css('max-height')))
{
$(this).addClass('hidden');
$(this).next('.e-more').addClass('show');
}
else
{
$(this).removeClass('hidden');
$(this).next('.e-more').removeClass('show');
}
});
});
/* ! share */
js.ready.push(function()
{
var u = encodeURIComponent(location.href), h = '';
for (var i = 0; i < js.share.links.length; i++)
{
var l = js.share.links[i];
h += '';
}
$('.e-share').html('' + h);
$('.e-share a').on('click', function(event)
{
event.preventDefault();
window.open($(this).attr('href'), 'share', 'width=500,height=300,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,directories=no,status=no');
});
$('.e-share').on('tap', function(event)
{
if ($(event.target).is('.e-share a')) return;
$(this).toggleClass('hover');
});
$('.e-share').tapHighlight();
$('.e-share').on('mouseenter', function() {$(this).addClass('hover')}).on('mouseleave', function() {$(this).removeClass('hover')});
});
/* ! scroller */
js.ready.push(function()
{
$('.scroller').each(function()
{
$(this).html(''
+ ''
+ '
' + $(this).html() + '
');
var s = $(this), c = s.find('.content>div'), l = s.find('.left'), r = s.find('.right'), i, speed = s.data('speed') || 400;
c.on('scroll', function()
{
var e = $(this)[0], w = $(this).width(), d = 'disabled';
if (e.scrollWidth > w)
{
if (e.scrollLeft <= 0) {l.addClass(d); r.removeClass(d)}
else if (e.scrollWidth - e.scrollLeft <= w) {l.removeClass(d); r.addClass(d)}
else {l.removeClass(d); r.removeClass(d)}
}
else {l.addClass(d); r.addClass(d)}
});
$('.scroller .left, .scroller .right').tapHighlight();
if (s.hasClass('steps'))
{
l.on('tap', function() {c.stop().animate({scrollLeft: c.scrollLeft() - c.width()}, speed)});
r.on('tap', function() {c.stop().animate({scrollLeft: c.scrollLeft() + c.width()}, speed)});
return;
}
l.on('touchstart mouseover', function(event)
{
if (i || (js.touch && event.type == 'mouseover')) return;
i = setInterval(function() {c.scrollLeft(c.scrollLeft() - 5)}, 10);
});
l.on('touchend mouseout', function() {if (i) clearInterval(i); i = null});
r.on('touchstart mouseover', function(event)
{
if (i || (js.touch && event.type == 'mouseover')) return;
i = setInterval(function() {c.scrollLeft(c.scrollLeft() + 5)}, 10);
});
r.on('touchend mouseout', function() {if (i) clearInterval(i); i = null});
});
});
js.resize.push(function(width, height)
{
$('.scroller .content>div').trigger('scroll').each(function()
{
var c = $(this);
c.css({marginBottom: -(c[0].offsetHeight - c[0].clientHeight + 40)});
if (c.closest('.steps').length) c.scrollLeft(Math.round(c.scrollLeft() / c.width()) * c.width());
});
});
/* ! slider */
js.ready.push(function()
{
$('.slider').each(function()
{
$(this).html(''
+ ''
+ '
' + $(this).html() + '
');
var s = $(this), c = s.find('.content'), r = s.find('.pager'), busy, start, end,
p = s.find('.prev'), n = s.find('.next'), count = c.find('.slide').length,
delay = s.data('delay') || 3000, speed = s.data('speed') || 400, current = 1;
c.find('.slide:last-child').prependTo(c);
if (count == 1) {n.hide(); p.hide(); r.hide()}
if (count == 2) c.append(c.html());
c.find('.slide').css({width: (100 / (count == 2 ? 4 : count)) + '%'});
if (count > 1) c.css({width: (count * 100 * (count == 2 ? 2 : 1)) + '%', marginLeft: '-100%'});
for (var i = 0; i < count; i++) r.append(''); activate(1);
function next()
{
if (busy) return; busy = 1;
c.transition('transform', speed + 'ms').translate(-c.parent().width());
setTimeout(function()
{
c.transition('transform', '0s').translate(0).find('.slide:first-child').appendTo(c);
current = current == count ? 1 : current + 1;
activate(current); busy = 0;
}, speed);
}
function prev()
{
if (busy) return; busy = 1;
c.transition('transform', speed + 'ms').translate(c.parent().width());
setTimeout(function()
{
c.transition('transform', '0s').translate(0).find('.slide:last-child').prependTo(c);
current = current == 1 ? count : current - 1;
activate(current); busy = 0;
}, speed);
}
function activate(slide)
{
c.find('.slide.active').removeClass('active');
c.find('.slide:nth-child(2)').addClass('active');
r.find('i.active').removeClass('active');
r.find('i:nth-child(' + slide + ')').addClass('active');
}
function stop()
{
if (s[0].interval) {clearInterval(s[0].interval); s[0].interval = null}
}
c.find('.slide').on('touchstart', function(event)
{
if (count == 1 || busy) return;
start = end = event.originalEvent.touches[0].pageX;
c.transition('transform', '0s');
$(this).on('touchmove', function(event)
{
end = event.originalEvent.touches[0].pageX;
c.translate(end - start);
});
}).on('touchend', function(event)
{
$(this).off('touchmove');
if (end - start < -50) {stop(); next()}
else if (end - start > 50) {stop(); prev()}
else
{
busy = 1; c.transition('transform', speed + 'ms').translate(0);
setTimeout(function() {c.transition('transform', '0s'); busy = 0}, speed);
}
});
n.on('tap', function() {stop(); next()});
p.on('tap', function() {stop(); prev()});
if (s.data('autoplay') && c != 1) s[0].interval = setInterval(function() {next()}, delay);
});
$('.slider .prev, .slider .next').tapHighlight();
});
/* ! image */
js.scene.init = function(selector)
{
js.scene.db = [];
$(selector).each(function()
{
js.scene.db.push(this);
$(this).off('click').on('click', function(event)
{
event.preventDefault();
js.scene.show(this);
});
});
}
js.scene.show = function(image)
{
$('body').append('
'
+ ''
+ '
');
var db = js.scene.db, s = $('.scene').css({opacity: 1}), c = s.find('.content'), d = c.find('div'),
p = s.find('.prev'), n = s.find('.next'), l = s.find('.loader').css({opacity: 1}),
tmp = new Image(), x, y, s1, e1, s2, e2, r1, r2, busy, speed = 400;
if (db.length == 1) {p.hide(); n.hide()}
$('').on('load', function()
{
if (!d.find('img').length) d.append(this);
p.css({opacity: 1}); n.css({opacity: 1});
c.css({opacity: 1}); l.css({opacity: 0});
var e = find('current'), t = e.attr('title') || e.attr('alt');
if (t) {d.find('span').show().html(t)} else {d.find('span').hide().html('')}
setTimeout(function() {busy = 0}, speed);
js.trigger.resize();
}).on('error', function() {busy = 0}).attr({src: $(image).attr('href') || $(image).attr('src')});
function load(e)
{
var url = e.attr('href') || e.attr('src');
tmp.src = url; c.css({opacity: 0});
console.log(db);
setTimeout(function()
{
d.transition('transform', '0s').translate(0);
l.css({opacity: 1}); c.find('img').attr({src: url});
}, speed);
}
function find(e)
{
var o = db[0], src = c.find('img').attr('src');
for (var i = 0; i < db.length; i++)
{
if ($(db[i]).attr('href') == src || $(db[i]).attr('src') == src) break;
}
if (e == 'next') o = i == db.length - 1 ? db[0] : db[i + 1];
if (e == 'prev') o = i == 0 ? db[db.length - 1] : db[i - 1];
if (e == 'current') o = db[i];
return $(o);
}
p.on('tap', function() {if (busy) return; busy = 1; load(find('prev'))});
n.on('tap', function() {if (busy) return; busy = 1; load(find('next'))});
s.on('tap', function(event)
{
if (event && event.target != s[0] && event.target != c[0]) return; s.css({opacity: 0});
setTimeout(function() {if (s) s.remove()}, speed);
});
s.on('touchstart', function(event)
{
event.preventDefault();
if (db.length == 1 || busy) return;
s1 = e1 = event.originalEvent.touches[0].pageX;
s2 = e2 = event.originalEvent.touches[0].pageY;
d.transition('transform', '0s'); x = 1; y = 1; r1 = 0; r2 = 0;
s.on('touchmove', function(event)
{
e1 = event.originalEvent.touches[0].pageX;
e2 = event.originalEvent.touches[0].pageY;
r1 = e1 - s1; r2 = e2 - s2;
if (y && r2 < -10) x = 0;
if (x && (r1 < -10 || r1 > 10)) y = 0;
d.translate(x ? r1 : 0, y && r2 <-10 ? r2 : 0);
});
});
s.on('touchend', function(event)
{
s.off('touchmove');
if (busy) return; busy = 1;
d.transition('transform', speed + 'ms');
if (y && r2 < -10) {d.translate(0, -s.height()); s.trigger('tap')}
else if (x && r1 < -50) {d.translate(-s.width()); load(find('next'))}
else if (x && r1 > 50) {d.translate(s.width()); load(find('prev'))}
else {d.translate(0); setTimeout(function() {d.transition('transform', '0s'); x = 1; y = 1; busy = 0}, speed)}
});
$('.scene .prev, .scene .next').tapHighlight();
};
js.ready.push(function()
{
js.scene.init('article a[rel^="zoom"]');
});
js.resize.push(function(width, height)
{
$('.scene .content img').css({'max-width': width - (width <= 640 ? 40 : (width >= 1600 ? 240 : 120)), 'max-height': height - (width <= 640 ? 40 : 80)});
$('.img-sign-wrap').each(function()
{
var w = $(this).find('img').innerWidth();
if (w) $(this).find('span').width(w).show();
$(this).parent('a').addClass('img-sign-link');
});
});
/* ! gallery */
js.ready.push(function()
{
$('.e-photo').each(function()
{
$(this).html('
'
+ ''
+ ''
+ '
' + $(this).html() + '
');
var s = $(this), c = s.find('.content'), d = c.find('div'), t = s.find('.thumbs'), k = t.find('div'),
p = s.find('.prev'), n = s.find('.next'), l = s.find('.loader').css({opacity: 1}), tmp = new Image(),
i, s1, e1, speed = 400, busy, next, prev;
s.removeClass('e-photo').addClass('gallery');
var img = $('').on('load', function()
{
if (!c.find('img').length) d.append(this);
p.css({opacity: 1}); n.css({opacity: 1});
c.css({opacity: 1}); l.css({opacity: 0});
if (prev.length) {p.show(); setTimeout(function() {p.removeClass('disabled')}, 10)}
if (next.length) {n.show(); setTimeout(function() {n.removeClass('disabled')}, 10)}
var t = $(this).attr('title') || $(this).attr('alt');
if (t) {d.find('span').show().html(t)} else {d.find('span').hide().html('')}
setTimeout(function() {busy = 0}, speed);
js.trigger.resize();
}).on('error', function() {busy = 0}).on('tap', function() {js.scene.show(img)});
function load(e, m)
{
var url = e.attr('href') || e.attr('src'), alt = e.attr('title') || e.attr('alt') || '';
if (img.attr('src') == url) {busy = 0; return}
t.find('div>*').removeClass('active'); e.addClass('active');
tmp.src = url; c.css({opacity: 0});
next = e.next(); prev = e.prev();
if (!prev.length) {p.addClass('disabled'); setTimeout(function() {p.hide()}, speed)}
if (!next.length) {n.addClass('disabled'); setTimeout(function() {n.hide()}, speed)}
if (m) k.stop().animate({scrollLeft: e.position().left - (k.width() / 2) + (e.width() / 2) + parseInt(e.css('margin-left'))}, speed);
setTimeout(function()
{
d.transition('transform', '0s').translate(0);
l.css({opacity: 1}); img.attr({src: url}).attr('alt', alt);
}, speed);
}
load(t.find('div>*:first').addClass('active'));
p.on('tap', function() {if (busy || !prev.length) return; busy = 1; load(prev, 1)});
n.on('tap', function() {if (busy || !next.length) return; busy = 1; load(next, 1)});
t.on('mousemove', function(event)
{
if (js.touch) return;
var o = $(this).offset(), x = event.pageX - o.left;
if (x < 40) {if (i) return; i = setInterval(function() {k.scrollLeft(k.scrollLeft() - 5)}, 10)}
else if (x > t.width() - 40) {if (i) return; i = setInterval(function() {k.scrollLeft(k.scrollLeft() + 5)}, 10)}
else if (i) {clearInterval(i); i = null}
});
t.on('mouseout', function(event) {if (i) clearInterval(i); i = null});
t.find('div>*').off('click').on('click', function(event)
{
event.preventDefault();
if ($(this).hasClass('active')) return;
if (busy) return; busy = 1; load($(this));
});
c.on('touchstart', function(event)
{
s1 = e1 = event.originalEvent.touches[0].pageX;
d.transition('transform', '0s');
c.on('touchmove', function(event)
{
e1 = event.originalEvent.touches[0].pageX;
d.translate(e1 - s1);
});
});
c.on('touchend', function(event)
{
c.off('touchmove');
if (busy) return; busy = 1; d.transition('transform', speed + 'ms');
if (next.length && e1 - s1 < -50) {d.translate(-s.width()); load(next, 1)}
else if (prev.length && e1 - s1 > 50) {d.translate(s.width()); load(prev, 1)}
else {d.translate(0); setTimeout(function() {d.transition('transform', '0s'); busy = 0}, speed)}
});
});
$('.gallery .prev, .gallery .next, .gallery .zoom').tapHighlight();
});
js.resize.push(function(width, height)
{
$('.gallery .content').each(function()
{
var g = $(this).closest('.gallery'), h = Math.round(g.width() / (g.data('ratio') || 1.5));
$(this).css({height: h}); $(this).find('img').css({'max-height': h});
});
});
/* ! video */
js.resize.push(function(width, height)
{
$('.e-video').each(function() {$(this).css({height: $(this).width() / 1.777777})});
});
/* ! touch */
js.ready.push(function()
{
if (!js.touch) return;
$('body').removeClass('desktop');
$('a, .e-btn').tapHighlight();
});
/* ! customize */
js.map.options =
{
mapType: 'ROADMAP', zoomPosition: 'LEFT_TOP',
scrollwheel: 0, disableDefaultUI: 1, streetViewControl: 0,
styles:
[
{'featureType': 'administrative.province', 'elementType': 'all', 'stylers': [{'visibility': 'off'}]},
{'featureType': 'administrative.neighborhood', 'elementType': 'all', 'stylers': [{'visibility': 'off'}]},
{'featureType': 'administrative.land_parcel', 'elementType': 'all', 'stylers': [{'visibility': 'off'}]},
{'featureType': 'poi', 'elementType': 'labels', 'stylers': [{'visibility': 'off'}]},
{'featureType': 'poi.business', 'elementType': 'all', 'stylers': [{'visibility': 'off'}]},
{'featureType': 'water', 'elementType': 'labels', 'stylers': [{'visibility': 'off'}]}
]
};
js.share.links =
[
{title: 'Twitter', icon: 'twitter', url: 'https://twitter.com/share?url='},
{title: 'Facebook', icon: 'facebook', url: 'https://www.facebook.com/sharer.php?u='},
];
js.ready.push(function()
{
var feedback =
{
id: 'feedback',
title: 'Зворотній зв’язок',
alert: 'Будь ласка, заповніть усі поля.',
submit: 'Надіслати',
success: 'Ваше повідомлення надіслано!',
error: 'Ой! Щось пішло не так…',
url: '/?form=feedback',
fields:
[
{name: 'name', type: 'text', label: 'Ім’я', required: 1, alert: 'Будь ласка, введіть своє ім’я.'},
{name: 'email', type: 'email', label: 'Електронна пошта', required: 1, alert: 'Будь ласка, введіть адресу своєї електронної пошти.'},
{name: 'message', type: 'textarea', label: 'Повідомлення', required: 1, rows: 5}
]
};
$('.e-feedback-show').on('tap', function() {js.form.create(feedback, 'modal')});
$('.search').submit(function()
{
return $('#search').val() == '' ? false : true;
});
$('.search div').click(function(event)
{
if ($('#search').val() == '') $('#search').focus();
$('.search').submit();
});
$('#search').focus(function()
{
$(this).parent().addClass('hover');
});
$('#search').blur(function()
{
if ($(this).val() == '') {$(this).parent().removeClass('hover')}
});
$('.e-share').on('tap', function(event)
{
if ($(event.target).is('.e-share a')) return;
$(this).parent().toggleClass('share-hover');
});
$('.e-share').on('mouseenter', function() {$(this).parent().addClass('share-hover')}).on('mouseleave', function() {$(this).parent().removeClass('share-hover')});
$('#calendar').calendar();
$('a[id^="note"]').addClass('note');
$('.bishop-words .more').on('tap', function() {$(this).parent().addClass('open')});
prepareMore();
});
js.scroll.push(function(top, left)
{
$('body').toggleClass('fixed', top > $('header').outerHeight());
});
js.map.ready.push(function()
{
if (!js.map.markers) return;
for (var i = 0; i < js.map.markers.length; i++)
{
js.map.markers[i][6] = js.map.polygon(js.map.markers[i][1], js.map.markers[i][2] || '000000');
eval('google.maps.event.addListener(js.map.markers[i][6], "click", function(event) {window.location = "/church-structure/-" + js.map.markers[' + i + '][0] + "/"})');
eval('google.maps.event.addListener(js.map.markers[i][6], "mouseover", function(event) {$("#ugcc-map-hint").html(js.map.markers[' + i + '][4]).show(); this.setOptions({fillOpacity: 0.45})})');
google.maps.event.addListener(js.map.markers[i][6], 'mouseout', function(event) {$('#ugcc-map-hint').hide(); this.setOptions({fillOpacity: 0.35})});
}
});
js.map.polygon = function(paths, color, pan)
{
var a = paths.split(';'), c = [], bs = new google.maps.LatLngBounds();
for (var i = 0; i < a.length; i++)
{
var l = new google.maps.LatLng(a[i].split(',')[0], a[i].split(',')[1]);
c.push(l); bs.extend(l);
}
var polygon = new google.maps.Polygon({map: js.map.core, paths: c, strokeColor: '#' + color, strokeOpacity: 0.5, strokeWeight: 1, fillColor: '#' + color, fillOpacity: 0.35});
if (pan) js.map.core.panTo(bs.getCenter());
return polygon;
}
$(document).mousemove(function(e)
{
if (!js.touch && $('#ugcc-map-hint').length)
{
var left = e.offsetX;
if ($('.ugcc-map').width() < $('#ugcc-map-hint').outerWidth() + left) {left = left - $('#ugcc-map-hint').outerWidth()}
$('#ugcc-map-hint').css({top: e.offsetY, left: left});
}
});
var calendarContent = [], months = ['Січень', 'Лютий', 'Березень', 'Квітень', 'Травень', 'Червень', 'Липень', 'Серпень', 'Вересень', 'Жовтень', 'Листопад', 'Грудень'], days = 'НдПнВтСрЧтПтСб';
$.fn.calendar = function(date)
{
var id = $(this).attr('id');
var fd = 2, mn = months, dn = days;
var mD = new Date(), m = parseInt(mD.getMonth() + 1, 10), y = parseInt(mD.getFullYear());
if (date) m = parseInt(date.month, 10);
if (date) y = parseInt(date.year);
var dim = [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
var oD = new Date(y, m - 1, 1); oD.od = oD.getDay() + 1;
var tmpod = oD.od - fd; if (tmpod < 0) tmpod = 7 + tmpod; oD.od = tmpod + 1;
var wkstr = dn.substr(fd, dn.length) + dn.substr(0, fd);
var cd = new Date(); var today = (y == cd.getFullYear() && m == cd.getMonth() + 1) ? cd.getDate() : 0;
var oM = m, oY = y, nM = m, nY = y;
nM = (nM == 12) ? '01' : (nM + 1).pad();
oM = (oM == 1) ? 12 : (oM - 1).pad();
if (m == 12) nY = (nY == 2100) ? 1900 : nY + 1;
if (m == 1) oY = (oY == 1900) ? 2100 : oY - 1;
dim[1] = (((oD.getFullYear() % 100 != 0) && (oD.getFullYear() % 4 == 0)) || (oD.getFullYear() % 400 == 0)) ? 29 : 28;
var t = '
' + mn[m - 1] + '' + y
+ '
';
for (s = 0; s < 7; s++) t += '
' + wkstr.substr(s * 2, 2) + '
';
t += '
';
for (i = 1; i <= 42; i++)
{
var x = ((i - oD.od >= 0) && (i - oD.od < dim[m - 1])) ? '' + (i - oD.od + 1) + '' : '';
if ((i - oD.od + 1) == today) x = '' + x + '';
if ((i % 7 == 0) || ((i + 1) % 7 == 0)) x = '' + x + ''; t += '
' + x + '
';
if ((i % 7 == 0) && (i < 36)) t += '
';
}
t += '
';
$(this).html(t);
if ($('.current-date').html()) $('#' + id + ' td em').each(function() {if ($(this).parent().html().match($('.current-date').html())) $(this).addClass('mark').addClass('active')});
$('#calendar .head b').tapHighlight();
$.ajax({url: '/?calendar=' + id + '&month=' + m.pad() + '&year=' + y, dataType: 'script', cache: true});
};
function selectCalendar(date, obj)
{
if (!$(obj).hasClass('mark')) return;
$('#calendar .active').removeClass('active');
$('#calendar .first').removeClass('first');
$(obj).addClass('active');
var a = calendarContent, html = '', curYear = date.replace(/^(\d\d\d\d)-(\d\d)-(\d\d)$/g, '$1');
for (var i = 0; i < a.length; i++)
{
if (a[i][0] == date)
{
var descr = a[i][3] ? '' + a[i][3] + '' : '';
var image = a[i][4] ? '' : '';
image = a[i][5] && image ? '' + image + '' : image;
var year = a[i][1].replace(/^(\d\d\d\d)-(\d\d)-(\d\d)$/g, '$1');
var years = curYear - year;
years = years > 0 ? ' — ' + years + ' ' + decOfNum(years, ['рік', 'роки', 'років']) + ' тому' : '';
html += '
' + a[i][2].replace(/ \(/g, ' (') + '
' + a[i][1].replace(/^(\d\d\d\d)-(\d\d)-(\d\d)$/g, '$3.$2.$1') + years + '
' + image + descr + '
';
}
}
$('#calendar-content').html('
' + date + '
' + html);
$('#calendar-content .item .head').tapHighlight();
$('#calendar-content .item .head').on('tap', function()
{
if (!$(this).parent().hasClass('show')) $('#calendar-content .show').removeClass('show');
$(this).parent().toggleClass('show');
});
}
function prepareCalendar(calendar)
{
var a = calendarContent;
for (var i = 0; i < a.length; i++)
{
$(calendar + ' td em').each(function()
{
if ($(this).parent().html().match(a[i][0]))
{
$(this).addClass('mark');
if ($(this).parent().is('b') && !$('#calendar-content').html()) $(this).trigger('click').addClass('first');
}
});
}
}
function prepareMore()
{
$('.get-more').off('tap');
$('.get-more').on('tap', function()
{
var o = $(this), post =
{
'query': o.data('query'),
'limit': o.data('limit'),
'template': o.data('template'),
'category': o.data('category'),
'sort': o.data('sort'),
'page': o.data('page'),
'search': o.data('search'),
'current': o.data('current')
};
$.ajax({url: '/data/more/?ajax=on', type: 'POST', cache: !1, data: post, success: function(html)
{
o.parent().append(html); o.remove(); prepareMore();
}});
});
}
function decOfNum(number, titles)
{
var cases = [2, 0, 1, 1, 1, 2];
return titles[(number % 100 > 4 && number % 100 < 20) ? 2: cases[(number % 10 < 5) ? number % 10 : 5]];
}