//Klassen Vordefinieren
var Const =
		{
			Target :
			{
					Container : 1,
					flashContainer : 2
			},
		
			Timer : 
			{
					flashContainerShow : 0.2,
					flashContainerHide : 0.2,
					ContainerResize : 0.5,
					ContainerUpdate : 0.5,
					SubnaviShow : 0.5,
					SubnaviHide : 0.5,
					switchBackground : 4
			},
			
			Conf :
			{
				Menu :
				{
					Up : 60,
					Down : 47
				}
			}
};

_Container = function ( )
{
	log ( "EC _Container");
	this._element = $('container');
	this._scope = this._element.identify();
	
	this.resize = function ( width , height )
	{
		log ( "EF resizeContainer");
		var style1 = 'height:' + height + 'px; width: ' + width + 'px;';
		var style2 = 'height:'+ (height-150) + 'px; backGroundColor: #f00'; 
		
		var options = {
				fps : 100,
				duration:  Const.Timer.ContainerResize,
				transition: Effect.Transitions.sinoidal,
				queue : {
					scope : this._scope
				}
		};
		
		new Effect.Parallel([
		                     new Effect.Morph( this._element , {sync: true , style: style1} ),
		                     new Effect.Morph( 'contentWrapper', {sync: true, style: style2} )
		                     ],options
							);
		log ( "End resizeContainer");
	};
	
	this.update = function ( content ,  hash , data )
	{
		log ( "EF Container.update");

		if ( Hashlist.getHash( 'content' ) == hash  )
		{
			log ("Container.update HASCHECK" );	
			return false;
		}

		var scope = 'textContent';
		var options =
			{
				delay: Const.Timer.ContainerResize,
				fps: 100,
				from: 1,
				to: 0,
				duration : Const.Timer.ContainerUpdate,
				queue :
				{
					position:'end',
					scope: this._scope
				},
				afterFinish :
					function ()
					{
						$('textContent').update( content );
						$('contentWrapper').scrollTop = 0;
						rerouteLinks();
						Hashlist.setHash( 'content', hash );
						Container.resize( 690 , data.box_height );
					}				
			};
		
		new Effect.Opacity('textContent', options );
		
		options.to = 1;
		options.from = 0;
		options.delay  = Const.Timer.ContainerResize;

		new Effect.Opacity('textContent', options );

		if ( $('bnt_minmize').getStyle('display') == 'none')
		{
			$('bnt_minmize').show();
		}
		log ( "End Container.update");
	};
};

_Flashcontainer = function ()
{
	log ( 'EC Flashcontainer');
	
	this._element = $('flashContainer');
	this._scope = this._element.identify();
	
	this.update = function ( data )
	{
		log ( "EF Flashcontainer.updateContent");
		
		if ( Hashlist.getHash( 'content' ) == data.hash.content  )
		{
			log ("Flashcontainer.update HASCHECK" );	
			return false;
		}

		var options =
			{
				fps: 100,
				from: 1,
				to: 0,
				duration : Const.Timer.ContainerUpdate,
				delay: Const.Timer.ContainerResize,
				queue :
				{
					position:'end',
					scope: this._scope
				},
				afterFinish :
					function ()
					{
						$('flashContainer_content').scrollTop = 0;
						$('flashContainer_content').update( data.content );
						rerouteLinks();
						Hashlist.setHash( 'content', data.hash.content );
					}				
			};
		log ('flashContainer_content');

		
		log ( !$('flashContainer_content').empty() );
		if ( !$('flashContainer_content').empty() )
			new Effect.Opacity('flashContainer_content', options );
		
		options.to = 1;
		options.from = 0;
		options.delay  = Const.Timer.ContainerResize;
		
		new Effect.Opacity('flashContainer_content', options );		
		
		rerouteLinks();
	};
	
	this.show = function()
	{
		$('breadcrumb_container').addClassName('noprint');		
		log ( "EF Flashcontainer.show");
		if ( parseInt( this._element.getStyle('height') ) != 0 )
		{
			return true;
		}
		
		/**
		 * alles anhalten
		 */
		
		var queue = Effect.Queues.get(this._scope);
		queue.each(function(effect) {
			effect.cancel();
			});
		
		var duration = Const.Timer.flashContainerShow;
		var target_height = 390;
		
		this._element.setStyle({bottom: "263px" });
		
		new Effect.Parallel([
		                     new Effect.Morph(
		                    		 this._element,
		                    		 {
		                    			 sync: true,
		                    			 style: "height:" + target_height +"px"
		                    		 }
		                     ),
		             		new Effect.Morph(
		             				this._element,
		             				{
		            					sync: true,
		            					style: 'bottom:' + (263 - target_height/2 ) + 'px'
		            				}
		            		)],
		            		{
								fps: 100,
								duration: duration,
								delay: Const.Timer.ContainerResize + 0.5,
								queue :
								{
									scope: this._scope
								},
								afterFinish : function ()
								{
									new Effect.Appear(
											'flashContent',
											{
												duration: Const.Timer.flashContainerShow,
												fps: 100,
												queue :
													{
														scope: FlashContainer._element.identify(),
														position : 'end'
													}
											}
									);
								}
						   });
	};
	
	this.hide = function()
	{
		$('breadcrumb_container').removeClassName('noprint');
		
		log ( "EF FlashContainer.hide");
		original_height = parseInt(this._element.getStyle('height'));
		if ( original_height == 0 )
		{
			return true;
		}
		
		new Effect.Fade(
				'flashContent',
				{
					duration: Const.Timer.flashContainerHide,
					fps: 100,
					queue : {
						position : 'end',
						scope: this._scope
					}
				}
		);
		
		new Effect.Parallel ([
		          		new Effect.Morph(
		        				this._element,
		        				{
		        					sync: true,
		        					style: "height: 0px;"
		        				}
		        		),
		        		
		        		new Effect.Morph(
		        				this._element,
		        				{
		        					sync: true,
	            					style: 'bottom:' + (68 + original_height/2 ) + 'px'
		        				}
		        		)],
				{
					delay: Const.Timer.flashContainerHide,
					fps: 100,
					duration: Const.Timer.flashContainerHide,
					queue : {
						position: 'end',
						scope: this._scope
					}
				}
		);
		
		log ( "End Flashcontainer.hide" );
	};
};

_SN = function ()
{
	this._element = $('subnav');
	this._scope = this._element.identify();
	
	this.update = function ( data )
	{
		log ( "EF _Subnavi.update" );

		//Hashcheck
		if ( Hashlist.getHash( 'subnavi' ) == data.hash.subnavi )
		{
			log ("End _Subnavi.update HASCHECK" );
			try {
				this._highlight( data.level_3.seiten_name );
			} catch (e){};
			
			return false;
		}
		
		//Alles unterbrechen
		var queue = Effect.Queues.get(this._scope);
		queue.each(
				function(effect)
				{
					effect.cancel();
				}
		);
		
		if ( data.subnavi.size() )
		{
			this._show( data );
			try {
				this._highlight( data.level_3.seiten_name );
			} catch (e){};			
		}
		else
		{
			this._hide();
		}
		
		
		Hashlist.setHash ( 'subnavi' , data.hash.subnavi );
		log ( "End _Subnavi.update" );
	};
	
	this._highlight = function ( name )
	{
		log ( "EF _Subnavi._highlight" );
		
		$$('#subnav li a').each (
				function (part)
				{
					$(part).removeClassName('highlight');
					
					if ( part.firstChild.textContent == name )
					{
						$(part).addClassName('highlight');
					}
				}
		);
		log ( "End _Subnavi._highlight" );
	};
	
	this._show = function ( data )
	{
		log ( "EF _Subnavi._show" );
		
		// Alle Subnavi punkte löschen
		this._element.childElements().invoke('remove');
		$( data.subnavi ).each( function (part)
				{
					var attribs = {href: part.seiten_url}; 
					var li =  Builder.node ( 'li', [Builder.node( 'a' , attribs , part.seiten_name )] );
					$('subnav').insert({ bottom: li });
				}
		);
	
		Subnavi._resizeMenu( Const.Conf.Menu.Up );
		new Effect.Appear(
				this._element,
				{
					duration: Const.Timer.SubnaviHide,
					queue:
					{
						scope: this._scope,
						position: 'end'
					}
				});
		
		
		log ( "End _Subnavi._show" );
	};
	
	this._hide = function ()
	{
		log ( "EF _Subnavi._hide" );
		new Effect.Fade(
				this._element,
				{
					duration: Const.Timer.SubnaviHide,
					queue:
					{
						scope: this._scope,
						position: 'end'
					},
					afterFinish: function ()
					{
						Subnavi._resizeMenu( Const.Conf.Menu.Down );
					}
				});
		
		log ( "End _Subnavi._hide" );
	};

	this._resizeMenu = function ( height )
	{ 
		log ( 'EF Subnavi._resizeMenu');
		
		var verwandte_bottom = height - Const.Conf.Menu.Up;
		
		new Effect.Parallel ([
		                      new Effect.Morph ( 'navigation' ,
		                    		  {
				                    	  sync : true,
				                    	  style : 'height:' +  height + "px"
		                    		  }
		                      ),
		                      
		                      new Effect.Morph ( 'container_verwandte' ,
		                    		  {
		                    	  		sync : true,
		                    	  		style : 'bottom: ' + verwandte_bottom + 'px'
		                    		  }
		                      )],
				{
					fps: 100,
					duration: Const.Timer.SubnaviHide,
					queue : {
						scope: this._scope
					}
					
				}
		);
		log ( 'END Subnavi._resizeMenu');
	};
	
};

_Subnavi = function ( )
{
	this._scope = 'navi';
	this._destroy = function () 
	{
		$('subnav').remove();
		return true;
	};
	
	this._fadeout = function ()
	{
		log ( 'EF Subnavi._fadeout');

		if ( $('subnav') )
		{
			var options = {
					fps: 100,
					duration: 0.5,
					afterFinish : function () { $('subnav').remove(); },
					queue : {
						position: 'end', 
						scope: this._scope
					}
			};
			
			new Effect.Fade('subnav', options );
		}
		log ( 'End Subnavi._fadeout');
	};
	
	this._fadein = function ( navi , highlight )
	{
		log ( "EF Subnavi._fadein"); 
		//navi erscheinen lassen
		
		if ( $('subnav') )
		{
			$('subnav').remove();
		}
		
		var ul =  Builder.node ( 'ul', {id : 'subnav'} );
		
		$(ul).setOpacity(0);
		
		$('navigation').insert({ top: ul });
		
		$(navi).each( function (part)
				{
					var attribs = {href: part.seiten_url}; 
					if ( part.seiten_id == highlight )
					{
						attribs.className = 'highlight';
					}	
					
					var li =  Builder.node ( 'li', [Builder.node( 'a' , attribs , part.seiten_name )] );
					$('subnav').insert({ bottom: li });
				}
		);
	
		var options =
		{
			fps: 100,
			duration : 0.5,
			queue: {
				position: 'end',
				scope: this._scope
			}
		};

		new Effect.Appear ( 'subnav' , options );
		
		log ( "Subnavi._fadein");
	};
	
	this._resizeMenu = function ( height )
	{ 
		log ( 'EF Subnavi._resizeMenu');
		
		var options = {
				fps: 100,
				duration: 0.5,
				scope: this._scope,
				style :	'height:' +  height + "px",
				queue : 'end'
		};
		
		new Effect.Morph ( 'navigation' , options );
	};
	
	this.update = function ( navi , highlight )
	{
		log ( "EF Subnavi.update");
		navi = $(navi);
		if ( navi.size() != 0 )
		{
			log ( 'A');
			if ( $('subnav') )
			{
				log (11);
				this._fadeout();
				this._fadein( navi , highlight );
			}
			else
			{
				log (12);

				this._resizeMenu( 60 );
				this._fadeout();
				this._fadein( navi , highlight );
			}
		}
		else
		{
			log ( 'B' );			
			if ( $('subnav') )
			{
				log (21);

				this._fadeout();
				this._resizeMenu( 47 );				
			}
			else
			{
				log (22);
				
			}
		}
		log ( "End Subnavi.update");
	};
};

function Verwandte( element )
{
	log ( "EC Verwandte");
	this._element = $(element);
	this._scope = element.id;
	this._duration = Const.Timer.ContainerResize + Const.Timer.ContainerUpdate;	
	
	this._fadein = function ( delay )
	{
		new Effect.Appear(
				this._element.identify(),
				{
					delay : delay,
					duration: this._duration,
					queue :
					{
						scope : this._scope,
						position: 'end'
					}
				}
			);
	};
	
	this._fadeout = function ( delay )
	{
		new Effect.Fade(
				this._element.identify(),
				{
					delay : delay,
					duration: this._duration,
					queue :
					{
						scope : this._scope,
						position: 'end'
					}
				}
		);		
	};
	
	this._create = function ( data )
	{
		this._element.descendants().invoke('remove');

		$(data).each(
				function (part, counter )
				{
					if ( counter == 0 )
					{
						var extra = "";
					}
					else
					{
						var extra = ' | ';
					}
					var link = Builder.node ( 'a' , {href: part.seiten_url } , extra + part.seiten_name );
					this._element.insert({bottom: link });
				},
				this
		);
	};
	
	this.update = function ( data , hash )
	{
		log ( "EF Verwandte.update" );
		if ( Hashlist.getHash( 'verwandte' ) == hash )
		{
			log ( 'End Verwandte.update HASHCHECK');
			return false;
		}
		
		Hashlist.setHash( 'verwandte', hash );
		
		if ( data.size() != 0 )
		{
			this._create( data );
			this._fadein( 0 );
		}
		
		if ( data.size() == 0 )
		{
			this._fadeout( 0 );
		}
		
		rerouteLinks();
		log ( 'End Verwandte.update');
	};
};

function Breadcrumb( element )
{
	log ( "EC Breadcrumb");
	this._element = $(element);
	this._scope = element.id;
	this._duration = Const.Timer.ContainerResize + Const.Timer.ContainerUpdate;
	
	log ( "Breadcrumb_objekt : " + this._element.identify());
	
	this._fadein = function ( delay )
	{
		new Effect.Appear(
				this._element.identify(),
				{
					delay : delay,
					duration: this._duration,
					queue :
					{
						scope : this._scope,
						position: 'end'
					}
				}
			);
	};
	
	this._fadeout = function ( delay )
	{
		new Effect.Fade(
				this._element.identify(),
				{
					delay : delay,
					duration: this._duration,
					queue :
					{
						scope : this._scope,
						position: 'end'
					}
				}
		);		
	};
	
	this._create = function ( data, delay )
	{
		log ( "EF Breadcrumb._create");
		this._element.descendants().invoke('remove');
		
		var home_url = "home.html";
		if ( data.lang == 'en')
		{
			var home_url = "en/home.html";
		}
		

		if ( this._element.identify() == "breadcrumb_flashcontainer" )
		{
			this._element.update ( new Builder.node( 'a' , { href: home_url} , "[...] | " ));
			this._element.insert({bottom: $(data).last().seiten_name });
		}
		else
		{
			var link = Builder.node ( 'a' , {href:home_url } , "ZELFMADE.DE" );
			this._element.insert({bottom: link });
			
			$(data).each(
					function (part, test)
					{
						var link = Builder.node ( 'a' , {href: part.seiten_url } , " | " + part.seiten_name );
						this._element.insert({bottom: link });
					},
					this
			);
		}
	};
	
	this.update = function ( data , hash )
	{
		log ( "EF Breadcrumb.update" );
		
		if ( Hashlist.getHash( 'breadcrumb' ) == hash )
		{
			log ( 'End Breadcrumb.update HASHCHECK');
			return false;
		}
		
		var options =
			{
				delay: Const.Timer.ContainerResize,
				fps: 100,
				from: 1,
				to: 0,
				duration : Const.Timer.ContainerUpdate,
				queue :
				{
					position:'end',
					scope: this._scope
				},
				afterFinish :
						function ( effect )
						{
							log ( "EF Breadcrumb._create");

							effect.element.descendants().invoke('remove');
		
							if ( effect.element.identify() == "breadcrumb_flashcontainer" )
							{
								if ( data.breadcrumb.size() )
								{
									var preLink = Builder.node ( 'a' , {href: data.breadcrumb_successor.seiten_url } , "[...] | " );
									effect.element.insert( preLink );
									var link = Builder.node ( 'a' , {href: data.breadcrumb.last().seiten_url } ,  data.breadcrumb.last().seiten_name );
									effect.element.insert({ bottom: link });
								}
								else
								{
									effect.element.update('');
								}
							}
							else
							{
								var home_url = "home.html";

								if ( data[0].seiten_url.search('en\/') != -1)
								{
									var home_url = "en/home.html";
								}
								var link = Builder.node ( 'a' , {href:home_url } , "ZELFMADE.DE" );
						
								effect.element.insert({bottom: link });
								$(data).each(
										function ( part )
										{
											var link = Builder.node ( 'a' , {href: part.seiten_url } , " | " + part.seiten_name );
											effect.element.insert({bottom: link });
										},
										effect.element
								);
							};
						
							rerouteLinks();
							Hashlist.setHash( 'breadcrumb', hash );
						}
			};
		
		new Effect.Opacity( this._element, options );
		
		options.to = 1;
		options.from = 0;
		options.delay  = Const.Timer.ContainerResize;

		new Effect.Opacity( this._element, options );		
		
		rerouteLinks();
		log ( 'End Breadcrumb.update');
	};
};


_Hashlist = function ( )
{
	this.hashlist = $('hash_list').getInputs();
		
	this.getHash = function ( hashname )
	{
		var hash = this.searchHash( hashname );
		log ( "GET Hash: " + hashname  + " => " + $(hash).getValue() );
		return $(hash).getValue();
	};
	
	this.setHash = function ( hashname , value )
	{
		var hash = '';
		log ( "SET Hash: " + hashname  + " <= " + value );
		
		if ( hash = this.searchHash( hashname ) )
		{
			$(hash).value=value;
			return true;
		}
		else
		{
			return false;
		}
	};
	
	this.searchHash = function ( hashname )
	{
		var hash = this.hashlist.select (
				function ( n )
				{
					if ( n.name == hashname )
					{
						return true;
					}
					else
					{
						return false;
					}
				}
		);
		
		if ( hash.size() == 0 )
		{
			return false;
		}
		
		return hash[0];
	};
};

Event.observe (
	window,
	'dom:loaded',
	function ()
	{
		//Init
		Container = new _Container();
		FlashContainer = new _Flashcontainer();
		Hashlist = new _Hashlist();
		Subnavi = new _SN();

		rerouteLinks ( );		
		fitBackground( 'background' );
		
		//Alle Link auf den Responder umleiten
		new Event.observe(
				window,
				'resize',
				function ()
				{
					fitBackground( 'background' );
				}
		);
	}
);
var store_data = "";
function rerouteLinks ()
{
	if ( (navigator.userAgent.indexOf("AppleWebKit") != -1) && (navigator.userAgent.indexOf("Mobile") != -1) )
	{
	       return;
	}
	log ( "EF rerouteLinks" );
	$$('a').each(
			function (part)
			{
				if ( $(part).hasClassName('linkprotection'))
					return;

				if ( Prototype.Browser.WebKit )
				{
					if ( $(part).hasClassName('linkprotection_webkit') )
					{
						return;
					}
				}
				
				$(part).stopObserving('click');
				part.observe(
					'click',
					function(event)
					{
						
						new Ajax.Request(
								this.href,
								{
									method: 'post',
									parameters: {responder: 'repsonder'},
								  	onLoading:	function(){},			
									onSuccess:
										function(transport)
										{
								  			var response = transport.responseText.evalJSON();
								  			store_data = response.data;
								  			updatePage(  response.data );
										}
								}
						);
						event.stop();
					}
				);
			}
	);
	
	
	$$('form').each(
			function (part)
			{
				
				if ( $(part).hasClassName('linkprotection'))
					return;
				
				$(part).stopObserving('submit');
				part.observe(
					'submit',
					function(event)
					{
						log (  Form.serializeElements( $(this).getInputs() , true ) );
						var para  = Form.serializeElements( $(this).getElements() , true );
						para.responder = 'repsonder';
						
						log ( para );
						new Ajax.Request(
								this.action,
								{
									method: 'post',
									parameters: para,
								  	onLoading:	function(){},			
									onSuccess:
										function(transport)
										{
								  			var response = transport.responseText.evalJSON();
								  			store_data = response.data;
								  			updatePage(  response.data );
										}
								}
						);
						event.stop();
					}
				);
			}
	);
	
}


function updatePage( data )
{
	log ( "EF updatePage" );
	
/*
	//etrackerbedienen
	et_pagename = data.canonical;
	var et_img = new Image();
	et_img.src = "https://www.etracker.de/cnt.php?et=udVjuV&amp;v=3.0&amp;java=n&amp;et_easy=0&amp;et_pagename=" + et_pagename + "&amp;et_areas=&amp;et_ilevel=&amp;et_target=,0,,0&amp;et_lpage=0&amp;et_trig=&amp;et_se=0&amp;et_cust=0&amp;et_basket=&amp;et_url=&amp;et_tag=&amp;et_organisation=&amp;et_demographic=";
*/	
/*
	et=udVjuV
	v=3.0
	java=n
	et_easy=0
	et_pagename=" + et_pagename + "
	et_areas=
	et_ilevel=
	et_target=,0,,0
	et_lpage=0
	et_trig=
	et_se=0
	et_cust=0
	et_basket=
	et_url=
	et_tag=
	et_organisation=
	et_demographic=
*/	
/*
<img style='border:0px;' alt='' src='https://www.etracker.de/cnt.php?
	et=udVjuV
	&amp;v=3.0
	&amp;java=n
	&amp;et_easy=0
	&amp;et_pagename=!{$canonical}!
	&amp;et_areas=
	&amp;et_ilevel=
	&amp;et_target=,0,,0
	&amp;et_lpage=0
	&amp;et_trig=
	&amp;et_se=0
	&amp;et_cust=0
	&amp;et_basket=
	&amp;et_url=
	&amp;et_tag=
	&amp;et_organisation=
	&amp;et_demographic=' /
*/
	try
	{
		var XKEYX = 'udVjuV';
		var et_pagename = data.canonical;
		var et_areas = '';
		var et_ilevel = '';
		var et_url = '';
		var et_target = ',0,,0';
		var et_tval = '';
		var et_tonr = '';
		var et_tsale = '';
		var et_cust = '';
		var et_basket = '';
		var et_lpage = 0;
		var et_trig = '';
		var et_tag = '';
		var et_sub ='';
		
		et_eC_Wrapper( XKEYX, et_pagename, et_areas, et_ilevel, et_url, et_target, et_tval, et_tonr, et_tsale, et_cust, et_basket, et_lpage, et_trig, et_tag, et_sub );
	}catch (e)
	{
		log(e);
	}
	
	
	//regiolink anzeigen
	if( $('regiolink') )
	{ 
		if ( data.seite.seiten_startseite == 1 || data.seite.seiten_url == 'home.html')
		{
			log ( "RegioLink anzeigen" );
			if ( $('regiolink').visible() && $('regiolink').empty() )
			{
				$('regiolink').hide();
			}
			$('regiolink').innerHTML = '<span style="font-size: 11px;"><a id="event_link" href="extras/regional/eventagentur-hamburg.html">Eventagentur Hamburg</a></span>';
			
			$('regiolink').appear(
					{
					});
		}
		else
		{
			log ( "RegioLink verbergen" );
			$('regiolink').fade(
					{
						afterFinish: function()
							{
								$('regiolink').innerHTML = '';
							}
					});
		}
	}
	
	//daylight anzeigen
	if ( data.seite.daylightswitch == 1)
	{
		log ( "daylightswitch anzeigen" );
		//update der links
		$('daylight_day').href= data.seite.seiten_url + '?fb=ZELFMADE_PNP5_tags.jpg';  
		$('daylight_moon').href= data.seite.seiten_url + '?fb=ZELFMADE_PNP5_nachts.jpg';  
		
		
		$('daylight').appear();
	}
	else
	{
		log ( "daylightswitch verbergen" );
		$('daylight').fade();
	}
	
	//Titel anpasssen
	document.title = data.title;
	
	//Hintergund anpassen
	if ( data.pfb )
	{
		switchBackground( "media_upload/medien_galerien_inhalte/" +  data.background_image , data.hash.background_image );
	}
	else
	{
		if (  data.background_image )
		{
			switchBackground( "public/images/backgrounds/" +  data.background_image,  data.hash.background_image );
		}
	}
	
	updateNavigation( data.level_2.seiten_id );
	Subnavi.update( data );
	
	//Richtigen Container befüllen
	if ( data.target == Const.Target.flashContainer )
	{
		log( 'FlashInhalt' );
		minimize_container();
		FlashContainer.show();
		FlashContainer.update( data );
		
		Subnavi._resizeMenu(47);
		
		var B = new Breadcrumb( $('breadcrumb_flashcontainer') );
		B.update( data ,  data.hash.breadcrumb ) ; 
		
		var V = new Verwandte( $('flashcontainer_verwandte') );
		V.update( data.verwandte ,  data.hash.verwandte ) ;
	}
	else if (data.target == Const.Target.Container )
	{
		log( 'Container' );
		FlashContainer.hide();
		
		//prüfen ob versucht wird bei einem Projekt das Bild zu aktualisieren  
		if ( data.query.indexOf('pic=') != -1 && data.mini==false && $('container').getHeight() != 0 )
		{
			//prüfen ob es ein Video oder eine Bild inhalt ist
			
			var dom_content = Builder.node( 'div' ); 
			dom_content.innerHTML = data.content;

			if ( data.data.media_typ == 'video' )
			{
				$$('.projekt_part').first().update( $(dom_content).select('.projekt_part').first() );
				$$('.projekt_part').first().removeClassName('image');
				$$('.projekt_part').first().removeClassName('video');
				$$('.projekt_part').first().addClassName('video');
			}
			
			if ( data.data.media_typ == 'image' )
			{
				if ( $$('.projekt_part').first().hasClassName('video') )
				{
					$$('.projekt_part').first().update( $(dom_content).select('.projekt_part').first() );
				}

				//bild updaten..
				var img = new Image();
				img.src = "media_upload/medien_galerien_inhalte/" + data.data.small;
				img.onload = function ()
				{
					var new_img = Builder.node( 'img' );
					
					new_img = $(new_img);
					new_img.src = this.src;
					new_img.id = 'new_slideshowImage';
					new_img.setOpacity(0);
					new_img.setStyle( { position: 'absolute' } );
							
					$$('#slideshowContainer a').first().insert( {top: new_img} );
					
					var options =
					{
						fps : 25,
						duration : 0.5,
						transition : Effect.Transitions.sinoidal,
						delay: 0,
						queue:
							{
								position:'end',
								scope : 'slideshowImage'
							},
						afterFinish:
							function ()
							{
								var dom_content = Builder.node( 'div' ); 
								dom_content.innerHTML = data.content;
								
								new_img.setStyle( { position: 'static' } );
								$('slideshowImage').remove();
								new_img.id = 'slideshowImage';
								
								//links anpassen
								//'als hintergrund' link
								
								var old_query = $('bnt_background').href.toQueryParams();
								$('bnt_background').href = $(dom_content).select('#bnt_background').first().href;
								
								$$('#slideshowContainer a').first().href = $(dom_content).select('#slideshowContainer a').first().href;
								$('slideshowImage').href = $(dom_content).select('#slideshowImage').first().href;							
								$('nextSmall').href = $(dom_content).select('#nextSmall').first().href;							
								$('previousSmall').href = $(dom_content).select('#previousSmall').first().href;
								$('pic_selector').update ( $(dom_content).select('#pic_selector').first().innerHTML );
								
								addBackgroundEffects();						
							}
					};
					
					new Effect.Appear
					(
							new_img,
							options
					);
					
					$$('.projekt_part').first().removeClassName('image');
					$$('.projekt_part').first().removeClassName('video');
					$$('.projekt_part').first().addClassName('image');
					
				};
			};
			
		}
		else
		{
			setTimeout( function ()
					{
						//Container anpassen
						if ( data.mini )
						{
							minimize_container ();
							Hashlist.setHash( 'content', 0);
						}
						else
						{
							Container.update( data.content , data.hash.content , data);
							$('btn_maximize').hide();
							var B = new Breadcrumb( $('breadcrumb_container') );
							B.update( data.breadcrumb ,  data.hash.breadcrumb ); 
							
							var V = new Verwandte( $('container_verwandte') );
							V.update( data.verwandte ,  data.hash.verwandte ); 
						}
					}, Const.Timer.flashContainerHide + 0.5 );
		}
		
		//Schliessen Link anpassen
		var closelink = $('btn_close').select('a').first();
		closelink.href = data.url;

		var minilink = $('bnt_minmize').select('a').first();
		var query = data.query.toQueryParams() ;
		query.mini = 1;
		minilink.href = data.seite.seiten_url + '?' + Object.toQueryString(query) ;
		
		//Vergrößern Link anpassen
		if ( data.mini == false )
		{
			var maxilink = $('btn_maximize').select('a').first();
			var query = data.query.toQueryParams();
			query.mini = 0;
			
			maxilink.href = data.seite.seiten_url + '?' + Object.toQueryString(query);
		}
	}
	
	//SuggestLink anpassen
	$$('.bnt_recommend_site a').each (
			function ( part )
			{
				if (data.lang == 'en')
				{
					$(part).href = 'en/extras/recommend-page.html?suggest_id=' + data.seiten_id +"&"+ data.query;
				}
				else
				{
					$(part).href = 'extras/seite-empfehlen.html?suggest_id=' + data.seiten_id +"&"+ data.query;
				}
			}
	);
	
	rerouteLinks();
}

function minimize_container()
{
	log ( "EF minimize_container");
	Container.resize( 690, 0 );
	$('container_verwandte').fade();
	$('textContent').update('');
	$('btn_maximize').setStyle({'display' : 'inline'});
}

function fitBackground( id )
{
	log ( "EF fitBackground");	
	
	var h = $('main').getHeight() ;
	var w = h *  2;
	
	if ( w < $('main').getWidth() )
	{
		w = $('main').getWidth();

		var style =
			{
				height : w/2+'px',
				width : w + 'px'
			};
	}
	else
	{	
		var style =
			{
				height : h+'px',
				width : h * 2 + 'px'
			};
	}
	
	Element.setStyle (id , style);
	log ( "End fitBackground");	
	
}

function switchBackground ( filename , hash  )
{
	log ( "EF switchBackground");	
	/*
	 * Nur updaten wenn wirklich was neues kommt
	 */
	
	if ( Hashlist.getHash( 'background_image' ) == hash )
	{
		log ( 'SwitchBG Hashexit');
		return false;
	}
	
	var img = new Image();
	$('mm_loading').show();
	img.src = filename;
	img.onload = function ()
				{
					Hashlist.setHash( 'background_image', hash );
					var new_img = Builder.node( 'img', { className: 'background' } );
					
					new_img = $(new_img);
					new_img.src = this.src;
					new_img.id = 'new_background';
					$(new_img).addClassName('noprint');
					
					fitBackground( new_img );
					$('background').insert( { before: new_img } );
					
					var options =
					{
						fps : 100,
						duration : Const.Timer.switchBackground,
						transition : Effect.Transitions.linear,
						delay: Const.Timer.ContainerResize,
						queue:
							{
								position:'end',
								scope : 'Background'
							},
						afterFinish:
							function ()
							{
								$('background').remove();
								new_img.id = 'background';
								$('mm_loading').hide();		
								
							}
					};
					
					new Effect.Fade (
							'background',
							options
					);
				};
}

function updateNavigation ( seiten_id )
{
	log( 'EF updateNavigation');
	$$('ul#mainnav li a').each (
			function ( part )
			{
				$(part).removeClassName('highlight');
			}
	);
	try {$('mainnavipoint_'+seiten_id).addClassName('highlight');} catch (e) {}
	log( 'End updateNavigation');	
}

function log ( msg )
{
	return true;
	try {
		console.log ( msg );
	}
	catch (e)
	{
		
	}
}


var player;
function playerReadyCallback(obj) {
	player = $(obj['id']);
	addListeners();
    
    //länge des Videos herraus finden
    
	player.addModelListener("STATE", "stateListener");

	var zoom_slider = $('zoom_slider');
	s1 = new Control.Slider(zoom_slider.down('.handle'), zoom_slider,
			{
				range: $R(0, 100),
				sliderValue: 0,
				onSlide: function(value)
				{
					player.sendEvent( 'SEEK' , value );
				},
				
				onChange: function(value)
				{ 
					//player.sendEvent( 'SEEK' , value );
				}
	});

	var zoom_slider_volume = $('zoom_slider_volume');
	s2 = new Control.Slider(zoom_slider_volume.down('.handle_volume'), zoom_slider_volume,
			{
				range: $R(0, 100),
				sliderValue: 60,
				onSlide: function(value)
				{
					player.sendEvent( 'VOLUME' , value );
				},
				
				onChange: function(value)
				{ 
					player.sendEvent( 'VOLUME' , value );
				}
	});
	
	$('vc_btn_play').observe(
			'click',
			function()
			{
				if ( player.getConfig().state != 'PLAYING' )
				{
					log( '-> PLAY ');
					player.sendEvent( 'PLAY' , true );
				}
			}
	);
	
	$('vc_btn_pause').observe(
			'click',
			function()
			{
				log( '-> PAUSE ');
				player.sendEvent( 'PLAY' , false );
			}
	);
	
	$('vc_btn_full').observe(
			'click',
			function()
			{
				log( '-> FULLSCREEN ');
				player.sendEvent ( '' );
			}
	);	
};

function addListeners() {
	if (player)
	{ 
		player.addModelListener("STATE" , "stateListener");
		player.addModelListener("TIME" , "timeTracker");
	}
	else
	{
		setTimeout("addListeners()",100);
	}
}

function stateListener(obj)
{
	currentState = obj.newstate; 
	previousState = obj.oldstate;
	
	if ( currentState == 'PLAYING' )
	{
		//	player.addModelListener(); 
	}
	log ( currentState );
}

function timeTracker(obj)
{
	var percentComplete = ( 100 *  ( obj.position / obj.duration ) );
	updateSlider ( percentComplete );
}

function updateSlider ( percent )
{
	s1.setValue( percent );
}


function addBackgroundEffects()
{
	Event.observe
	(
		'slideshowImage',
		'mouseover', 
		function ()
		{
			$('bnt_background').setStyle({backgroundImage: 'url(public/images/de/Button_alsHintergrund_dunkelgrau.jpg)'} );
		}
	);

Event.observe
	(
		'slideshowImage',
		'mouseout',
		function ()
		{
			$('bnt_background').setStyle({backgroundImage: 'url(public/images/de/Button_alsHintergrund_hellgrau.jpg)'} );
		}
	);

Event.observe
	(
		'bnt_background',
		'mouseover', 
		function ()
		{
			$('bnt_background').setStyle({backgroundImage: 'url(public/images/de/Button_alsHintergrund_dunkelgrau.jpg)'} );
		}
	);

Event.observe
	(
		'bnt_background',
		'mouseout',
		function ()
		{
			$('bnt_background').setStyle({backgroundImage: 'url(public/images/de/Button_alsHintergrund_hellgrau.jpg)'} );
		}
	);	
}

