$(function(){
$('#site_rules_new_close').click(function () {
this.parentNode.remove();
$.get('/ajax/site_rules/accept');
});
if ($.cookie) {
var pageShow = $.cookie('_pageShow') || 0;
$.cookie('_pageShow', ++pageShow, { expires: 365, path: '/' });
var pageShow_auth = $.cookie('_pageShow_auth');
if (pageShow_auth) {
$.cookie('_pageShow_auth', ++pageShow_auth, { path: '/' });
}
}
$(document)
.on('mouseover', '.iClose', function(){ $(this).prev().show(); })
.on('mouseout', '.iClose', function(){ $(this).prev().hide(); })
.on('click', '.redigoPopup', function(e){
var el = $(e.target);
if(el.parents('.redigoPopup_frame').size() < 1 && !el.is('.popupNotClose')){
$(this).hide();
if($('.redigoPopup').not(':hidden').size() == 0)
bodyFreezing.unfreeze();
//$('body').removeClass('noscroll');
}
})
.on('click', '.subscribeUserProviderAction', function(e){
var el = $(e.target);
var provider = el.data('provider');
var type = el.data('type');
if (provider == 'twitter') {
var data = {
'provider': provider,
'type': type
};
$.get('/ajax/subscribeUserProvider/action', data);
$('#followMe').remove();
bodyFreezing.unfreeze();
if (type == 'later') {
_gaq.push(['_trackEvent', 'social_promo', 'twitter', 'remind_me_later']);
} else if (type == 'deny') {
_gaq.push(['_trackEvent', 'social_promo', 'twitter', 'reject']);
}
}
});
if (window.twttr && $('#followMe').length) {
window.twttr.ready(function(twttr){
twttr.events.bind('follow', function (event) {
$.get('/ajax/subscribeUserProvider/action', {
'provider': 'twitter',
'type': 'yes'
});
$('#followMe').hide();
bodyFreezing.unfreeze();
_gaq.push(['_trackEvent', 'social_promo', 'twitter', 'official']);
});
})
if($('#followMe').is(':visible'))
bodyFreezing.freeze();
}
var userSubMenuTimer = null;
$(document)
.on('click', '#currUser', function(){
if($('#userSubMenu').is(':hidden')){
$(this).addClass('act');
clearTimeout(userSubMenuTimer);
$('#userSubMenu').show();
}else{
$(this).removeClass('act');
$('#userSubMenu').hide();
}
})
.on('mouseleave', '#userSubMenu', function(){
userSubMenuTimer = setTimeout(function(){
$('#userSubMenu').hide();
$('#currUser').removeClass('act');
}, 1000);
});
var anchor = document.location.hash;
if(anchor.length > 0) {
try {
if ($(anchor).length) {
$('html, body').animate({scrollTop: $(anchor).offset().top - 200}, 500);
}
} catch (e) {
if (console && console.log) {
console.log(e);
}
}
}
$('.anchor').click(function(){
var t = $(this);
$('html, body').animate({scrollTop: Math.round($(t.attr('href')).offset().top - 200) }, 500);
});
})
var bodyFreezing = {
body: $('body'),
freeze: function(){
var w = bodyFreezing.getScrollWidth();
bodyFreezing.body.addClass('noscroll');
if(w > 0){
bodyFreezing.body.css('padding-right', w + 'px');
}
},
unfreeze: function(){
bodyFreezing.body.removeClass('noscroll').css('padding-right', '0px');
},
getScrollWidth: function(){
var div = document.createElement('div');
div.style.overflowY = 'scroll';
div.style.width = '50px';
div.style.height = '50px';
div.style.visibility = 'hidden';
document.body.appendChild(div);
var scrollWidth = div.offsetWidth - div.clientWidth;
document.body.removeChild(div);
return scrollWidth;
}
}
var main = {};
main.suggest = {
selectedIndex: -1,
searchRequest: null,
init: function(){
this.input_element = $('.with_suggest');
if(!this.input_element.length) return;
var t = this;
this.input_element.attr('autocomplete', 'off');
var params = this.input_element[0].onclick();
this.suggest_href = params.suggest;
this.form_href = this.input_element.parents('form').attr('action') + '?' + this.input_element.attr('name') + '=';
/*
if(params.example && params.example.length > 0){
$('
Например: ' + params.example + '
').insertAfter(this.input_element.parent()).find('.pseudo_link').click(function(){
t.input_element.val(params.example);
t.input_element.focus();
});
}
*/
this.spinner = $('').insertBefore(this.input_element).hide();
this.suggest_element = $('').insertAfter(this.input_element.parents('form'));
this.suggest_element.bind('focus mousedown keydown', function(){t.over = true;});
this.suggest_element.bind('blur mouseup keyup', function(){t.over = false; t.input_element.focus();});
this.suggest_element.hide();
this.data = [];
this.input_element.bind('focus keyup mouseup change', function(){
if(t.searchRequest && typeof(t.searchRequest) == 'object') {
t.searchRequest.abort();
clearTimeout(t.loading);
t.spinner.hide();
t.hide();
}
t.show();
});
this.input_element.blur(function(){
if(!t.over){
t.hide();
}
});
},
show: function(){
var value = this.input_element.val();
if(!value || value.length < 2){
this.hide();
return;
}
if(this.data[value] == undefined){
// aborting the previous request
/*
if(this.searchRequest && typeof(this.searchRequest) == 'object') {
this.searchRequest.abort();
clearTimeout(this.loading);
this.spinner.hide();
}*/
this.spinner.show();
clearTimeout(this.loading);
t = this;
this.loading = setTimeout(function() {
t.searchRequest =
$.getJSON(
t.suggest_href + escape(value),
function(data){
t.data[value] = {data: data};
if(!data || !data.total){
t.suggest_element.hide();
}else{
t.make(value);
t.suggest_element.show();
}
t.spinner.hide();
}
).error(function(){ t.data[value] = ''; t.hide(); });
}, 500);
} else {
if(this.data && this.data[value] && this.data[value].data.total) {
this.make(value);
this.suggest_element.show();
} else {
this.hide();
}
}
},
hide: function(){
this.suggest_element.hide();
},
make: function(value){
if(this.old_value == value) return;
this.unbindKeys();
this.old_value = value;
var d = this.data[value];
var counter = 0;
if(d.data && !d.html){
this.spinner.hide();
d.html = '';
for(var i = 0, group, ii, item; i < d.data.groups.length; i++){
group = d.data.groups[i];
d.html += '
' + group.title + '
';
for(ii = 0; ii < group.items.length; ii++){
item = group.items[ii];
d.html += '
';
counter++;
}
d.html += '
';
}
d.html += '
';
}
this.suggest_element.html(d.html);
if(d.data && d.data.total > 0) {
//this.input_element.blur();
this.bindSuggestNavigation();
var _this = this;
$('.suggest .suri').each(
function() {
$(this).bind(
'mouseover',
function() {
$('.suggest .suri.active').removeClass('active');
var tmp = $(this).attr('id').split('_');
_this.selectedIndex = parseInt(tmp[1], 10);
}
);
}
).filter('[data-type]').click(function(){
_this.trackEvent($(this));
});
}
},
trackEvent: function(el) {
_gaq.push(['_trackEvent', 'SuggestSearch', el.data('type') + ' - ' + el.data('title'), this.input_element.val()]);
},
arrowNavigationSuggest : function (e) {
switch(e.keyCode || e.which) {
case 37: // go left
break;
case 38: //go up
var prevIndex = this.selectedIndex - 1;
var prevElement = $('#suri_'+ prevIndex);
$('.suggest .suri.active').removeClass('active');
if(!prevElement.length) {
this.selectedIndex = -1;
} else {
$(prevElement).addClass('active');
this.selectedIndex = prevIndex;
}
$(this.input_element).val($(this.input_element).val());
return false;
break;
case 39: // go right
break;
case 40: // go down
var nextIndex = this.selectedIndex + 1;
var nextElement = $('#suri_'+ nextIndex);
if(!nextElement.length) {
return false;
} else {
$('.suggest .suri.active').removeClass('active');
$(nextElement).addClass('active');
this.selectedIndex = nextIndex;
return false;
}
break;
case 13:
// console.log('We\'re here');
var aLink = $('#suri_'+ this.selectedIndex +' a');
if(this.selectedIndex > -1 && aLink.length) {
this.trackEvent($('.suggest .suri.active'));
window.document.location = $(aLink).attr('href');
return false;
}
return true;
default:
return true;
break;
}
},
preventDefaultKeys : function() {
$(document).bind('keypress keyup keydown', function(e) {
if(!e) var e = window.event;
var code = e.keyCode || e.which;
if(code == 37 || code == 38 || code == 39 || code == 40 || (this.selectedIndex > -1 && code == 13)) {
e.cancelBubble = true;
e.returnValue = false;
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
return false;
} else {
return true;
}
});
},
bindSuggestNavigation : function() {
this.preventDefaultKeys();
$(document).bind('keyup', {_this: this}, function(event) { return event.data._this.arrowNavigationSuggest(event); } );
},
unbindKeys : function() {
this.selectedIndex = -1;
$(document).unbind('keyup');
$(document).unbind('keydown');
$(document).unbind('keypress');
}
};
Calculator = {
init: function(){
var calc = $(".calculator_link");
this.calc = calc;
if(this.calc.size()){
this.calc.bind("click", function(){
if($("#calculator").size()){
$('#currencyFrom').val('');
$('#currencyResults table.result tbody').html('');
$("#calculator").show();
} else {
Calculator.create_form();
$("body").append("");
$("#calculator").show();
$(document).on('click', '#calculator_overlay', function(){
$(this).hide();
$("#calculator").hide();
});
}
var price = parseInt($(this).data('price'));
var currency = $(this).data('currency');
if (price && currency) {
$('#currencyFromType', '#calculator').val(currency)
$('#currencyFrom', '#calculator').val(price).trigger('keyup');
}
$('#calculator').offset({ top: $(this).offset().top + 20, left: $(this).offset().left });
$("#calculator_overlay").show();
if(typeof calc_value != 'undefined' && calc_value > 0) {
$('#currencyFrom').val(calc_value);
Calculator.convertCurrency();
}
});
}
},
create_form: function(){
var form_src = '';
//Calculator.calc.parent().append(form_src);
$('body').append(form_src);
$('#calculator').offset({ top: Calculator.calc.offset().top + 20, left: Calculator.calc.offset().left });
$('#currencyFrom').bind("keyup", function(){
Calculator.convertCurrency();
});
$('#currencyFromType').bind("change", function(){
Calculator.convertCurrency();
});
$('#calculator .iClose').bind("click", function(){
$("#calculator").hide();
$("#calculator_overlay").hide();
});
$(window).resize(function() {
$('#calculator').offset({ left: Calculator.calc.offset().left });
});
},
convertCurrency: function() {
var sourceValue = Calculator.stringToFloat($('#currencyFrom').val()),
sourceCurrency = $('#currencyFromType').val();
//course = 'По курсу ЦБРФ на ';
if($('#currencyResults table.result tbody').size())
$('#currencyResults table.result tbody').html('');
else
$('#currencyResults').append('');
$('#currencyResults table.result').hide();
if(sourceValue > 0){
$('#currencyResults table.result').show();
if(sourceCurrency == 'RUB'){
if(custom_code.length > 0)
Calculator.convertAppendResult(custom_code, sourceValue/Calculator.stringToFloat(custom_rate));
Calculator.convertAppendResult('USD', sourceValue/Calculator.stringToFloat(usd));
Calculator.convertAppendResult('EUR', sourceValue/Calculator.stringToFloat(eur));
}
if(sourceCurrency == 'USD'){
if(custom_code.length > 0)
Calculator.convertAppendResult(custom_code, sourceValue * Calculator.stringToFloat(usd) / Calculator.stringToFloat(custom_rate));
Calculator.convertAppendResult('RUB', sourceValue * Calculator.stringToFloat(usd));
Calculator.convertAppendResult('EUR', sourceValue * Calculator.stringToFloat(usd) / Calculator.stringToFloat(eur));
}
if(sourceCurrency == 'EUR'){
if(custom_code.length > 0)
Calculator.convertAppendResult(custom_code, sourceValue * Calculator.stringToFloat(eur) / Calculator.stringToFloat(custom_rate));
Calculator.convertAppendResult('RUB', sourceValue * Calculator.stringToFloat(eur));
Calculator.convertAppendResult('USD', sourceValue * Calculator.stringToFloat(eur) / Calculator.stringToFloat(usd));
}
if(sourceCurrency == 'custom'){
Calculator.convertAppendResult('RUB', sourceValue * Calculator.stringToFloat(custom_rate));
Calculator.convertAppendResult('USD', sourceValue * Calculator.stringToFloat(custom_rate) / Calculator.stringToFloat(usd));
Calculator.convertAppendResult('EUR', sourceValue * Calculator.stringToFloat(custom_rate) / Calculator.stringToFloat(eur));
}
}
},
stringToFloat:function(value) {
return(value.toString().replace(",", ".").replace(" ", ""));
},
floatToString: function(value) {
//console.log(value);
value = value.toFixed(2).toString().replace(".", ",");
if(value.length < 7){
return(value);
}else{
if(value.length > 9){
var position1 = value.length - 9;
var position2 = value.length - 6;
return(value.substring(0,position1) + ' ' + value.substring(position1,position2) + ' ' + value.substring(position2, value.length));
}else{
var position = value.length - 6;
return(value.substring(0,position) + ' ' + value.substring(position, value.length));
}
}
},
convertAppendResult: function(currency, value) {
$('#currencyResults table.result tbody').append(
'' +
'≈ ' +
Calculator.floatToString(value) +
' | ' +
'' +
currency +
' | ' +
'
'
);
}
}
function controlMainHost() {
if(top.location.href != document.location.href && top.frames && top.frames.length > 0)
top.location = document.location.href;
}
//controlMainHost();
function equalHeight(items) {
var max = 0;
items.each(function() {
var h = $(this).height();
if(h > max) max = h;
});
items.height(max);
}
function words(num, one, two, ten){
if ((num % 10) == 0)
return ten;
if(20 > num && num > 10)
return ten;
if(num == 1 || (num % 10) == 1)
return one;
if((num % 10) > 4)
return ten;
return two;
}
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;
}
if(jQuery) {
$.event.trigger('load.main.js');
(function($){
function reloadCounter() {
$("#ramblerTop100counter").html();
$('script[src*="st.top100.ru/top100/top100.js"]').remove();
var _top100q = _top100q || [];
_top100q.push(["setAccount", "2892367"]);
_top100q.push(["trackPageviewByLogo", document.getElementById("ramblerTop100counter")]);
(function(){
var top100 = document.createElement("script"); top100.type = "text/javascript";
top100.async = true;
top100.src = ("https:" == document.location.protocol ? "https:" : "http:") + "//st.top100.ru/top100/top100.js";
var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(top100, s);
})();
$("#liveinternet-counter").html("<\/a>");
$('script[src*="mc.yandex.ru/metrika/watch.js"]').remove();
(function (d, w, c) {
(w[c] = w[c] || []).push(function() {
try {
w.yaCounter7178416 = new Ya.Metrika({id:7178416, enableAll: true, trackHash:true, webvisor:true});
} catch(e) {}
});
var n = d.getElementsByTagName("script")[0],
s = d.createElement("script"),
f = function () { n.parentNode.insertBefore(s, n); };
s.type = "text/javascript";
s.async = true;
s.src = (d.location.protocol == "https:" ? "https:" : "http:") + "//mc.yandex.ru/metrika/watch.js";
if (w.opera == "[object Opera]") {
d.addEventListener("DOMContentLoaded", f);
} else { f(); }
})(document, window, "yandex_metrika_callbacks");
$('script[src*="stats.g.doubleclick.net/dc.js"]').remove();
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-23363597-1']);
_gaq.push(['_setDomainName', '.redigo.ru']);
_gaq.push(['_setAllowHash', 'false']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
(function() {
var img = new Image();
img.src = 'http://www.tns-counter.ru/V13a***R>' + document.referrer.replace(/\*/g, '%2a') + '*sup_ru/ru/UTF-8/tmsec=redigo_total/' + Math.round(Math.random() * 1000000000);
})();
}
var cnt = 0;
$(document).on('ajax.reload', function () {
cnt++;
if (cnt < 3) return;
cnt = 0;
reloadCounter();
$('iframe[id^="AdFox_iframe"]').each(function () {
$(this).parent().prev().html('');
var e = $(this).contents(), n = $(this).attr("id"), i = $(this).parent(), r = e.find("script"), a = r.attr("src");
e.find("head");
if (!a) return;
$(this).remove();
i.append('');
var s = document.getElementById(n).contentDocument;
s.write('');
})
});
})(jQuery)
}