$(document).ready(function() {
	$("#opentop").click(function(){
		$("div#paneltop").slideDown("slow");
		return false;
	});	
	$("#closetop").click(function(){
		$("div#paneltop").slideUp("slow");	
		return false;
	});
	$("#toggletop a").click(function () {
		$("#toggletop a").toggle();
	});
	$('#mask').css({'height':$('#panel-1').height()});	
	$('#menupanel').width(parseInt($('#mask').width() * $('#menupanel div').length));
	$('#menupanel div').width($('#submenu').width());
	$('#main-menu a').mouseenter(function () {
		$('#submenu').stop();
		clearTimeout(showTimer);
		$('#submenu').slideDown('fast');
		$('#main-menu a').removeClass('active');
		$(this).addClass('active');
		var panelheight = $($(this).attr('rel')).height();
		$('#submenu').animate({'height':panelheight},{queue:false, duration:500});
		$('#submenu').scrollTo($(this).attr('rel'), 400);
		return false;
	});
	$('#submenu').mouseenter(function () {
		clearTimeout(showTimer);
	});
	var showDelay = 200;
	var showTimer = null;
	$('#submenu').mouseleave(function(){
		if (showTimer)
			clearTimeout(showTimer);
		showTimer = setTimeout(function(){
			$('#submenu').slideUp();
			$('#main-menu a').removeClass('active');
		}, showDelay);
	});
	$('#main-menu a').mouseleave(function(){
		if (showTimer)
			clearTimeout(showTimer);
		showTimer = setTimeout(function(){
			$('#submenu').slideUp();
			$('#main-menu a').removeClass('active');
		}, showDelay);
	});
	$("div.property div:first-child").each(function(i) {
		var img_ = $('img', this);
		var img_height = img_.attr('height');
		var p_height = $('p', this).outerHeight();
		$(this).height(img_height);
		$(this).parent().hover(function() {
			img_.stop().animate({marginTop : -p_height}, 500);
		}, function() {
			img_.stop().animate({marginTop : '0'}, 750);
		});
	});
});
