/**
 * @author Vlad Yakovlev (scorpix@design.ru)
 * @copyright Art.Lebedev Studio (http://www.artlebedev.ru)
 */
$(function() {
	var dots = {};

	var prefixClass = 'type_';

	var rootBlock = $('#main_content .metro_map');

	var dotsSections = rootBlock.find('.dot_icons');

	var defOpacity = 0.7;

	var lightCounter = 0;

	var maxLightCounter = 3;

	var lightTime = 200;

	rootBlock.find('.dots li').each(function() {
		var type = getType($(this).attr('class'));

		dots[type] = dotsSections.filter('.' + prefixClass + type).find('.dot_icon');

		$(this).find('p.link, span.link').hover(function() {
			lightCounter = 0;
			onHoverIn(type);
		}, function() {});
	});

	function onHoverIn(type) {
		if ($.browser.msie) {
			dots[type].css('filter', 'alpha(opacity=100)');
		} else {
			dots[type].css('opacity', 1);
		}

		setTimeout(function() {
			onHoverOut(type);
		}, lightTime);
	}

	function onHoverOut(type) {
		if ($.browser.msie) {
			dots[type].css('filter', 'alpha(opacity=' + (defOpacity * 100) + ')');
		} else {
			dots[type].css('opacity', defOpacity);
		}

		lightCounter++;

		if (lightCounter < maxLightCounter) {
			setTimeout(function() {
				onHoverIn(type);
			}, lightTime);
		}
	}

	function getType(classesPlain) {
		var classes = classesPlain.split(' ');

		for (var i = 0; i < classes.length; i++) {
			if (prefixClass == classes[i].substr(0, prefixClass.length)) {
				return classes[i].substr(prefixClass.length);
			}
		}

		return false;
	}
});
