function doNextProject()
{
		new Ajax.Request( '/projekte/' + current_project + '/nextjson',
		{
			onComplete: function()
			{
				preload = new Image();
				preload.onload = function()
				{
          next_id  = next_image;
					next_img = $( "image_" + next_image);
					next_img.src 	 = result.src;
					next_img.title = result.title;
					
					next_container = $( "teaser_container" + next_image );
					next_container.style.zIndex = 20;
					
					next_image 		= (!next_image)?1:0;
					act_container = $('teaser_container' + next_image );
					act_container.style.zIndex =  10;
					
					new Effect.Appear( next_container, { duration: 1, afterFinish: function(){ $('teaser_container' + next_image).hide(); } } );
					
					$( 'teaser_link' + next_id ).href = 'projekte/' + result.url;
					$( 'teaser_link' + next_id ).title = result.title;
					current_project = result.url;

				}
				preload.src = result.src;
				
			}
		}
		);
}


var domready_callbacks = {
	'home_index': function()
	{
		tc = $('teaser_container1');
		if(tc) {
			tc.hide();	
		}
	},
	
	'services_index': function()
	{
		$('submenu').hide();
	},

	'partner_index': function()
	{
  	$$('.column').each( function(e){ e.hide(); });  
	}

}

var onload_callbacks = {
	'services_index': function()
  {
 		new Effect.BlindRight( 'submenu', { delay: 0.5, duration: 2 });
  },

	'home_index': function()
	{
		//pe = new PeriodicalExecuter( doNextProject, 5 );

	},
	
	'partner_index': function()
	{
 		i = 0;
    $$('.column').each( function( e ) {
    	new Effect.BlindDown( e, { delay: ++i, duraton: 2 } );
    });            
	}

}


function doBeforeLoad()
{
	var overlay_opacity = 0.85;

	if( $("content_related") )
	{
 		$("content_related").hide();		
	}

	modal_contact = new Control.Modal('contact',{
	    opacity: overlay_opacity,
	    width: 800,
	    height: 350,
	    fade: true,
	    onSuccess: function()
	    {
	        if( !$('closebutton') ) {
	            Control.Modal.closebutton = $(document.createElement('div'));
	            Control.Modal.closebutton.id = "closebutton";
	            Control.Modal.closebutton.innerHTML = '<img src="/images/btn_close.gif" alt="Schließen" title="Schließen" />';
	            Control.Modal.closebutton.onclick = Control.Modal.close;
	            Control.Modal.container.appendChild( Control.Modal.closebutton );
	        }
	    }
	});

	modal_impressum = new Control.Modal( 'impressum',{
	    opacity: overlay_opacity,
	    width: 800,
	    height: 350,
	    fade: true,
	    onSuccess: function()
	    {
	        if( !$('closebutton') ) {
	            Control.Modal.closebutton = $(document.createElement('div'));
	            Control.Modal.closebutton.id = "closebutton";
	            Control.Modal.closebutton.innerHTML = '<img src="/images/btn_close.gif" alt="Schließen" title="Schließen" />';
	            Control.Modal.closebutton.onclick = Control.Modal.close;
	            Control.Modal.container.appendChild( Control.Modal.closebutton );
	        }
	    }
	}); 
	
	var page_id = document.getElementsByTagName( 'body' )[0].id; //there is a prototype way?
	
 	// execute dom ready actions if applicable


 	if( domready_callbacks[page_id] ) {
		domready_callbacks[page_id]();
	}
	
	// register on load behaviour

	Event.observe( window, 'load', function() {
	    if( onload_callbacks[page_id] ) {
	        onload_callbacks[page_id]();
	    }
      if( $('content_related') ) {
				new Effect.BlindDown( 'content_related', { delay: 1, duration: 2.5 } );
			}
	} );

}

