ltm.navigation = {	
	setup: function( oOpt )
	{		
		  $.address.init( function( event )
		  {
				$( '.menu a' ).address();
				
			}).change( function( event )
			{        
				if( ltm.userAgent == "IE6" || ltm.userAgent == "IE7" || ltm.userAgent == "IE8" || ltm.debug == true ) ltm.navigation.updateFallbackView();
					else ltm.navigation.updateView( event );
				
				ltm.navigation.updateNavigationState( event );
				
				ltm.navigation.updateLanguageLink( event );
				
				ltm.navigation.animateContent( "-->" );
			});
			
			if( ltm.userAgent == "IE6" || ltm.userAgent == "IE7" || ltm.userAgent == "IE8" || ltm.debug == true )
			{
				$( "#video_wrapper" ).remove();
				$( "#maps_container" ).remove();
				$( ".kontakt_container_fallback" ).css( { "display": "block", "visibility": "visible" } );
				$( ".kontakt_container_fallback" ).click( function() { ltm.gotoGoogleMaps() });	
				
				$( "#content_UNTERNEHMEN" ).css( { "margin-top": "100px" } );
				$( "#content_BRANTERTAINMENT" ).css( { "margin-top": "100px" } );
				$( "#content_LEISTUNGEN" ).css( { "margin-top": "100px" } );
				$( "#content_WIRKUNGSWEISE" ).css( { "margin-top": "100px" } );
				$( "#content_LEITBILD" ).css( { "margin-top": "100px" } );
				$( "#content_IMPRESSUM" ).css( { "margin-top": "100px" } );
			}
			
			$( "#content" ).remove();
			$( ".impressum_makinmovez_link a" ).css( { "text-decoration": "none" } );
			
			var path = $.address.path().toString();
			if( path.length == 0 ) 
			{
				$( "#content_HOME" ).css( { visibility:"visible", display:"block", opacity: "0.0" } );	
				$( "#content_HOME" ).animate( { "left": "-=0", "opacity": "1.0" }, { queue: false, duration: 750, easing: "backEaseInOut" } );		
			}
	},
	
	updateView: function( e )
	{	
		//alert("updateView() " + e);
	
		var path = $.address.path().toString().split( "/" );
		
		if( path[ 1 ] == "KONTAKT" || path[ 1 ] == "CONTACT" )
		{	
			//alert("1.");
		
			ltm.contact.setup();
			$( "#maps_container" ).css( { visibility:"visible", display:"block", opacity: "0.0" } );	
			$( "#maps_container" ).animate( { "left": "-=0", "opacity": "1.0" }, { queue: false, duration: 750, easing: "backEaseInOut" } );
		}
		//if( path[ 1 ] != "KONTAKT" )
		else
		{
			//alert("2.");
			$( "#maps_container" ).css( { visibility:"hidden", display:"none" } );
		}
		
		ltm.currentpath = path;
		
		ltm.navigation.updateFallbackView();
	},
	
	updateFallbackView: function()
	{
		var path = $.address.path().toString().split( "/" );
			
		$( "section" ).css( { "display": "none", "visibility": "hidden" } );
		
		var selecta;
		if( path[ 1 ] != undefined )
		{
			selecta = "#content_" +  path[ 1 ];
			
			if( ltm.language.toString() == "en" )
			{
				var foo = ltm.navigation.languageHackEN2DE( path[ 1 ] );
				selecta = "#content_" + foo;
				//alert("LANG:" + ltm.language );
			}
		}
		else selecta = "#content_HOME";
		
		$( selecta ).css( { visibility:"visible", display:"block", opacity: "0.0" } );	
		$( selecta ).animate( { "left": "-=0", "opacity": "1.0" }, { queue: false, duration: 750, easing: "backEaseInOut" } );
	},
	
	languageHackDE2EN: function( value )
	{
		var id = "";
		
		switch( value )
		{
			case "UNTERNEHMEN":
				id = "COMPANY";
				break;
			
			case "BRANDTAINMENT":
			case "HOME":
				id = value;
				break;
				
			case "LEISTUNGEN":
				id = "SERVICES";
				break;
				
			case "WIRKUNGSWEISE":
				id = "HOW-WE-WORK";
				break;
			
			case "LEITBILD":
				id = "MISSION-STATEMENT";
				break;
				
			case "REFERENZEN":
				id = "REFERENCES";
				break;
				
			case "KONTAKT":
				id = "CONTACT";
				break;
				
			case "IMPRESSUM":
				id = "IMPRINT";
				break;
		}
		
		return id;
	},
	
	languageHackEN2DE: function( value )
	{
		var id = "";
		
		switch( value )
		{
			case "COMPANY":
				id = "UNTERNEHMEN";
				break;
			
			case "BRANDTAINMENT":
			case "HOME":
				id = value;
				break;
				
			case "SERVICES":
				id = "LEISTUNGEN";
				break;
				
			case "HOW-WE-WORK":
				id = "WIRKUNGSWEISE";
				break;
			
			case "MISSION-STATEMENT":
				id = "LEITBILD";
				break;
				
			case "REFERENCES":
				id = "REFERENZEN";
				break;
				
			case "CONTACT":
				id = "KONTAKT";
				break;
				
			case "IMPRINT":
				id = "IMPRESSUM";
				break;
		}
		
		return id;
	},
	
	animateContent: function( direction )
	{
		$( "#content_container_inner" ).animate( { "left": "-=0", "opacity": "1.0" }, { queue: false, duration: 750, easing: "backEaseInOut" } );
	},
	
	updateLanguageLink: function( e )
	{
		var path = $.address.path().toString().split( "/" );
		
		var url = "http://www.leotainment.com/";
		if( ltm.language.toString() == "de" ) url += "index_en.php";
		
		if( path.length != 0 )
		{
			if( path[ 1 ] != undefined )
			{
				if( ltm.language.toString() == "de" )
				{
					var foo = ltm.navigation.languageHackDE2EN( path[ 1 ] );
					url += "#/" + foo + "/";
				}
				if( ltm.language.toString() == "en" )
				{
					var bar = ltm.navigation.languageHackEN2DE( path[ 1 ] );
					url += "#/" + bar + "/";
				}
			}
			//url += "#/" + path[ 1 ] + "/";
		}
		
		$( "#language_toggle" ).attr( 'href', url );
	},
	
	updateNavigationState: function( e )
	{
		var path = e.value.toString().split( "/" );
		
		$( '.menu a' ).each( function()
		{
			$( this ).removeClass( 'current_page_item' );
		});
		
		$( '.submenue a' ).each( function()
		{
			$( this ).removeClass( 'current_page_item' );
		});
		
		$( '.menu a' ).each( function()
		{
			if( $( this ).attr( 'href' ) == "#/" + path[ 1 ] + "/" )
			{
				$( this ).addClass( 'current_page_item' ).focus();
			}
		});
		
		$( '.submenue a' ).each( function()
		{
			if( $( this ).attr( 'href' ) == "#/" + path[ 1 ] + "/" )
			{
				$( this ).addClass( 'current_page_item' ).focus();
			}
		});
	},
	
	onLoad: function ( e )
	{
	},

	initialize: function()
	{
		ltm.navigation.setup(
			{
				sSelector: "#bgvideoloop"
			}
		);	
	}
}

jQuery( window ).bind( "load", ltm.navigation.onLoad );
jQuery( ltm.navigation.initialize );
