function bindMenu() {
	$('#navigation ul li, #menu_projekte ul li').each(function() {
		var theid = $(this).find('img:first').attr("id");
		if ($(this).attr("class") != "active")
			$(this).hover(function() {
				$('#'+theid).attr("src","images/"+theid+"_mo.gif");
			}, function () {
				$('#'+theid).attr("src","images/"+theid+".gif");
			});
	});
}

$(document).ready(function () {
	var nextRef;
	var oldRef = 'ref_1';
	$(".lavaLamp").lavaLamp({ fx: "backout", speed: 700, click: function(event, menuItem) {
		
		nextRef = menuItem.getAttribute("id");
		if (nextRef != "" && nextRef != null) {
			if ($('p#introtext').css("display") == "block")
				$('p#introtext').fadeOut('slow', showNextReferenz);
			else
				$('#block_'+oldRef).fadeOut('slow', showNextReferenz);
			
			oldRef = nextRef;
		}
	}});
	
	$('#ref_1').trigger('click');
	
	if (hidefirst == 'true')
		$('li.back').hide();
	
	function showNextReferenz() {
		$('#block_'+nextRef).fadeIn('slow');
	}
	
	$('#menu_portfolio').click(function () {
		$('#content').css("background-color","#fff");
			
		var theid = $('#navigation ul li.active').find('img:first').attr("id");		
		if (theid != 'menu_portfolio') {
			$('#navigation ul li.active').removeClass('active');
			$('#menu_portfolio').parent().parent().addClass('active').unbind();
			$('#menu_portfolio').attr("src","images/menu_portfolio_mo.gif");
			$('#'+theid).attr("src","images/"+theid+".gif");
		} else {
			var theid_proj = $('#menu_projekte ul li.active').find('img:first').attr("id");
			$('#'+theid_proj).attr("src","images/"+theid_proj+".gif");
			$('#menu_projekte ul li.active').removeClass('active');
		}
				
		if (subshown != undefined && subshown != 'true') {
			$('#menu_projekte ul li').hide().css("position","absolute").css("left","0").css("top","106px");
			$('#menu_projekte ul li').css("top","156px"); // nun rutschen sie von weiter unten rein
			$('#menu_projekte ul').css("top","-150px").show();
			var startpos=0;
			$('#menu_projekte ul li').each(function () {
				$(this).animate({
					top: startpos, opacity: 'show'
				}, 1500);
				startpos += 26;
			});
		}

		var animCompl = false;
		$('#content div, #content img').animate({
			opacity: 0
		}, 750, function () {
			if (!animCompl) {
				$.get("portfolio.inc",
					function(data){
						$('#content').html(data);
						$('#block_ref_port').animate({
							opacity: 'show'
						}, 750);
					}
				);
				document.title = 'eigenart grafik und idee | portfolio';
				animCompl = true;
			}
		});
		
		bindMenu();

		$('#blaettern').hide();
	});
	
	bindMenu();
	
	$('#logo img').hover(function () {
		$(this).attr("src","images/logo_on.gif");
	}, function () {
		$(this).attr("src","images/logo_off.gif");
	});
});
