active = "";
$(document).ready(function(){
	$(".ind_link, .comm-link").mousemove(function(e){
	      mouseX = e.pageX;
	      mouseY = e.pageY;
	});

	$(".ind_link").hoverIntent(function(){
		if ($(this).attr("id") != active)
			$(".circle").fadeOut();

        var left = mouseX + 8 - $(this).offset().left + $(this).position().left;
        var top = mouseY - 8 - $(this).offset().top + $(this).position().top - $(this).next(".circle").height();

		$(this).next(".circle").css("left", left)
								.css("top", top)
								.css("z-index", "1000")
								.fadeIn();

		active = $(this).attr("id");
	}, function(){
		setTimeout(function(){
				flag = false;
				if ( /* $.browser.msie && $.browser.version == "7.0" && */ $(".circle.hover").length == 1) {
					$(".circle").fadeOut();
				}
//				if ( ($(".circle:hover") == undefined && !$(".circle.hover").length) || ( /*!$(".ind_link:hover").length && */ !$(".circle:hover").length && !$(".circle *:hover").length) ) {
//					$(".circle").fadeOut();
//				}
			}, 500);
	});

	$(".circle").hover(function(){
		$(this).toggleClass("hover");
	}, function(){
		$(this).toggleClass("hover");
		if ( !$(".ind_link.hover").length )
			$(".circle").fadeOut();
	});

	$(".comm ul").hover(function(){$(this).addClass("hover");},   function(){$(this).removeClass("hover");});
	$(".ind_link").hover(function(){$(this).addClass("hover");},   function(){$(this).removeClass("hover");});


	/* ÌÛÑËÈ */
	active_comment = -1;
	$(".comm-link").hoverIntent(function(){

		if ( $(".comm-link").index($(this)) != active_comment)
			$(".comm ul").fadeOut();



		active_comment = $(".comm-link").index($(this));

        var left = mouseX + 8 - $(this).offset().left + $(this).position().left - $(this).next("ul").width()/2;
        var top = mouseY - 14 - $(this).offset().top + $(this).position().top - $(this).next("ul").height();

		var sumWidth = $(this).offset().left + $(this).next("ul").width()+30+left;

		if ( sumWidth > $(window).width() )
			left -= $(this).next("ul").width() - ($(window).width() - mouseX) + 70 - $(this).next("ul").width()/2;

		$(this).next("ul").css("left", left)
						.css("top", top)
						.css("z-index", "1100")
						.fadeIn();
	}, function(){
		setTimeout(function(){
				flag = false;
//				if ( ($(".comm-link:hover") == undefined && !$(".comm.hover").length ) 
//						|| (!$(".comm-link:hover").length && !$(".comm ul:hover").length && !$(".comm ul *:hover").length) )

				if ( !$(".comm .hover").length )
					$(".comm ul").fadeOut();
			}, 500);
	});


	$(".comm ul").hover(function(){
	}, function(){
//		if ( $(".comm-link:hover") == undefined || !$(".comm-link:hover").length )
		$(this).fadeOut();
	});









	$(window).resize( moveComments );
	moveComments();

	function moveComments(){
		var width = $("#man").width();
		$("#man .comm").css("left", width/2 - 250);

		var width = $("#woman").width();
		$("#woman .comm").css("right", width*0.55 - 265);
	}




	Cufon.set('fontSize','16px');
	Cufon.replace('.var')
	
	Cufon.set('fontSize','14px');
	Cufon.set('lineHeight','27px');
	Cufon.replace('.din2');
	
	Cufon.set('fontSize','27px');
	Cufon.set('lineHeight','27px');
//	Cufon.replace('.din');

/*

	$(".ind_link").each(function(){
		var circle_width = $(this).next("div.circle").css("width");
		$(this).next("div.circle").find(".cbg-r").css("margin-left", circle_width);

		var left = parseInt($(this).css("left"));
		var top = parseInt($(this).css("top"));

		var c_height = $(this).next("div").height();

		$(this).next("div").css("top", top + c_height/4 );
		$(this).next("div").css("left", left+30);
	});

*/

});
