function sf(txt){
	document.write(txt);
}
function switch_job_group(groupid){
	if(document.getElementById("jgroup"+groupid).style.display=="block")
		document.getElementById("jgroup"+groupid).style.display="none";
	else{
		var l=document.getElementById("job").getElementsByTagName("div");
		for(var i=0;i<l.length;++i)
			if(l[i].className=="jgroup")
				l[i].style.display="none";
		document.getElementById("jgroup"+groupid).style.display="block";
	}
}
function switch_job_item(itemid){
	if(document.getElementById("b"+itemid).style.display=="block")
		document.getElementById("b"+itemid).style.display="none";
	else{
		var l=document.getElementById("job").getElementsByTagName("div");
		for(var i=0;i<l.length;++i)
			if (l[i].className=="block")
				l[i].style.display="none";
		document.getElementById("b"+itemid).style.display="block";
	}
}
function uswitch(rootid,itemid,cname){
	var l=document.getElementById(rootid).getElementsByTagName("div");
	if(document.getElementById(itemid).style.display=="block")
		document.getElementById(itemid).style.display="none";
	else{
		for(var i=0;i<l.length;++i)
			if(l[i].className==cname)
				l[i].style.display="none";
		document.getElementById(itemid).style.display="block";
	}
}
function sswitch(itemid){
	if(document.getElementById(itemid).style.display=="block")
		document.getElementById(itemid).style.display="none";
	else
		document.getElementById(itemid).style.display="block";
}
function show_city(i2){
	uswitch('region','b'+i2,'block');
	document.location.href="http://www.baltlease.ru/contacts/#bb"+i2;
}

function inner_lightbox()
{
	var images = $('.content-inner img');
	var img;
	var parent;
	var regex = [/window\.open\(['"]?(.*?)['"]?,/i, /window\.open\(this\.href,/i];
	var match;
	var content;

	for (var i = 0; i < images.length; i++)
	{
		img = $(images[i]);
		parent = img.parent();

		/**
		 * Пропустить картинки, которые:
		 * - расположены внутри слайдера логотипов производителей автомобилей.
		 * - являются контентом слайдера фото в контактах.
		 * - имеют атрибутом _no_prettyphoto="true"
		 */
		if (img.is('.brands-carousel img, .techline img')
			|| img.parents('#slidebox, #contact-address-map').length > 0
			|| img.attr('_no_prettyphoto') == 'true')
		{
			continue;
		}

		if (parent.is('a') && parent.attr('onclick') != undefined)
		{
			if (match = regex[1].exec(parent.attr('onclick')))
			{
				content = $('<a href="'+parent.attr('href')+'&prettyPhoto" rel="prettyPhoto" title=" "></a>');

				img.appendTo(content);
				parent.replaceWith(content);
			}

			continue;
		}

		if (img.attr('onclick'))
		{
			if (match = regex[0].exec(img.attr('onclick')))
			{
				content = $('<a href="'+match[1]+'" rel="prettyPhoto" title=" "></a>');

				img.removeAttr('onclick').unbind('click').clone().appendTo(content);
				img.replaceWith(content);
			}

			continue;
		}

		// Convert simple image into PrettyPhoto
		if (!parent.is('a'))
		{
			content = $('<a href="'+img.attr('src')+'" rel="prettyPhoto" title=" "></a>');

			img.clone().appendTo(content);
			img.replaceWith(content);
		}
	}
}

$(function(){
	$(".georeg h2").click(function(){
		var info=$('.info',$(this).parent());
		if(info.css("display")=='none')
			info.show('slow');
		else
			info.hide('slow');
	});
	$(".expand").click(function(){
		var info=$('.tail');
		if(info.css("display")=='none'){
			info.show();
			$("a.expand").html('Скрыть');
		}else{
			info.hide();
			$("a.expand").html('Показать всех');
		}
		return false;
	});

	if( true || !$.browser.msie || !location.pathname.match( /specs\/read\/\d+/ ) )
	{
		var correct_pp = $("a[class^='prettyPhoto']");

		if (correct_pp.length > 0)
		{
			correct_pp.attr('rel', correct_pp.attr('class')).removeAttr('class');
		}

		inner_lightbox();

		$("a[rel^='prettyPhoto']").prettyPhoto({
			hideflash: true,
			deeplinking: false,
			social_tools: null
		});
	}

	/** Go-to-top button **/
	$(window).scroll(function(){
		var margin = 10;
		var button = $('#go-to-top');
		var visible = button.is(':visible');
		var pos = $(window).scrollTop();

		if (pos > margin && !visible)
		{
			button.fadeIn(200);
		}
		else if (pos <= margin && visible)
		{
			button.fadeOut(200);
		}
	});

	$('#go-to-top a').click(function(){
		$.scrollTo(0, 300);
		return false;
	});

	$(window).scroll();

	/** Index News Images **/
	$('.sidebar-news-item img')
		.removeAttr('width').removeAttr('height')
		.css('max-width', '60%');
});

