var menuFadeSpeed = 200;
var mouseOverMain = false;
$(function ()
{
	$("#likeButton").mouseover (function ()
	{
		showLike ();
	});
	$(window).resize (function ()
	{
		$("#likeIframe").css("top", $("body").height() - 52);
		$("#likeIframe").css("left", $("body").width() - 102);
	});
	$(window).resize ();
	$("#mainMenuButton").mouseover (openMainMenu);
	$("#projectsMenuButton").mouseover (function ()
	{
		openProjectsMenu ("projectsMenuButton");
	});
	buildMainMenu ();
	buildProjectsMenu ();
	$("#mainMenu").bind ("mouseenter", function ()
	{
		mouseOverMain = true;
	});
	$("#mainMenu").bind ("mouseleave", function ()
	{
		mouseOverMain = false;
	});
	
});
function showLike (hide_in)
{
	if(!hide_in)
	{
		$("#likeIframe").mouseout (function ()
		{
			showLike (true);
		});
		$("#likeIframe").fadeIn (200);
	}
	else
	{
		$("#likeIframe").fadeOut (200);
	}
}
function openMainMenu ()
{
	$("#mainMenu").fadeIn (menuFadeSpeed);
	$("#mainMenu").mouseleave (hideMainMenu);
}
function hideMainMenu ()
{
	$("#mainMenu").fadeOut (menuFadeSpeed);
}
var mouseOnMenuProjectos = false;
var timer;
function openProjectsMenu (opener_in)
{
	$("#" + opener_in).mouseleave (function ()
	{
		$("#" + opener_in).unbind ("mouseleave");
		$("#menuprojectos").mouseenter (function ()
		{
			mouseOnMenuProjectos = true;
		});
		$("#menuprojectos").mouseleave (function ()
		{
			mouseOnMenuProjectos = false;
		});
		timer = setTimeout (function ()
		{
			clearTimeout (timer);
			if(mouseOnMenuProjectos)
			{
				$("#menuprojectos").mouseleave (hideProjectsMenu);
			}
			else
			{
				hideProjectsMenu ();
			}
		}, 1500);
	});
	$("#mainMenu").unbind ("mouseleave", hideMainMenu);
	$("#menuprojectos").fadeIn (menuFadeSpeed);
	$("#areaShader").fadeIn (menuFadeSpeed);
}
function hideProjectsMenu ()
{
	var overProjects = false;
	$("#mainMenu").mouseenter (function ()
	{
		overProjects = true;
	});
	$("#areaShader").fadeOut (menuFadeSpeed);
	$("#menuprojectos").fadeOut (menuFadeSpeed, function ()
	{
		if(overProjects || mouseOverMain)
		{
			$("#mainMenu").mouseleave (hideMainMenu);
		}
		else
		{
			hideMainMenu ();
		}
	});
}
function buildMainMenu ()
{
	$("body").append ('<div id="mainMenu">'+
					'<table border="0" cellspacing="0" cellpadding="0">'+
					'<tr>'+
					'<td width="130" height="45">&nbsp;</td>'+
					'</tr>'+
					'<tr>'+
					'<td width="130" height="20" valign="top"><table width="130" border="0" cellspacing="0" cellpadding="0">'+
					'<tr>'+
					'<td><a href="atelier.html" class="menu">Atelier</a></td>'+
					'<td align="right" class="menu">-</td>'+
					'</tr>'+
					'</table></td>'+
					'</tr>'+
					'<tr>'+
					'<td height="13" valign="top"><img src="images/traco.gif" alt="" width="130" height="2"></td>'+
					'</tr>'+
					'<tr>'+
					'<td height="22" valign="top"><table width="130" border="0" cellspacing="0" cellpadding="0">'+
					'<tr>'+
					'<td><a href="javascript:void (0);" onclick="openProjectsMenu (\'sub_projectos\')" class="menu" id="sub_projectos">Projectos</a></td>'+
					'<td align="right" class="menu">-</td>'+
					'</tr>'+
					'</table></td>'+
					'</tr>'+
					'<tr>'+
					'<td height="13" valign="top"><img src="images/traco.gif" alt="" width="130" height="2"></td>'+
					'</tr>'+
					'<tr>'+
					'<td height="22" valign="top"><table width="130" border="0" cellspacing="0" cellpadding="0">'+
					'<tr>'+
					'<td><a href="noticias.html" class="menu">Noticias</a></td>'+
					'<td align="right" class="menu">-</td>'+
					'</tr>'+
					'</table></td>'+
					'</tr>'+
					'<tr>'+
					'<td height="13" valign="top"><img src="images/traco.gif" alt="" width="130" height="2"></td>'+
					'</tr>'+
					'<tr>'+
					'<td height="22" valign="top"><table width="130" border="0" cellspacing="0" cellpadding="0">'+
					'<tr>'+
					'<td><a href="contactos.html" class="menu">Contactos</a></td>'+
					'<td align="right" class="menu">-</td>'+
					'</tr>'+
					'</table></td>'+
					'</tr>'+
					'<tr>'+
					'<td height="22" valign="top"><img src="images/traco.gif" alt="" width="130" height="2"></td>'+
					'</tr>'+
					'</table>'+
					'</div>');
}
function buildProjectsMenu ()
{
	$("body").append ('<div id="menuprojectos">'+
					'<table border="0" cellspacing="0" cellpadding="0">'+
					'<tr>'+
					'<td width="130" height="0"></td>'+
					'</tr>'+
					'<tr>'+
					'<td width="130" height="20" valign="top"><table width="130" border="0" cellspacing="0" cellpadding="0">'+
					'<tr>'+
					'<td><a href="projectos-habitacao.html" class="menu">Habitação</a></td>'+
					'<td align="right" class="menu">-</td>'+
					'</tr>'+
					'</table></td>'+
					'</tr>'+
					'<tr>'+
					'<td height="13" valign="top"><img src="images/traco.gif" alt="" width="130" height="2"></td>'+
					'</tr>'+
					'<tr>'+
					'<td height="22" valign="top"><table width="130" border="0" cellspacing="0" cellpadding="0">'+
					'<tr>'+
					'<td><a href="projectos-restauracao.html" class="menu">Restauração</a></td>'+
					'<td align="right" class="menu">-</td>'+
					'</tr>'+
					'</table></td>'+
					'</tr>'+
					'<tr>'+
					'<td height="13" valign="top"><img src="images/traco.gif" alt="" width="130" height="2"></td>'+
					'</tr>'+
					'<tr>'+
					'<td height="22" valign="top"><table width="130" border="0" cellspacing="0" cellpadding="0">'+
					'<tr>'+
					'<td><a href="projectos-servicos.html" class="menu">Serviços</a></td>'+
					'<td align="right" class="menu">-</td>'+
					'</tr>'+
					'</table></td>'+
					'</tr>'+
					'<tr>'+
					'<td height="13" valign="top"><img src="images/traco.gif" alt="" width="130" height="2"></td>'+
					'</tr>'+
					'<tr>'+
					'<td height="22" valign="top"><table width="130" border="0" cellspacing="0" cellpadding="0">'+
					'<tr>'+
					'<td><a href="projectos-mobiliario.html" class="menu">Mobiliário</a></td>'+
					'<td align="right" class="menu">-</td>'+
					'</tr>'+
					'</table></td>'+
					'</tr>'+
					'<tr>'+
					'<td height="22" valign="top"><img src="images/traco.gif" alt="" width="130" height="2"></td>'+
					'</tr>'+
					'</table>'+
					'</div>');
}


function scrollToTop ()
{
$("html:not(:animated),body:not(:animated)").animate({ scrollTop: 0}, 1000);
}

