$(document).ready(function(){
	
	var mapImg = new Image();
	mapImg.onload = function(){
		$('.regionsMap').css({
			'background-position': 'left top',
			'background-image': 'url(/i/mapc.gif)'
		});
		
		$('map area').bind('mouseover', function(){
			$('.regionsMap').css({
				'background-position': 'left -' + parseInt(this.id.substr(1)) * 250 + 'px'
			});
			var txt = $(this).attr('data');
			txt = txt.split('||');
			txt = '<b>' + txt[0] + '</b><br />' + txt[1];
			
			$('#mapHint').html(txt).show();
		}).bind('mouseout', function(){
			$('.regionsMap').css({
				'background-position': 'left top'
			});
			$('#mapHint').hide();
		}).bind('mousemove', function(e){
			var left = e.pageX + 10;
			if (left + 330 >= $(window).width()) {
				left = $(window).width() - 330;
			}
			$('#mapHint').css({
				'top': e.pageY + 20,
				'left': left
			});
		}).bind('click', function(){
			location.href = 'http://' + $(this).attr('lnk') + '.fsrar.ru/';
			return false;
		});
	};
	mapImg.src = '/i/mapc.gif';
	
	$('.mapHeader').click(function(){
		location = '/map';
	});
	
	$('.search input').bind('focus', function(){
		if (this.value == 'поиск') {
			this.value = '';
			this.style.color = '#000';
		}
	}).bind('blur', function(){
		if (this.value == '') {
			this.value = 'поиск';
			this.style.color = '#747474';
		}
	});
	
	$('#showFeedBack').bind('click', function(){
		showFeedBack();
		return false;
	});
	
	$('#showSearchExt').bind('click', function(){
		if ($.browser.msie && $.browser.version == 6) {
			location = '/search/'
		} else {
			$('#search_ext').slideDown();
		}
	});
	
	$('#search_ext .bottom').bind('click', function(){
		$('#search_ext').slideUp();
	});
	
	$('#hideFeedBack').bind('click', function(){
		hideFeedBack();
		return false;
	});
	
	$('.menu ul:last').addClass('last');
	
	$('.menu ul li').bind('mouseenter', function(){
		$('ul', this).show();
	}).bind('mouseleave', function(){
		$('ul', this).hide();
	});
	/*
	if (!$.browser.msie && $.browser.version != 6) {
		$('.sitePath').css('width', 'auto');
		if ($('.sitePath').width() > 500) {
			var html = $('.sitePath').html();
			var text = html.split(' &gt; ');
			html = text[0];
			for (var i = 1; i < text.length; i++) {
				if ($('.sitePath').html(html + text[i]).width() > 500) {
					$('.sitePath').html(html);
					break;
				}
				else {
					html += ' &gt; ' + text[i];
				}
			}
		}
	}
	*/
});

function showFeedBack(){
	$('#showFeedBack').hide();
	$('.feedbackForm').slideDown();
}

function hideFeedBack(){
	$('#showFeedBack').show();
	$('.feedbackForm').slideUp();
}

function checkForm(form){
	var fields = $('.notEmpty:visible', form);
	var result = true;
	for (var i = 0; i < fields.length; i++){
		if (fields[i].value == '') {
			$(fields[i]).css('background-color', '#ffc2b2');
			result = false;
		} else {
			$(fields[i]).css('background-color', '#fff');
		}
	}
	if (!result) {
		alert('Поля отмеченные звездочками обязательны для заполнения');
	}
	return result;
}

function showSub(id){
	$('#subMenu' + id).slideToggle('fast');
	return false;
}
