window.addEvent( "domready", function() {
	
	var ad = $( "prestitial_ad" );
	if( !ad || ad.getElement( "td" ).getChildren().length < 3 ) {
		// nichts tun -> es wurde kein ad geladen
		return;
	}
	
	var background = $( "prestitial_background" );
	var header = $( "prestitial_header" );
	var link = header.getElement( "a" );

	function openPrestitial() {
		if( $defined( prestitial.bg ) ) {
			$( "prestitial_background" ).setStyle( "background-color", prestitial.bg );
		}
		
		link.addEvent( "click", function( event ) {
			event = new Event( event );
			event.stop();
			event.stopPropagation();
			closePrestitial()
		} );
		header.addEvent( "click", function() {
			link.fireEvent( "click" );
		} );
		
		var height = Browser.Engine.trident ? document.documentElement.clientHeight : window.innerHeight;
		ad.setStyle( "height", height - 80 ); 
		
		background.removeClass( "hidden" );
		$$( "div.flashcontainer" ).each( function( div ) {
			div.setStyle( "visibility", "hidden" );
		} );
	}

	function closePrestitial() {
		background.dispose();
//		background.addClass( "hidden" );
		
		$$( "div.flashcontainer" ).each( function( div ) {
			div.setStyle( "visibility", "" );
		} );
		
		header.removeEvents();
		link.removeEvents();
	}
	
	openPrestitial();
	var autoCloseSeconds = 10; // nach 10 sekunden (default) schlie�en
	if( $defined( prestitial.close ) && $type( prestitial.close ) == "number" ) autoCloseSeconds = prestitial.close;
	if( autoCloseSeconds > 0 ) closePrestitial.delay( autoCloseSeconds * 1000 );
} );

