function initStartseite()
{
	$('.nojs').removeClass("nojs");

	$('#kollektionen li a').bind("mouseenter", function()
	{		
		$('.logo', this).fadeIn('fast');
		$('.img', this).animate({
			opacity: 0.2
		});
		
	}).bind("mouseleave", function()
	{	
		$('.logo', this).fadeOut('fast');
		$('.img', this).animate({
			opacity: 1
		});
	});
}

function initSubseite()
{
	$('.nojs').removeClass("nojs");

	$('#kollektionen li a').bind("mouseenter", function()
	{
		if( !$(this).hasClass('active') )
		{			
			$(this).animate({
				opacity: 1
			});
		}
		
	}).bind("mouseleave", function()
	{	
		if( !$(this).hasClass('active') )
		{
			$(this).animate({
				opacity: 0.2
			});
		}
	});
	
	
	if( kollektion )
	{
		hideVisuals( visual );
	}
	
	$('.scroll').jScrollPane();
	
	
	// Contentgröße anpassen
	function resize()
	{
		wW = $(window).width();
		wH = $(window).height();
		
		if( wW > 1198 )
		{
			nW	= 1198;
		}
		else if( wW < 990 )
		{
			nW = 980;
		}
		else
		{
			nW = wW-20;
		}
		
		if( wH > 820 )
		{
			nH	= 645;
		}
		else if( wH < 600 )
		{
			nH = 420;
		}
		else
		{
			nH = wH-195;
		}
		
		$('#site').width(nW);
		$('#content').width(nW);
		$('#site').height(nH);
		$('#content').height(nH);
		
		// meta Content muss 25 Pixel höher sein
		//$('.meta #content').height(nH+25);
	}
	
	var	wW, wH, nW, nH;
	resize();
	$(window).bind("resize", resize);
}

function switchVisual( kol, d )
{
	visualNext = visual+1;
	visualPrev = visual-1;
	
	if( visual == 3 )
	{
		visualNext = 1;
	}
	else if( visual == 1 )
	{
		visualPrev = 3;
	}
	
	if( d == "+" )
	{
		visual = visualNext;
	}
	else if( d == "-" )
	{
		visual = visualPrev;
	}
	
	//visual = 2;
	
	$('#visual_'+visual).css( "cssText", "z-index: "+(zIndex++)+" !important" );		
	$('#visual_'+visual).fadeTo( 0, 0 );
	$('#visual_'+visual).fadeTo( 'slow', 1 );
	
	return false;
}

function hideVisuals( nr )
{
	for( i=1; i<=3; i++ )
	{
		if( i != nr )
		{
			$('#visual_'+i).fadeTo( 0, 0 );
		}
	}
}

function loadContent( n )
{
	nArr = n.split("/");
	
	if( $('#copy').length > 0 )
	{
		closeContent( true, n );
	}
	else
	{
		$.get( '/ajax.php?n='+n, function(data)
		{			
			$('#content').append(data);
			$('#copy').fadeTo( 0, 0 );
			$('#copy').fadeTo( 'slow', 1 );
			$('#navigation_sub .'+nArr[1]+' a').addClass("active");
			$('.scroll').jScrollPane();
		}); 
	}
	
	return false;
}

function closeContent( LC, n  )
{
	$('#navigation_sub .designer a').removeClass("active");
	$('#navigation_sub .idee a').removeClass("active");
			
	$('#copy').fadeTo( 'slow', 0, function()
	{
		if ( LC === undefined )
		{
			$('#copy').remove();
		}
		else
		{
			$('#copy').remove();
			loadContent( n )
		}
	});
	
	return false;
}

if( kollektion )
{
	$.address.change(function(event)
	{
		if( event.value != "/" )
		{
			nArr = event.value.split("/");
			loadContent( nArr[1]+"/"+nArr[2] );
		}
		else
		{
			closeContent();
		}
	}); 
}


$(document).ready(function() {
	if( $("body").hasClass('startseite') )
	{
		initStartseite();
	}
	else if( $("body").hasClass('subseite') )
	{
		initSubseite();
	}
});


