function initScripts()
{
	if(use_cookie('show_comments') == 'all') use_cookie('show_comments', 'by_pages', {expires: 365, path: '/'});
	
	/*Calendar*/
	$('.b-calendar .calendar').each(function()
	{
		new archive(this);
	});	
	
	/*Highliting current section*/
	
	if(typeof(news_id)!='undefined') $('#n_'+news_id).addClass('current');
	if(typeof(photo_section)!='undefined') $('#c_'+photo_section).addClass('current');
	
	/* Live-events */
	//I put live events call in tmpl file to make it work faster.

	/*Highlighting sections/tournaments/years*/
	
	$('#s_'+section).addClass('current');
	if($('.b-section-nav-year')[0])
	{
		$('#y_'+year).addClass('current');
		$('#ct_'+year).addClass('current');
		$('#t_'+tournir_id).addClass('current');
		var t_years=$('.b-section-nav-year dd');
		var t_year_block=$('#t_by_years dd');
		t_year_block.css('display','none');
		$('#year_'+year)[0].style.display='block';
		for(var i=0;i<t_years.length;i++){
			t_years[i].onclick=(function(i){
				return function(){
					t_years.removeClass('current');
					$('.b-section-nav-year dd:eq('+i+')').addClass('current');
					t_year_block.css('display','none');
					t_year_block[i].style.display='block';
					return false;
				}
			})(i);
		}
	}
	
	/*Switching articles-video block*/
	
	if($('.l-block .b-article .b-topic')[0])
	{
		var b_headers=$('.l-block .b-topic .b-black-header-menu ul li');
		for(var i=0;i<b_headers.length;i++)
		{
			b_headers[i].onclick=(function(i){
				return function(){
					b_headers.removeClass('current');
					$('.l-block .b-topic .b-black-header-menu ul li:eq('+i+')').addClass('current');
					$('.l-block .b-topic .b-topic-list')[i].style.display='block';
					$('.l-block .b-topic .b-topic-list')[1-i].style.display='none';
					return false;
				}
			})(i);
		}
	}
	

	/*Changing login-comments fields*/
	
	//$("p.login input[name='openid_url']").focus(function(){$(this)[0].value='';});
	
	if($('.logged')[0])
	{
		/*$(".logged textarea[name='c_comm']").focus(function(){
			if($(this).hasClass('c_comm-empty')){
				$(this).removeClass(); 
				$(this)[0].value='';
				$(this).css({'font-style':'normal','color':'#000'})
			}
		});*/
		
		$(".logged input[name='c_title']").focus(function(){
			if($(this).hasClass('c_title-empty')){
				$(this).removeClass(); 
				$(this)[0].value='';
				$(this).css({'font-style':'normal','color':'#000'});
			}
		});
		
		var commentFormContainer = $('#commentForm'),
			commentFormContainerExist = !(commentFormContainer.length === 0);
		
		if (commentFormContainerExist) {
			var commentSendButton = commentFormContainer.find("input[name='c_send']"),
				commentTextarea = commentFormContainer.find('textarea'),
				symbolsLeftMessage = $('#symbolsLeft'),
				secondsLeftMessage = $('#secondsLeft'),
				secondsLeftBlock = secondsLeftMessage.parent(),
				COMMENT_TIMEOUT_COOKIE = 'commentTimeout',
				SYMBOLS_LEFT_MESSAGE_POSTFIX = ' сек',
				DISABLED_BUTTON_CLASS = 'disabled',
				COMMENT_DELAY = 15000,
				TIMER_REFRESH_INTERVAL = 1000,
				MAX_SYMBOLS = 1024,
				countdown;
								
			function checkMaxSymbols () {
				var currentValue = commentTextarea.val(),
					symbolsLeft = MAX_SYMBOLS - currentValue.length,
					valueIsEmpty = (currentValue === '');
				
				symbolsLeftMessage.text(symbolsLeft);
				
				if (currentValue.length > MAX_SYMBOLS || valueIsEmpty) {
					symbolsLeftMessage.addClass('warning');
					commentSendButton.attr('disabled','disabled').parent().addClass(DISABLED_BUTTON_CLASS);
				} else {
					symbolsLeftMessage.removeClass('warning');
					if (!commentSendButton.data('disabledByCountdown')) {
						commentSendButton.removeAttr('disabled').parent().removeClass(DISABLED_BUTTON_CLASS);
					}
				}
				
				if (valueIsEmpty) {
					commentSendButton.attr('disabled','disabled').parent().addClass(DISABLED_BUTTON_CLASS);
					symbolsLeftMessage.removeClass('warning');
				}
			}
			
			function checkCommentTimeout () {
				var endTime = use_cookie(COMMENT_TIMEOUT_COOKIE);
				
				if (endTime) {
					deactivateSendButton();
					
					countdown = setInterval(function () {
						secondsLeftBlock.show();
						
						var currentTime = (new Date()).getTime(),
							secondsLeft = Math.floor((endTime - currentTime) / 1000);
						
						if (secondsLeft > 0) {
							secondsLeftMessage.text(secondsLeft + SYMBOLS_LEFT_MESSAGE_POSTFIX);
						} else {
							secondsLeftBlock.hide();
							activateSendButton();
						}
					}, TIMER_REFRESH_INTERVAL);
				} else {
					activateSendButton();
				}
			}
			
			function deactivateSendButton () {
				commentSendButton
					.attr('disabled', 'disabled')
					.data('disabledByCountdown', true)
					.parent()
						.addClass(DISABLED_BUTTON_CLASS);
			}
			
			function activateSendButton () {
				clearInterval(countdown);
				clearCookie(COMMENT_TIMEOUT_COOKIE);
				commentSendButton.data('disabledByCountdown', null);
				
				if (commentTextarea.val()) {
					commentSendButton
						.removeAttr('disabled')
						.parent()
							.removeClass(DISABLED_BUTTON_CLASS);
				}
			}
			
			function setCommentTimeout () {
				deactivateSendButton();
				var ts = (new Date()).getTime() + COMMENT_DELAY;
				use_cookie(COMMENT_TIMEOUT_COOKIE, ts, { expires: 365, path: '/' });
			}
			
			commentTextarea.bind('keyup keydown change', checkMaxSymbols);
			commentFormContainer.mouseover(checkMaxSymbols);
			
			commentFormContainer.find('form').bind('submit', setCommentTimeout);
			
			checkCommentTimeout();
			checkMaxSymbols();
		}
	}
	
	var foldMenu = $('#footer .menu-list:has(b.menu-list-handle)');
	if(foldMenu.length)
	{
		var handler = $('.menu-list-handle', foldMenu);
		handler.click(function(){
			use_cookie('foldMenu', foldMenu.hasClass('menu-list-folded') ? 0 : 1, {expires: 365, path: '/'});
			handler.attr('title', foldMenu.hasClass('menu-list-folded') ? 'Скрыть рубрики' : 'Показать рубрики');
			foldMenu.toggleClass('menu-list-folded');
			window.scrollTo(0, foldMenu.offset().top);
		});
		if(use_cookie('foldMenu') == 1)
		{
			foldMenu.addClass('menu-list-folded');
			handler.attr('title', 'Показать рубрики');
		}
		else
		{
			handler.attr('title', 'Скрыть рубрики');
		}
	}
	
	$("#commentForm input[name='openid_url']").each(loginFieldEvents);
	
	$('#footer a[name^=m-]').each(unParseM);

	// Selection of TV program channels
	tvProgramSectionsSelector.init({
		dayProgramContainerClass : 'b-tv-program-table',
		tvChannelsListId : 'tvChannelsList'
	});
	
	// Switching video previews
	videoPreviewSwitcher.init({
		linksListId : 'videoLinksList',
		previewsContainerId : 'videoPreviewsContainer'
	});
	
	// константа, приходит с сервера, содержит настройки сортировки для столбцов
	var bindOptions = bindOptions || {};

	var numbersOptions = window.numbersOptions, // константа, приходит с сервера, содержит информацию, является ли первый столбец списком порядковых номеров (в этом случае сортировать его не нужно)
		widgetsOptions = [ 'zebra' ], // виджет "zebra" по умолчанию применяется для всех таблиц
		sortListOptions = window.sortListOptions || [];
		
	// виджет "numbers" применяется опционально на тех страницах, где он нужен
	if (numbersOptions) {
		widgetsOptions.push('numbers');
	}
	
	var checkAttributeToSort = function (node) {
		var attributeToSort = node.getAttribute('sortOrder');
		
		return attributeToSort || $(node).text();
	};
	
	// Sorting tables
	$('table.b-table-sortlist').tablesorter({
		cssAsc : 'sort-up',
		cssDesc : 'sort-down',
		cssHeader : 'sort-none',
		cssSkip : 'sort-skip',
		headers : bindOptions,
		widgets : widgetsOptions,
		widgetZebra : { css : [ 'tr_0', 'tr_1' ] },
		textExtraction : checkAttributeToSort,
		sortList : sortListOptions,
		dateFormat : 'dd.mm.yyyy'
	});
	
	// управление фотографиями в "Фотоленте" (сортировка и пр.)
	var photoSortContainer = $('#photoSort'),
		photoFeedContainer = $('#allPhotos');
	
	if (photoSortContainer.length && photoFeedContainer.length) {
		photoFeedManager(photoSortContainer, photoFeedContainer);
	}
	
	// переключение групп в Турнирной Таблице
	var groupChangeContainer = $('#tournamentGroupChange');

	if (groupChangeContainer.length) {
		groupChangeManager.init(groupChangeContainer);
	}
	
	var yearSwitcherContainer = $('#yearSwitcher');

	if (yearSwitcherContainer.length) {
		yearSwitcher.init(yearSwitcherContainer);
	}
}

var loginField = function()
{
	$("#fanat-strip input[name='openid_url']").each(loginFieldEvents);
};
function loginFieldEvents()
{
	var defaultValue = 'Ваш логин';
	$(this).focus(function(){
		if($(this).val() == defaultValue) $(this).val('').css({ color: '#111111' });
	}).blur(function(){
		var v = $(this).val().replace(/\s/g, '');
		if(v == '' || v == defaultValue.replace(/\s/g, '')) $(this).val(defaultValue).css({ color: '#808080' });
	}).trigger('blur');
}

var yearSwitcher = (function () {
	var _container, yearControls,
		ID_PREFIX = 'ty';
		
	function getYearContainer (year) {
		return $('#' + ID_PREFIX + year);
	}
	
	function bindEvents () {
		var firstYear, firstYearContainer, prevContainer, prevControl, firstControl;
		
		yearControls = _container.find('a');
		
		firstControl = yearControls.first();
		firstYear = firstControl.text();
		firstYearContainer = getYearContainer(firstYear);
		
		prevYearContainter = firstYearContainer;
		prevControl = firstControl;
		
		for (var i = 0, l = yearControls.length; i < l; i++) {
			(function (i) {
				var currentControl, currentYearContainer, currentYear;
				
				currentControl = $(yearControls[i]);
				currentYear = currentControl.text();
				currentYearContainer = getYearContainer(currentYear);
				
				currentControl.click(function (e) {
					e.preventDefault();
					
					if ($(this).hasClass('active')) {
						return;
					}
					
					currentYearContainer.show();
					currentControl.addClass('active');
					
					prevYearContainter.hide();
					prevControl.removeClass('active');
					
					prevYearContainter = currentYearContainer;
					prevControl = currentControl;
				});
			})(i);
		}
	}
	
	return {
		init : function (container) {
			_container = container;
			bindEvents();
		}
	}
})(); 

var rating = function(pid, authorOrPhoto)
{
	var CONFIG = {
			author : {
				elemSelector : 'div.rating',
				loginMessageSelector : 'dd.login-alert',
				outOfDateMessageSelector : 'dd.login-alert-out-date',
				url : '/includes/author_rate.php',
				getParamsToSend : function (cur, pid, aid) {
					return {
						'pub_type' : 'article',
						'pub_id' : pid,
						'act' : 'rate',
						'r' : parseInt(cur, 10),
						'a_id' : aid
					};
				},
				checkAlreadyRated : function (uid, pid, aid) {
					return use_cookie('r_' + uid + '_' + pid + '_' + aid);
				}
			},
			photo : {
				elemSelector : '#photoRating',
				loginMessageSelector : '#loginAlertMessage',
				outOfDateMessageSelector : '#outOfDateMessage',
				url : '/includes/photo/rate.php',
				getParamsToSend : function (cur, pid, aid) {
					return {
						'pub_type' : 'photo',
						'pub_id' : pid,
						'act' : 'rate',
						'r' : parseInt(cur, 10)
					};
				},
				checkAlreadyRated : function (uid, pid, aid) {
					return use_cookie('r_' + uid + '_ph' + pid);
				}
			}
		},
		
		currentConfig = CONFIG[authorOrPhoto],
		els = $(currentConfig.elemSelector),
		uid = use_cookie('phpbb3_champ_u'),
	    logined = uid !== '' && uid > 1,
	    notexp = +(new Date()) < (deny_com_from * 1000);
		
	if(logined && notexp)
	{
		els.each(function(){
			var els = $(this),
			    lis = els.find('li'),
			    aid = els.attr('a_id') || pid,
				
				// is it (photo or author) already reated (from cookie)
			    cur = currentConfig.checkAlreadyRated(uid, pid, aid),
			    highlight = function(i){
			    	lis.removeClass('sel current');
			    	if(i) lis.eq(i-1).prevAll().addClass('sel').end().addClass('sel current');
			    };
				
			if(!cur)
			{
				lis.mouseenter(function(){
					highlight($(this).html());
				}).click(function(){
					els.css({ opacity: 0.6 });
					cur = $(this).html();
					$.getJSON(currentConfig.url, currentConfig.getParamsToSend(cur, pid, aid), function(data){
						els.css({ opacity: 1 });
						if(data[aid])
						{
							$('#author' + aid).html(data[aid]);
						}
						if(data.errmsg) alert(data.errmsg);
						if(data.voted)
						{
							cur = data.voted;
							highlight(cur);
						}
						if(data[aid] || data.voted)
						{
							els.addClass('rated');
							lis.unbind('mouseenter mouseleave');
						}
					});
				});
				els.find('ol').mouseleave(function(){
					highlight(cur);
				});
			}
			if(cur)
			{
				highlight(cur);
				els.addClass('rated');
			}
		});
	}
	else
	{
		var parent = els.addClass('rated').parent('div.b-rating');
		parent.addClass('rating-disabled');
	}

	$(currentConfig.loginMessageSelector).css({
		display: logined ? 'none' : 'block'
	});
	$(currentConfig.outOfDateMessageSelector).css({
		display: (logined && notexp) || !logined ? 'none' : 'block'
	});
};

var live_table = function(obj)
{
	this.obj = $(obj);
	this.tabs = $('.live-sections li', this.obj);
	this.viewport = $('.content-wrap', this.obj);
	this.viewport.h = this.viewport[0].clientHeight;
	this.body = $('.content-main', this.obj);
	this.viewport.scroll = $('.scroll', this.obj);
	this.scroller = $('#scroller-wrap');
	this.transCount = $('#translations-count');
	this.currentSport = window.sport;
	
	this.scroller.recalc = function(nh)
	{
		var freeSpace = nh - that.body.outerHeight(),
		    optionMin = Math.min(freeSpace, 0);
		that.scroller.slider('option', 'min', optionMin);
		that.scroller.slider('value', freeSpace >= 0 ? 0 : that.scroller.slider('value'));

		if(optionMin == 0)
		{
			that.viewport.scroll.css('visibility', 'hidden');
			$('.actions .inc', that.obj).addClass('inactive');
			$('.actions .all', that.obj).addClass('inactive');
		}
		else
		{
			that.viewport.scroll.css('visibility', 'visible');
			$('.actions .inc', that.obj).removeClass('inactive');
			$('.actions .all', that.obj).removeClass('inactive');
		}

		$('.actions .dec', that.obj).removeClass('inactive');
		$('.actions .min', that.obj).removeClass('inactive');
		if(nh <= 64)
		{
			$('.actions .dec', that.obj).addClass('inactive');
			$('.actions .min', that.obj).addClass('inactive');
		}
	};
	this.warning = {
		'live': 'Live-трансляций в ближайшее время не запланировано',
		'live_video': 'Видео-трансляций в ближайшее время не запланировано',
		'live_result': 'Соревнований за последнее время не было',
		'live_tv': 'Нет передач в ближайшее время'
	};
	this.cacheTime = {
		'live': 60000,
		'live_video': 60000,
		'live_result': 300000,
		'live_tv': 300000
	};
	this.sectionClass = {
		'tennis': 'section-scored'
	};
	this.months = {
		0: 'января',
		1: 'февраля',
		2: 'марта',
		3: 'апреля',
		4: 'мая',
		5: 'июня',
		6: 'июля',
		7: 'августа',
		8: 'сентября',
		9: 'октября',
		10: 'ноября',
		11: 'декабря'
	};
	this.cache = new Object();
	this.timer = null;
	this.lock = false;
	this.lockLoad = false;
	this.min = 64;
	this.resizeLock = false;
	
	this.tabs.click(function(event)
	{
		event.preventDefault();
		if(that.lock) return false;
		that.lock = true;
		var obj = $(this);
		if(!obj.hasClass('current'))
		{
			that.tabs.removeClass('current');
			that.active = obj.find('a').attr('href').match('([a-z\_]+)$')[1];
			use_cookie('liveTableActive', that.active, {expires: 365, path: '/'});
			that.load();
			obj.addClass('current');
		}
		that.lock = false;
	});
	
	this.load = function()
	{
		if(that.timer) clearTimeout(that.timer);
		if(!that.lockLoad)
		{
			if(that.cache[that.active])
			{
				that.render();
			}
			else if(that.active)
			{
				$.getJSON('/' + that.active + '.json?' + Math.random(), that.render);
			}
		}
		that.timer = setTimeout(function(){
			that.cache[that.active] = null;
			that.load();
		}, that.cacheTime[that.active]);
	};
	
	this.empty = function(obj)
	{
		if(!obj) return true;
		for(i in obj) return false;
		return true;
	};
	
	this.render = function(data)
	{
		that.lock = true;
		that.body.css('display', 'none');
		that.body.html('');
		
		that.obj[0].className = '';
		if(that.active == 'live') that.obj[0].className = 'all-translations';
		if(that.active == 'live_tv') that.obj[0].className = 'tv-broadcast';
		if(that.active == 'live_video') that.obj[0].className = 'video-translations';

		if(that.cache[that.active])
		{
			that.body[0].innerHTML = that.cache[that.active];
		}
		else if(that.empty(data))
		{
			that.body.html('<p class="live-message">' + that.warning[that.active] + '</p>');
		}
		else
		{
			if(that.active == 'live' || that.active == 'live_result')
			for(sportType in data)
			{
				if(that.currentSport && that.currentSport != sportType) continue;
				var isCols = (sportType == 'football' || sportType == 'hockey'),
				    s = that.section(that.sectionClass[sportType], isCols),
				    h = '<span>' + data[sportType].title + '.</span>',
				    c = s,
				    tmpdata = data[sportType].match_data;
				if(tmpdata)
				for(match in tmpdata)
				{
					that.header(h + ' ' + match, s, tmpdata[match]['link']);
					if(isCols)
					{
						c = $('<div class="canyon-section"></div><div class="canyon-side"></div>');
						s.append(c);
					}
					for(var i = 0, a = tmpdata[match]['m_data'], l = a.length; i < l; i ++)
					{
						that.row(a[i], isCols && i % 2 != 0 ? c[1] : c[0]);
					}

					that.addClasses(c[0]);
					if(isCols) that.addClasses(c[1]);
				}
			}

			if(that.active == 'live_tv')
			for(day in data)
			{
				var s = that.section(), c;
				that.header('<span>' + that.dayConvert(day) + '</span>', s);
				c = $('<div></div>');
				s.append(c);
				if(data[day])
				for(row in data[day])
				{
					if(that.currentSport && that.currentSport != data[day][row].sport_label) continue;
					that.row(data[day][row], c[0]);
				}
				if(c[0].childNodes.length == 0)
				{
					s.remove();
				}
				else
				{
					that.addClasses(c[0]);
				}
			}

			if(that.active == 'live_video')
			for(sportType in data)
			{
				if(that.currentSport && that.currentSport != sportType) continue;
				var s = that.section('', true), 
				    c, tmpdata = data[sportType].game_data;
				that.header('<span>' + data[sportType].title + '</span>', s);
				c = $('<div class="canyon-section"></div><div class="canyon-side"></div>');
				s.append(c);
				if(tmpdata)
				for(var i = 0, l = tmpdata.length; i < l; i ++)
				{
					that.row(tmpdata[i], i % 2 != 0 ? c[1] : c[0]);
				}
				that.addClasses(c[0]);
				that.addClasses(c[1]);
			}

			if($('dl', that.body).length == 0) that.body.html('<p class="live-message">' + that.warning[that.active] + '</p>');
			
			that.cache[that.active] = that.body.html();
			setTimeout(function()
			{
				that.cache[that.active] = null;
			}, that.cacheTime[that.active]);
		}

		var transCountI = that.body[0].getElementsByTagName('dl').length;
		if(transCountI)
		{
			that.transCount.parent().removeAttr('style');
		}
		else
		{
			that.transCount.parent().css({ visibility: 'hidden' });
		}
		that.transCount.html(transCountI);
		that.body.css('top', '0px');
		that.body.css('display', 'block');
		
		var savedHeight = use_cookie('liveTable' + that.active);
		that.resize(savedHeight ? savedHeight : that.body.outerHeight());
		that.lock = false;
	};
	
	this.row = function(data, obj)
	{
		var dl = document.createElement('dl'),
		    link = data.link,
		    text = data.is_text && data.is_text == 'Y', 
		    title = link ? '<a href="' + link + '">' + data.name + '</a>' : data.name;
		    html = '<dt>' + title + '</dt>' +  
					that.dd(data.time, 'time', link) +
					(typeof(data.result) == 'string' ? that.dd(data.result, 'score', link) : '') + 
					(data.channel ? that.dd(data.channel, 'channel', link) : '') + 
					(data.sport ? that.dd(data.sport, 'sport', link) : '') + 
					(data.is_text ? that.dd(text ? 'текст' : false, 'text', link) : '') +  
					(data.status ? that.dd(data.status, 'state', link) : '') +
					(data.live ? that.dd(data.live == 'Y' ? 'прямая трансляция' : '', 'state', link) : '') + 
					(data.channels ? that.dd(data.channels + ' ' + that.channel_word(data.channels), 'state', link) : '');

		dl.innerHTML = html;
		obj.appendChild(dl);
	};
	this.channel_word = function(num)
	{
		var res;
		if (num % 100 >= 5 && num % 100 <= 20) {
			res = 'каналов';
		}else if (num % 100 >= 2 && num % 100 <5) {
			res = 'канала';
		} else if (num % 10 == 1) {
			 res = 'канал';
	        } else if (num % 10 == 0){
		         res = 'каналов';
		}else if (num % 10 >= 5 && num % 10 <= 9) {
		         res = 'каналов';
		} else {
		   res = 'канала';
		} 

		return res;	
	};
	this.dd = function(value, css, link)
	{
		var css = css || '';
		if(value === false)
		{
			return '<dd class="' + css + '"></dd>';
		}
		else if(link)
		{
			return '<dd class="' + css + '"><a href="' + link + '">' + value + '</a></dd>';
		}
		else if(css == 'time')
		{
			return '<dd class="' + css + '"><a>' + value + '</a></dd>';
		}
		else
		{
			return '<dd class="' + css + '">' + value + '</dd>';
		}
	};
	this.header = function(data, obj, link)
	{
		if(link) data = '<a href="' + link + '">' + data + '</a>';
		obj.append('<h3>' + data + '</h3>');
	};
	this.section = function(css, isCols)
	{
		var css = css || '',
		    obj = $('<div class="section ' + css + (isCols ? ' section-doubled canyon' : '') + '"></div>');
		that.body.append(obj);
		return obj;
	};
	this.addClasses = function(obj)
	{
		$('dl:first', obj).addClass('first');
		$('h3 + dl:not(.first):first', obj).addClass('first');
		$('dl:last', obj).addClass('last');
	};
	
	this.scroll = function(event, ui)
	{
		that.body.css('top', ui.value + 'px');
	};
	this.slideStart = function(event)
	{
		var inc = this.id.indexOf('top') == -1 ? -5 : 5;
		that.scrollTimer = setInterval(function()
		{
			that.scroller.slider('value', that.scroller.slider('value') + inc);
		}, 40);
	};
	this.wheelStart = function(event)
	{
		if(that.scroller.slider('option', 'min'))
		{
			event.preventDefault();
			that.scroller.slider('value', that.scroller.slider('value') + (event.delta * 5));
		}
	};
	this.slideEnd = function(event)
	{
		clearInterval(that.scrollTimer);
	};
	this.resizeClick = function(event)
	{
		var css = this.className,
		    isAll = css.indexOf('all') != -1,
		    isMin = css.indexOf('min') != -1;
		if(css.indexOf('inactive') == -1 && !that.resizeLock)
		{
			var inc = css.indexOf('dec') == -1 ? 60 : -60,
			    nh = that.viewport.height() + inc;
			if(isAll) nh = that.body.outerHeight();
			if(isMin) nh = that.min;
			use_cookie('liveTable' + that.active, nh, {expires: 365, path: '/'});
			that.resizeLock = true;
			that.resize(nh);
		}
	};
	this.resize = function(nh)
	{
		if(nh > that.body.outerHeight())
		{
			nh = that.body.outerHeight();
		}
		else if(nh < that.min && that.body.outerHeight() > that.min)
		{
			nh = that.min;
		}
		that.scroller.recalc(nh);
		that.height(nh);
	};
	this.height = function(nh, speed)
	{
		var speed = speed || 100;
		use_cookie('liveLast', nh, {expires: 365, path: '/'});
		that.viewport.animate({ height: nh + 'px' }, speed, null, function(){ that.resizeLock = false });
		that.viewport.scroll.animate({ height: nh + 'px' }, speed);
		that.scroller.css('height', nh - 54 + 'px');
	};
	
	this.dayConvert = function(day)
	{
		var part = day.match(/([0-9]{4})\-([0-9]{2})\-([0-9]{2})/),
		    now = new Date();
		    dt = part ? new Date(part[1], part[2] - 1, part[3]) : new Date(now);
		now = new Date(now.getFullYear(), now.getMonth(), now.getDate());
		return dt.getDate() + ' ' + that.months[dt.getMonth()] + (dt - now == 0 ? ', сегодня' : '') + (dt - now == 86400000 ? ', завтра' : '');
	};
	
	var that = this;
	that.scroller.slider({
		orientation: 'vertical',
		min: -1,
		max: 0,
		value: 0
	});
	if(use_cookie('liveLast')) that.height(use_cookie('liveLast'), 1);

	$('#scroll-top').bind('mousedown', that.slideStart);
	$('#scroll-bottom').bind('mousedown', that.slideStart);
	$('#scroll-top').bind('mouseup mouseleave', that.slideEnd);
	$('#scroll-bottom').bind('mouseup mouseleave', that.slideEnd);
	that.scroller.bind('slide slidechange', that.scroll);
	$('.actions .dec, .actions .inc, .actions .min, .actions .all', that.obj).bind('click', that.resizeClick);
	that.body.wheel(that.wheelStart);

	if(use_cookie('liveTableActive') === null) use_cookie('liveTableActive', 'live', {expires: 365, path: '/'});
	
	that.active = use_cookie('liveTableActive');
	$('a[href$=#' + that.active + ']', that.tabs).parent().trigger('click');
	
	$(document).ready(function(){
		$(window).blur(function(){ that.lockLoad = true; });
		$(window).focus(function(){
			var tmp = that; 
			that.lockLoad = false; 
			setTimeout(function () { 
				if( !tmp.lockLoad ) { tmp.load(); } 
			}, 500);
			
			//that.lockLoad = false; that.load(); 
		});
	});
};

var archive = function(obj)
{
	this.obj = obj;
	this.now = new Date();
	this.cur = $(obj).attr('date');
	this.min = new Date(2005, 2, 12);
	this.min.compare = new Date(this.min.getFullYear(), this.min.getMonth(), 1);
	this.max = new Date(this.now.getFullYear(), this.now.getMonth(), this.now.getDate());
	if(this.cur)
	{
		var parts = this.cur.match(/([0-9]{4})\-([0-9]{2})\-([0-9]{2})/);
		this.cur = new Date(parts[1], parts[2] - 1, parts[3]);
	}
	else
	{
		this.cur = new Date(this.max);
	}
	//this.url = $(obj).attr('url');
	//this.url = '/' + sport + (section != '' ? '/_' + section : '');
	
	this.sel = new Date(this.cur.getFullYear(), this.cur.getMonth(), 1);
	this.names = ["Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь"];
	
	this.init = function(opt)
	{
		if(opt) 
		{
			$.extend(that, opt);
		}
		else
		{
			this.url = '/' + sport + (section != '' ? '/_' + section : '') + '/{year}-{month}-{day}.html';
		}
		
		if(obj)
		{
			that.obj.month = $('.month', this.obj);
			that.obj.year = $('.year', this.obj);
			that.obj.body = $('table tbody', this.obj);
			
			$('a:first', that.obj.month).bind('click', 'monthPrev', that.set);
			$('a:last', that.obj.month).bind('click', 'monthNext', that.set);

			$('a:first', that.obj.year).bind('click', 'yearPrev', that.set);
			$('a:last', that.obj.year).bind('click', 'yearNext', that.set);
		}
	};
	
	this.generate = function()
	{
		var html = '<tr>',
		    dt = new Date(that.sel),
		    last = 0,
		    month = dt.getMonth() + 1,
			year = dt.getFullYear(),
		    str = '/' + year + '-' + (month < 10 ? '0' + month : month),
			availableDates = [],
			currentDateData = {
				year : year,
				month : month
			},
			paintHtml = function()
			{
				html += that.emptyCells(dt.getDay() == 0 ? 6 : dt.getDay() - 1);
				for(var i = 1; i < 32; i++)
				{
					dt.setDate(i);
					if(!dt || dt.getDate() != i) break;
					
					last = dt.getDay();
					var day = dt.getDate();
					if(day < 10) day = '0' + day;
					
					if(last == 1 && i != 1) html += '<tr>';
					if(dt > that.max || dt < that.min)
					{
						html += '<td><span>'+ dt.getDate() +'</span></td>';
					}
					else
					{
						var sel = (+dt == +that.cur) ? 'current ' : '',
							currentDateHtml = (function(){
								var date = dt.getDate() + '',
									url = '',
									dateUnavailable = !!(that.jsonWithAvailableDates) && ($.inArray(date, availableDates) === -1);
								
								if(dateUnavailable) 
								{
									date = '<span>' + date + '</span>';
								}
								else
								{
									currentDateData.day = day;
									currentDateData.month = (month < 10 ? '0' + month : month);
									url = that.url.supplant(currentDateData);
									date = '<a href="' + url + '">' + date + '</a>';
								}
								
								
								return date;
							})();
		
						sel += (dt.getDay() == 6 || dt.getDay() == 0) ? 'holiday' : '';
						if(sel != '') sel = ' class="' + sel + '"';
						html += '<td' + sel + '>' + currentDateHtml + '</td>';
					}
					if(last == 0) html += '</tr>';
				}
				if(last != 0) html += that.emptyCells(7 - last);
				
				$(that.obj.body).html(html);
				$('span', that.obj.month).html(that.names[that.sel.getMonth()]);
				$('span', that.obj.year).html(that.sel.getFullYear());
		
				$('a:first', that.obj.month).attr('class', (that.monthPrev() < that.min.compare) ? 'prev-disabled' : 'prev');
				$('a:first', that.obj.year).attr('class', (that.yearPrev() < that.min.compare) ? 'prev-disabled' : 'prev');
				
				$('a:last', that.obj.month).attr('class', (that.monthNext() > that.max) ? 'next-disabled' : 'next');
				$('a:last', that.obj.year).attr('class', (that.yearNext() > that.max) ? 'next-disabled' : 'next');
			};
			
		if(this.jsonWithAvailableDates)
		{
			var actualJsonUrl = this.jsonWithAvailableDates.supplant(currentDateData);
			$.getJSON(actualJsonUrl, function(data){
				availableDates = data;
				paintHtml();
			})
		}
		else
		{
			paintHtml();
		}
	};
	
	this.emptyCells = function(cnt)
	{
		var str = '';
		for(var i = 0; i < cnt; i++) str += '<td><span></span></td>';
		return str;
	};
	
	this.monthPrev = function(event)
	{
		var month = that.sel.getMonth();
		return new Date(that.sel.getFullYear() - (month == 0 ? 1 : 0), month == 0 ? 11 : month - 1, 1);
	};
	this.monthNext = function(event)
	{
		var month = that.sel.getMonth();
		return new Date(that.sel.getFullYear() + (month == 11 ? 1 : 0), month == 11 ? 0 : month + 1, 1);
	};

	this.yearPrev = function(event)
	{
		var year = that.sel.getFullYear();
		return new Date(year - 1, that.sel.getMonth(), 1);
	};
	this.yearNext = function(event)
	{
		var year = that.sel.getFullYear();
		return new Date(year + 1, that.sel.getMonth(), 1);
	};
	
	this.set = function(event)
	{
		event.preventDefault();
		if(this.className.indexOf('disabled') == -1)
		{
			that.sel = that[event.data]();
			that.generate();
		}
	};
	
	this.loadAvailableDates = function(year, month, callback)
	{
		var path = that.url + '/' + year + '/' + month + '.json';
		$.getJSON(path, callback);
	};

	var that = this;
	
	var opt = window.archiveOptions || null;
	
	that.init(opt);
	that.generate();
};

var newslist = function()
{
	this.obj = $('ul.news-list');
	this.lis = this.obj.find('li');
	this.opt = this.obj.prev('dl.inline-options').find('dd.option');
	this.menu = $('div.sections-sports ul.canyon-side');
	this.type = use_cookie('newsList') || '0';
	
	this.highlight = function(event)
	{
		var type = event ? event.data : that.type;
		if(!that.opt.eq(type).hasClass('option-selected'))
		{
			that.opt.removeClass('option-selected').eq(type).addClass('option-selected');
			use_cookie('newsList', type, {expires: 365,path:'/'});
			that['resort' + type]();
		}
	};
	
	this.resort0 = function()
	{
		var prev;
		that.lis.sort(function(a, b){
			return b.h - a.h;
		});
		that.lis.each(function(i, li){
			if(!prev || prev != li.p)
			{
				var a = that.menu.find('li:contains('+$(li).find('span.meta-sport').html()+')').find('a'),
				    div = $('<li class="sport"></li>');
				that.obj.append(div);
				div.append(a.clone());
			}
			that.obj.append(li);
			prev = li.p;
		});
	};
	
	this.resort1 = function()
	{
		that.obj.find('li.sport').remove();
		that.lis.sort(function(a, b){
			return b.d - a.d;
		});
		that.lis.each(function(i, obj){
			that.obj.append(obj);
		});
	};
	
	var that = this;
	that.opt.each(function(i, obj){ $(obj).bind('click', i, that.highlight); });
	that.lis.each(function(i, obj){
		var data = obj.onclick();
		obj.p = parseFloat(data.p);
		obj.d = parseFloat(data.d + $(obj).find('span.time').html().replace(':', ''));
		obj.h = (obj.p * -100000000) + obj.d;
		obj.removeAttribute('onclick');
	});
	that.highlight();
};

var comments = function()
{
	var form = $('#commentForm'),
	    prefix = form.attr('cookpre'),
	    openid = form.attr('openid');
	
	this.init = function()
	{
		var isLogined = use_cookie(prefix + 'u') && use_cookie(prefix + 'u') > 1;
		
		if(typeof(deny_com_from) != 'undefined' && (new Date()).getTime() > deny_com_from * 1000)
		{
			$('body').addClass('old-content');
			$('#comment_form_expired').removeClass('hidden');
		}
		else if(isLogined)
		{
			var fanat = use_cookie(prefix + 'fanatid');
			$('#comment_form > a.username').attr('href', 'http://' + fanat + '.' + openid).html(fanat);
			$('#comment_form').removeClass('hidden');
			$('#parent_id').attr('value', '');
		}
		else
		{
			$('#comment_form_login > input[name=redirect]').attr('value', document.location.pathname);
			$('#comment_form_login').removeClass('hidden');
		}

		var mode = use_cookie('show_comments') || 'by_pages';
		$('#commentAction li > a').click(that.setMode);
		$('#commentAction li:has(a[href$=#'+mode+'])').addClass('current');

		document.domain = document.location.host.match(/((www\.)?[\w\-]+\.\w+)$/)[1];

		var ual = $('ul.user-action-list'),
		    lis = ual.find('> li:not(:last)'),
		    cwrap = ual.find('> li:last');
		lis.find('a').click(function(event){
			event.preventDefault();
			var el = $(this),
			    hash = el.attr('href').match(/#(\w*)/)[1];
			cwrap.removeClass('bug-report-block blog-this-block');
			lis.removeClass('active');
			if(hash)
			{
				$('html, body').animate({ scrollTop: $('a[name='+hash+']').offset().top }, 'normal');
			}
			else
			{
				var li = el.parents('li:first'),
				    type = li.attr('class');
				cwrap.addClass(type + '-block');
				li.addClass('active');
				if(type == 'bug-report' && isLogined)
				{
					cwrap.find('p.desc').html('Отправка сообщения об ошибке в редакцию');
					cwrap.find('form').css({ display: 'block' });
				}
				else
				{
					cwrap.find('p.desc').html('Чтобы отправить сообщение, необходимо войти под своим логином');
					cwrap.find('form').css({ display: 'none' });
				}
				if(syncFrame) syncFrame();
			}
		});

		var btm = $('ul.blog-this-menu li');
		btm.find('a').click(function(){
			btm.removeClass('active');
			$(this).parents('li:first').addClass('active');
		});

		cwrap.find('a.close-button').click(function(event){
			event.preventDefault();
			cwrap.removeClass('bug-report-block blog-this-block');
			lis.removeClass('active');
		});
	};
	
	this.list = function()
	{
		$('div.b-comments-list dd.reply > a').click(that.replyComment);
	};

	this.setMode = function(event)
	{
		event.preventDefault();
		var mode = event.target.href.match(/#([a-z\_]+)$/);
		use_cookie('show_comments', mode[1], {expires: 365,path:'/'});
		window.location.reload();
		return false;
	};
	
	this.replyComment = function(event)
	{
		var parent = $(event.target).parents('dl'),
		    user =  $('a.username', parent),
		    pid = parent.prev('a').attr('name').match(/([0-9]+)/),
		    cancel = $('<b class="b-icon b-icon-cancel" title="Не отвечать"><b class="b-icon-in"></b></b>');
		
		if(!user.length) user = $('dt > b:has(span)', parent);
		user = user.eq(0);
		
		$('#comment_form > span').html('&nbsp;в ответ на <a href="#c'+pid[1]+'">комментарий</a> ').append(user.clone()).append(cancel);
		$('#parent_id').attr('value', pid[1]);
		$('#comment_form input[type=submit]').attr('value', 'Ответить на комментарий');
		cancel.click(that.replyCancel);
	};
	this.replyCancel = function()
	{
		$('#comment_form > span').html('');
		$('#parent_id').attr('value', '');
		$('#comment_form input[type=submit]').attr('value', 'Оставить комментарий');
	};
	
	var that = this;
	window.replyCancel = that.replyCancel;
	that.init();
};

var groupChangeManager = (function () {
	var container_, parentContainer,
		prevGroupContainer = [ ],
		groups = [ ],
		control = $('<span class="b-box-header-filter"><select /></span>').css('text-transform', 'none'),
		select = control.find('select'); 
	
	function addControl () {
		var currentOption, currentGroup, currentName, currentGroupContainer;
		
		if (groups.length === 0) {
			return false;
		}
		
		for (var i = 0, l = groups.length; i < l; i++) {
			currentGroup = $(groups[i]);
			currentName = currentGroup.text();
			
			currentGroupContainer = currentGroup.parent();
			
			if (i !== 0) {
				currentGroupContainer.hide();
			} else {
				prevGroupContainer = currentGroupContainer;
			}
			
			(function (currentGroupContainer) {
				currentOption = $('<option />', {
					val : currentName,
					text : currentName/*,
					click : function () {
						currentGroupContainer.show();
						prevGroupContainer.hide();
						prevGroupContainer = currentGroupContainer;
					}*/
				});
			})(currentGroupContainer);
			
			select.append(currentOption);
		}

		select.change(function () {
			var currentValue = $(this).val(),
				currentGroupContainer = parentContainer.find('h4:contains(' + currentValue + ')').parent();
			
			currentGroupContainer.show();
			prevGroupContainer.hide();
			prevGroupContainer = currentGroupContainer;				
		});
		
		container_.after(control);
	}
	
	function findGroups () {
		parentContainer = container_.parent();
		groups = parentContainer.find('h4');
	}
	
	return {
		init : function (container) {
			container_ = container;
			
			findGroups();
			addControl();
		}
	};
})();

/**
 * управление фотографиями в "Фотоленте" (сортировка и пр.)
 * 
 * @param {jQuery} photoSortContainer
 * @param {jQuery} photoFeedContainer
 */
var photoFeedManager = function (photoSortContainer, photoFeedContainer) {
	var SORT_COOKIE_NAME = 'photoFeedSortType',
		SORT_DIRECTION = 'desc',
		DEFAULT_SORT_TYPE = 'sort_order',
		SORT_TYPE_ATTRIBUTES = {
			'по порядку' : 'sort_order',
			'по рейтингу' : 'rating',
			'по комментариям' : 'num_comm'
		},
	
		defaultSort = checkSortTypeCookie(),
	
		bigPhotoContainer = $('.b-photo-pic'),
		bigPhotoLink = bigPhotoContainer.find('a:has(img)'),
		currentPhotoId = bigPhotoContainer.attr('photo_id'),
		currentPhotoInFeed = $('#ph_' + currentPhotoId),
		nextButton = bigPhotoContainer.find('a.raquo'),
		prevButton = bigPhotoContainer.find('a.laquo'),
		
		photosToSort = photoFeedContainer.find('li'),
		previousSortControl = photoSortContainer.find('li.current'), currentSortControl;
		
	function setSortTypeCookie (sortType) {
		if (sortType == DEFAULT_SORT_TYPE) {
			clearCookie(SORT_COOKIE_NAME);
			return;
		}
		
		setCookie(SORT_COOKIE_NAME, sortType);	
	}
	
	function checkSortTypeCookie () {
		var defaultSortType = getCookie(SORT_COOKIE_NAME);
		
		return defaultSortType;
	}
	
	function sortIt (sortType) {
		photosToSort.tsort({
			attr : sortType,
			order : SORT_DIRECTION
		});		
	}
	
	function toggleMarker () {
		currentSortControl
			.addClass('current')
			.find('a')
				.replaceWith(function () {
					return document.createTextNode($(this).text());
				});
		
		previousSortControl
			.removeClass('current')
			.wrapInner('<a href="#"></a>');
		
		previousSortControl = currentSortControl;
	}

	function setNavButtonsHrefs () {
		var nextPhotoInFeed = currentPhotoInFeed.next('li'),
			prevPhotoInFeed = currentPhotoInFeed.prev('li'),
			firstPhotoLink = currentPhotoInFeed.parent().find('li').first().find('a').attr('href'),
			lastPhotoLink = currentPhotoInFeed.parent().find('li').last().find('a').attr('href'),			
			nextPhotoLink, prevPhotoLink;

		if (nextPhotoInFeed.length) {
			nextPhotoLink = nextPhotoInFeed.find('a').attr('href');
			nextButton.attr('href', nextPhotoLink).show();
			bigPhotoLink.attr('href', nextPhotoLink);
		} else {
			
			
			
			nextButton.attr('href', firstPhotoLink);
			bigPhotoLink.attr('href', firstPhotoLink);
		}
		
		if (prevPhotoInFeed.length) {
			prevPhotoLink = prevPhotoInFeed.find('a').attr('href');
			prevButton.attr('href', prevPhotoLink).show();
		} else {
			prevButton.attr('href', lastPhotoLink);
		}
	}
	
	function highlightCurrentPhoto () {
		currentPhotoInFeed.addClass('current');
	}

	if (defaultSort) {
		currentSortControl = photoSortContainer.find('li.' + defaultSort);
		
		sortIt(defaultSort);
		toggleMarker(previousSortControl, currentSortControl);
	}
	
	setNavButtonsHrefs();
	highlightCurrentPhoto();
	
	bigPhotoContainer.show();
	photoFeedContainer.show();
	photoSortContainer.fadeIn('fast');
	
	photoSortContainer.live('click', function (e) {
		var targetLink = $(e.target).filter('a'),
			sortType;
		
		if (!targetLink.length) {
			return;
		}
		
		e.preventDefault();
		
		currentSortControl = targetLink.closest('li'); 
		
		sortType = SORT_TYPE_ATTRIBUTES[targetLink.text()];
		
		sortIt(sortType);
		toggleMarker(previousSortControl, currentSortControl);
		
		setSortTypeCookie(sortType);
		setNavButtonsHrefs();
	});
};

var tvProgramSectionsSelector = {
	elems : {
		controls : [],
		data : []
	},
	previousData : $([]),
	
	init : function (opt) {
		var elems = this.elems;
		
		elems.days = $('.' + opt.dayProgramContainerClass);
		if (elems.days.length === 0) {
			return;
		}
		
		this.allRows = this.elems.days.find('tr').not(':has(th)');
		elems.controls = $('#' + opt.tvChannelsListId).find('a');
		elems.showAll = $('#showAllTvChannels'); 
		
		var that = this,
			controls = elems.controls,
			data = elems.data,
			previousData = this.allRows;
		
		for (var i = 0, l = controls.length; i < l; i++) {
			(function (i) {
				var currentControl = $(controls[i]).attr('href', '#'),
					channelTitle = currentControl.attr('title'),
					currentData = $('td[title=' + channelTitle + ']').parents('tr');

				currentControl.click(function (e) {
					e.preventDefault();
					
					previousData.hide();
					
					currentData
						.show()
						.each(function () {
							var currentParent = $(this).parents('div').eq(0);
							currentParent.show();						
						});
					
					that.paintStripes();
					
					previousData = currentData;
				});
			})(i);
		}
		
		elems.showAll.click(function (e) {
			e.preventDefault();
			
			that.elems.days.show();
			previousData = that.allRows.show();
			that.paintStripes();
		});
	},
	
	paintStripes : function () {
		this.elems.days
			.each(function () {
				var currentDay = $(this),
					currentRows = currentDay.find('tr:visible').slice(1);
				
				if (currentRows.length === 0) {
					currentDay.hide();
				} else {
					currentRows
						.removeClass('odd')
						.filter(':even')
							.addClass('odd');
				}
			});
	}
};

var videoPreviewSwitcher = {
	init : function (opt) {
		var linksList = $('#' + opt.linksListId),
			previewsContainer = $('#' + opt.previewsContainerId);
		
		if (linksList.length === 0 || previewsContainer.length === 0) {
			return;
		}
		
		var links = linksList.find('a'),
		
			firstLink = $(links[0]),
			firstId = firstLink.attr('id'),
			firstPreview = previewsContainer.find('#' + firstId),
			firstLinkContainer = firstLink.parents('li:first'),
			
			previousPreview = firstPreview,
			previousLinkContainer = firstLinkContainer;
		
		for (var i = 0, l = links.length; i < l; i++) {
			var currentLink = $(links[i]);
			
			(function (currentLink) {
				var currentId = currentLink.attr('id'),
					currentHref = currentLink.attr('href'),
					currentLinkContainer = currentLink.parents('li:first'),
					currentPreview = previewsContainer.find('#' + currentId);
				
				currentLink
					.click(function (e) {
						e.preventDefault();
						
						if (currentLinkContainer.hasClass('selected')) {
							return;
						}
						
						currentPreview.show();
						currentLinkContainer.addClass('selected');
						
						previousPreview.hide();
						previousLinkContainer.removeClass('selected');
						
						previousPreview = currentPreview;
						previousLinkContainer = currentLinkContainer; 
					})
					.dblclick(function (e) {
						e.preventDefault();
						
						window.location.href = currentHref;
					});
			})(currentLink);
		}
	}
};

var videoHidePreviewOfCurrent = {
	init : function (opt) {
		var currentVideoContainer = $(opt.currentVideoContainer),
			previewsContainer = $(opt.previewsContainer);

		if (!currentVideoContainer || !previewsContainer) {
			return;
		}
		
		var currentVideoId = currentVideoContainer.attr('id'),
			currentVideoPreview = previewsContainer.find('#' + currentVideoId);
		
		currentVideoPreview.hide();
	}
};


eval(function(p,a,c,k,e,r){e=function(c){return c.toString(a)};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('7 8={e:9(a){7 b=\'\';f(7 i=0,l=a.g;i<l;i++)b+=8.r()+(a.m(i)+5*h).n(6*2*3)+8.r();c b},d:9(a){7 b=\'\';f(7 i=0,l=a.g/4;i<l;i++)b+=o.p(q(a.s((i*4)+1,2),6*2*3)-(5*h));c b},r:9(){7 a=j.t(j.u()*k);c a==k||a==0||a==5?\' \':a}};',31,31,'|||||||var|ml|function|||return|||for|length|111||Math|10||charCodeAt|toString|String|fromCharCode|parseInt||substr|round|random'.split('|'),0,{}));

var hrefPrefix = ml.d('7ig16i467ic 9if 2in2 ii2') + ':',
    unParseM = function(){
	var el = $(this);
	setTimeout(function(){
		var m = ml.d(el.attr('name').replace('m-', ''));
		el.html(m).attr('href', hrefPrefix + m);
	}, (Math.random() * 500) + 1000);
};

