var timer;
var timeout_kotir;
$(document).ready(function()
{
	$('a[href$=".jpg"],a[href$=".gif"],a[href$=".png"]').lightBox();
	//hide the all of the element with class msg_body
	$(".msg_body").hide();
	//toggle the componenet with class msg_body
	$(".msg_head").click(function()
	{
		$(this).next(".msg_body").slideToggle(600);
	});
	// override some default options
	$('div.expandable1 k').expander({
		slicePoint:       1,  // default is 100
		expandText:         'Подробнее', // default is 'read more...'
		collapseTimer:    0, // re-collapses after 5 seconds; default is 0, so no re-collapsing
		userCollapse:     true,
		userCollapseText: '[Скрыть]'  // default is '[collapse expanded text]'
	});
	$('.regbutton, .entercab').mouseover( function() { $('#regico').removeClass('regico').addClass('regico_select'); });
	$('.regbutton, .entercab').mouseout( function() { $('#regico').removeClass('regico_select').addClass('regico'); });
	function refkotir()
	{
		timeout_kotir = raadCookie('BITRIX_SM_GETKOTIR');
		var cssstyle = {"text-decoration":"none","color":"#999999"};
		if(timeout_kotir==60000)
			$('#kotirrefresh a').eq(1).css(cssstyle);
		else if(timeout_kotir==300000)
			$('#kotirrefresh a').eq(2).css(cssstyle);
		else if(timeout_kotir==900000)
			$('#kotirrefresh a').eq(3).css(cssstyle);
		else
			$('#kotirrefresh a').eq(0).css(cssstyle);
	}
	refkotir();
	$('#kotirrefresh a').bind('click',function(){
		switch($(this).index())
		{
			case 2: timeout_kotir=60000;break;
			case 3: timeout_kotir=300000;break;
			case 4: timeout_kotir=900000;break;
			default: timeout_kotir=0;
		}
	setCookie('BITRIX_SM_GETKOTIR',timeout_kotir);
	$('#kotirrefresh a').css({"text-decoration":"underline","color":"#000000"});
	$(this).css({"text-decoration":"none","color":"#999999"});
	});
	if(document.getElementById('kotirovki')) getKotir();
	$('#reg_block a').mouseenter(function(e){
	$(this).children('img').attr('src','/bitrix/templates/mrc new/images/'+$(this).attr('id')+'_act.png');
	$('#reg_block img').first().attr('src','/bitrix/templates/mrc new/images/reg_logomrc_act.png');
	});
	$('#reg_block a').mouseleave(function(e){
	$(this).children('img').attr('src','/bitrix/templates/mrc new/images/'+$(this).attr('id')+'.png');
	$('#reg_block img').first().attr('src','/bitrix/templates/mrc new/images/reg_logomrc.png');
	});
});
function getKotir()
{
if(timer) clearTimeout(timer);
jsAjaxUtil.LoadData('/quotes/quotes_ajax.php?t='+(new Date()).getSeconds(), PutData_kotir);
if(timeout_kotir && timeout_kotir >= 15000) timer = setTimeout(getKotir,timeout_kotir);
};
function PutData_kotir(data){document.getElementById('kotirovki').innerHTML = data;};
function setCookie(name,value)
{
	var dt = new Date();
	dt.setFullYear(dt.getFullYear()+1);
	document.cookie = name + '=' + value + ';expires=' + dt + ';path="/"';
	if(timer) clearTimeout(timer);
	if(value)
	timer = setTimeout(getKotir,15000);
}
function raadCookie(name)
{
	var cookies = document.cookie;
	var start = cookies.indexOf(name + "=");
	if(start == -1)	return false;
	start = cookies.indexOf("=",start)+1;
	var end = cookies.indexOf(";",start);
	if(end == -1) end = cookies.length;
	var value = unescape(cookies.substring(start,end));
	if(value == null)
	{
		setCookie("BITRIX_SM_GETKOTIR",0);
		return false;
	}
	else if(value)
		return value;
	else
		return false;
}
