// JavaScript Document

$(document).ready(function() 
{
	$('#hb_box1').bind('mouseenter', toggle_hb_box_in);
	$('#hb_box1').bind('mouseleave', toggle_hb_box_out);
	$('#hb_box2').bind('mouseenter', toggle_hb_box_in);
	$('#hb_box2').bind('mouseleave', toggle_hb_box_out);
	$('#hb_box3').bind('mouseenter', toggle_hb_box_in);
	$('#hb_box3').bind('mouseleave', toggle_hb_box_out);
});

$.fn.pause = function (n) 
{
	return this.queue(function () 
		{
			var el = this;
			setTimeout(function () 
			{
				return $(el).dequeue();
			}, n);
		});
};

var bheight = 28;
var element1h = 237;
var element2h = 185;
var element3h = 140;

function menubox1_open()
{
	$('#menubox1').addClass('opened');
	$('#menubox1c').animate({height: element1h}, "fast");
	$('#menubox1').animate({bottom: element1h + bheight + 2}, 'fast');
}

function menubox1_close(fnct)
{
	$('#menubox1').removeClass('opened');
	$('#menubox1c').animate({height: 0}, 'fast');
	$('#menubox1').animate({bottom: bheight + 2}, 'fast', fnct);
}

function menubox2_open()
{
	$('#menubox2').addClass('opened');
	$('#menubox1').animate({bottom: element2h + bheight + 2}, 'fast');
	$('#menubox2').animate({bottom: element2h + 1}, 'fast', function(){
		$('#menubox2c').animate({width: 727}, "fast");});
}

function menubox2_close(fnct)
{
	$('#menubox2').removeClass('opened');
	$('#menubox2c').animate({width: 0}, 'fast', function() {
		$('#menubox1').animate({bottom: bheight + 2}, 'fast');
		$('#menubox2').animate({bottom: 1}, 'fast', fnct);});
}

function menubox3_open()
{
	$('#menubox3').addClass('opened');
	$('#menubox1').animate({bottom: element3h + bheight + 2}, 'fast');
	$('#menubox2').animate({bottom: element3h + 1}, 'fast');
	$('#menubox3c').animate({height: element3h}, "fast");
}

function menubox3_close(fnct)
{
	$('#menubox3').removeClass('opened');
	$('#menubox3c').animate({height: 0}, 'fast');
	$('#menubox1').animate({bottom: bheight + 2}, 'fast');
	$('#menubox2').animate({bottom: 1}, 'fast', fnct);
}

function toggle_menubox1()
{
	if($('#menubox1c').css('height') != '0px')
	{
		menubox1_close();
	}
	else
	{
		if($('#menubox2c').css('width') != '0px') 
			menubox2_close(menubox1_open);
		else
		if($('#menubox3c').css('height') != '0px') 
			menubox3_close(menubox1_open);
		else
			menubox1_open(null);
	}
}

function toggle_menubox2()
{
	if($('#menubox2c').css('width') != '0px')
	{
		menubox2_close();
	}
	else
	{
		if($('#menubox1c').css('height') != '0px') 
			menubox1_close(menubox2_open);
		else
		if($('#menubox3c').css('height') != '0px') 
			menubox3_close(menubox2_open);
		else
			menubox2_open(null);
	}
}

function toggle_menubox3()
{
	if($('#menubox3c').css('height') != '0px')
	{
		menubox3_close();
	}
	else
	{
		if($('#menubox1c').css('height') != '0px') 
			menubox1_close(menubox3_open);
		else
		if($('#menubox2c').css('width') != '0px') 
			menubox2_close(menubox3_open);
		else
			menubox3_open(null);
	}
}

function toggle_buildergalerie()
{
	if($('#buildergalerie_c').css('height') == '0px')
	{
		$('#buildergalerie').addClass('opened');
		$('#buildergalerie').animate({bottom: 321}, 'fast');
		$('#buildergalerie_c').animate({height: 320}, 'fast');
	}
	else
	{
		$('#buildergalerie').removeClass('opened');
		$('#buildergalerie').animate({bottom: 0}, 'fast');
		$('#buildergalerie_c').animate({height: 0}, 'fast');
	}
}

function toggle_hb_box_in()
{
	$(this)
		.stop()
		.animate({top: -240}, 'fast');
}

function toggle_hb_box_out()
{
	$(this)
		.stop()
		.animate({top: 50}, 'fast');
}