var	lettersServices = document.getElementById ("letters-services"),
	lettersTeam = document.getElementById ("letters-team"),
	textMain = document.getElementById ("text-main");

function lench (x1, y1, x2, y2)
{
	var q = Math.sqrt ((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
	return q;
}

function mouseInFig (cursorX, cursorY)
{
	if (lench (cursorX, cursorY, 352.607, 286.967) < 285.843)
		return true;
	if (lench (cursorX, cursorY, 284.946, 371.538) < 285.842)
		return true;
	if ((lench (cursorX, cursorY, 281.468, 300.594) < 355.865)
		&& (lench (cursorX, cursorY, 364.48, 364.767) < 362.816)
		&& (lench (cursorX, cursorY, 87.269, 598.849) > 165.914)
		&& (lench (cursorX, cursorY, 520.882, 37.304) > 165.914)
			)
		return true;

	return false;
}

function choseRoom (x, y)
{
	if (y < 193) //4 floor
		return 1;
	else if (y < 193 + 16/kY)
	{
		if (x < 243)
			return 1;
	}
	else if (y < 376) //3 floor
	{
		if (x < 316)
			return 1;
		else if (x > 316 + 16/kY)
			return 2;
	}
	else if ((y > 376 + 16/kY) && (y < 560)) //2 floor
	{
		if (x < 134)
			return 3;
		else if (x > 134 + 16/kY)
			return 4;
	}
	else if (y > 560 + 16/kY) //1 floor
		return 5;
   
	return 0;
}

function mousePageXY(e)
{
	var x = 0, y = 0;
	var nameRoom = "space";

	if (!e) e = window.event;

	if (e.pageX || e.pageY)
	{
		x = e.pageX;
		y = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
		y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
	}

	x = (x - startX)/kY;
	y = (y - startY)/kY;

	if (mouseInFig(x,y))
	{
		switch (choseRoom(x,y))
		{
			case 1:
				houseBlue.style.clip = "rect(" + Math.round (277 * kY + 15) + "px, " + Math.round (495 * kY) + "px, " + Math.round (460 * kY) + "px, auto)";
				houseBlueDouble.style.clip = "rect(auto, " + Math.round (423 * kY) + "px, " + Math.round (277 * kY + 15) + "px, auto)";
				houseBlueTripple.style.clip = "rect(auto, auto, " + Math.round (277 * kY) + "px, " + Math.round (423 * kY) + "px)";
				lettersServices.style.visibility = "hidden";
				lettersTeam.style.visibility = "hidden";


				$('#text-main h2').html($('#projects-desc .title').html());
				$('#text-main p').html($('#projects-desc .description').html());
				document.getElementById ("text-lesser").style.visibility = "visible";
				textMain.style.visibility = "visible";

				break;
			case 2:
				houseBlue.style.clip = "rect(" + Math.round (277 * kY + 15) + "px, auto, " + Math.round (460 * kY) + "px, " + Math.round (493 * kY + 17) + "px)";
				houseBlueDouble.style.clip = "rect(0, 0, 0, 0)";
				houseBlueTripple.style.clip = "rect(0, 0, 0, 0)";
				lettersServices.style.visibility = "visible";
				lettersTeam.style.visibility = "hidden";

				$('#text-main h2').html($('#services-desc .title').html());
				$('#text-main p').html($('#services-desc .description').html());
				textMain.style.visibility = "visible";

				break;
			case 3:
				houseBlue.style.clip = "rect(" + Math.round (490 * kY) + "px, " + Math.round (315 * kY) + "px, " + Math.round (644 * kY) + "px, " + "auto)";
				houseBlueDouble.style.clip = "rect(0, 0, 0, 0)";
				houseBlueTripple.style.clip = "rect(0, 0, 0, 0)";
				lettersServices.style.visibility = "hidden";
				lettersTeam.style.visibility = "hidden";
//				textMain.style.visibility = "visible";
				break;
			case 4:
				houseBlue.style.clip = "rect(" + Math.round (460 * kY + 15) + "px, auto, " + Math.round (644 * kY) + "px, " + Math.round (315 * kY + 15) + "px)";
				houseBlueDouble.style.clip = "rect(0, 0, 0, 0)";
				houseBlueTripple.style.clip = "rect(0, 0, 0, 0)";
				lettersServices.style.visibility = "hidden";
				lettersTeam.style.visibility = "visible";

				$('#text-main h2').html($('#team-desc .title').html());
				$('#text-main p').html($('#team-desc .description').html());
				textMain.style.visibility = "visible";
				break;
			case 5:
				houseBlue.style.clip = "rect(" + Math.round (644 * kY + 15) + "px, auto, auto, auto)";
				houseBlueDouble.style.clip = "rect(0, 0, 0, 0)";
				houseBlueTripple.style.clip = "rect(0, 0, 0, 0)";
				lettersServices.style.visibility = "hidden";
				lettersTeam.style.visibility = "hidden";
//				textMain.style.visibility = "visible";
				break;
			default:
				houseBlue.style.clip = "rect(0, 0, 0, 0)";
				houseBlueDouble.style.clip = "rect(0, 0, 0, 0)";
				houseBlueTripple.style.clip = "rect(0, 0, 0, 0)";
				lettersServices.style.visibility = "hidden";
				lettersTeam.style.visibility = "hidden";
				textMain.style.visibility = "hidden";
		}
	}
	else
	{
		houseBlue.style.clip = "rect(0, 0, 0, 0)";
		houseBlueDouble.style.clip = "rect(0, 0, 0, 0)";
		houseBlueTripple.style.clip = "rect(0, 0, 0, 0)";
		lettersServices.style.visibility = "hidden";
		lettersTeam.style.visibility = "hidden";
		textMain.style.visibility = "hidden";
	}
}
document.onmousemove = mousePageXY;




