$(document).ready(function() {
	/*
		Если длина окна меньше 1000пх то фиксируем фон
	*/
	var changeBackgroundPositingOnResize = function(){
		if($(window).width() < 1000) {
			$("body").css('background-position', '-200px top');
		} else {					
			$("body").css('background-position', 'center top');
		}
	}
	// Проверяем при загрузке странцы
	changeBackgroundPositingOnResize()
	// Вешаем обработку на событие
	$(window).bind('resize', changeBackgroundPositingOnResize);		
	
	/*
		Скрыть фишки
	*/
	$("#more").click(function(){
		if($(".chip").is(":visible")){
			$(".moreinfo").fadeOut(100);
			$("#more-text").html("В подробностях...");
			$(".chip").hide();
		} else {
			$("#more-text").html("Без подробностей...");
			$(".chip").show();
		}
	})
	
	/*
		Добавлять класс "focused", если мышка на блоке с информацией
	*/
	$(".moreinfo").bind("mouseover", function(){
		$(this).addClass("focused");
	}).bind("mouseout", function(){
		$(this).removeClass("focused");
		var me = this;
		hideDelayTimer = setTimeout(function () {	
			if(!$(me).hasClass('focused')) {
				$(me).fadeOut(500);
			}
		}, 1500);
	})
	
	/*
		Показывать блок с информацией если мышка на фишке
	*/
	$(".chip").mouseover(function(){
		$(".moreinfo").fadeOut(100);
		$(this).addClass("focused");
		var id = $(this).attr('id').split('-')[1];
		$("#belongs-" + id).show();
	}).mouseout(function(){
		var id = $(this).attr('id').split('-')[1];
		var me = $("#belongs-" + id);
		
		hideDelayTimer = setTimeout(function () {	
			if(!$(me).hasClass('focused')) {
				$(me).fadeOut(500);
			}			
		}, 1500);
	});

});

