        var menuIds = {  t0: {pg:"text0.html",mn:"menu.html"},
                         t1: {pg:"text1.html",mn:"menu1.html"},
	                     t11: {pg:"text11.html",mn:"menu1.html"},
	                     t12: {pg:"text12.html",mn:"menu1.html"},
	                     t2: {pg:"text2.html",mn:"menu2.html"},
	                     t21: {pg:"text21.html",mn:"menu2.html"},
	                     t22: {pg:"text22.html",mn:"menu2.html"},
	                     t23: {pg:"text23.html",mn:"menu2.html"},
	                     t3: {pg:"text3.html",mn:"menu.html",mh:400},
	                     t4: {pg:"text4.html",mn:"menu.html",mh:470},
	                     t5: {pg:"text5.html",mn:"menu.html"},
	                     t6: {pg:"text6.html",mn:"menu.html"},
	                     t7: {pg:"text7.html",mn:"menu.html"},
	                     t8: {pg:"text8.html",mn:"menu.html",mt:225,mh:240}
                      };

		var onUpArrow = false;
		var onDownArrow = false;
         var interrupted = false;
         var niceInterrupt = false;
         var mainHeight = 364;
         var defaultMainHeight = 364;
//         var deco = null;
         var introTime = 2.0;
         var swapTime = 4000;
         var backdropUrl = "url('gfx/bd_t1.jpg')";

	function setImg(elemId,src)
     {
     	var elem = $(elemId);
         if (elem)
         	elem.src = src;
     }


     function rand(max)
     {
     	return Math.floor(Math.random()*max);
     }
     function swapIntro( outDiv,inDiv,makeNice)
     {
     	if (!interrupted)
         {
	         if ($(outDiv))
	             new Effect.Fade(outDiv, {duration:introTime});
	         if ($(inDiv))
	             new Effect.Appear(inDiv, {duration:introTime});

	        niceInterrupt = makeNice;
     	}
     }


      function interruptIntro()
     {

		interrupted = true;

         if (niceInterrupt)
         {

	          new Effect.Fade('i6',{duration:0.5,queue:'end'});
	          new Effect.Fade('introcontent',{duration:0.5,queue:'end'});
	          new Effect.Appear('backdrop',{duration:0.5,queue:'end'});
	          new Effect.Appear('d_backdrop',{duration:0.5,queue:'end'});
	          new Effect.Appear('content',{duration:0.5,queue:'end'});
	          new Effect.Appear('logo',{duration:0.5,queue:'end'});
	          new Effect.Appear('main-caption',{duration:0.5,queue:'end'});
	          new Effect.Appear('main',{duration:0.5,queue:'end'});
	          new Effect.Appear('menu',{duration:0.5,queue:'end'});
		      if (contentIsScrolling())
		          new Effect.Appear('nav',{duration:0.5,queue:'end'});
//               if (deco)
  //		          new Effect.Appear(deco,{duration:0.5,queue:'end'});
         }
         else
         {
	         $("i1").hide();
	         $("i2").hide();
	         $("i3").hide();
	         $("i4").hide();
	         $("i5").hide();
	         $("i6").hide();
	         $("introcontent").hide();

	         $("logo").show();
	         $("backdrop").show();
	         $("d_backdrop").show();
	         $("content").show();
	         $("main-caption").show();
	         $("main").show();
	         $("menu").show();
	         if (contentIsScrolling())
	              $("nav").show();
	         else
	              $("nav").hide();

//	         if (deco)
//	             deco.show();
     	}

     }

     function showIntro(obj)
     {
              swapIntro("i0","i1");
              window.setTimeout("swapIntro('i1','i2')",swapTime);
              window.setTimeout("swapIntro('i2','i3')",swapTime*2);
              window.setTimeout("swapIntro('i3','i4')",swapTime*3);
              window.setTimeout("swapIntro('i4','i5')",swapTime*4);
              window.setTimeout("swapIntro('i5','i6',true)",swapTime*5);
     }

     function refreshMenuLinks()
     {
         Element.getElementsByClassName($("menu"),"mitem").each(function(item)
         {
          	Event.observe(item,"click", showContent);
             Event.observe(item,"mouseover", showHighlight);
             Event.observe(item,"mouseout", hideHighlight);
         });

        /*
        Event.observe($('up'),"click", upArrow);
        Event.observe($('down'),"click", downArrow);
	     if (!Prototype.Browser.WebKit)
	     {
	        Event.observe($('up'),"mouseover", activeUp);
	        Event.observe($('down'),"mouseover", activeDown);
	        Event.observe($('up'),"mouseout", deactiveUp);
	        Event.observe($('down'),"mouseout", deactiveDown);
          }

          */


     }

     function refreshLinks()
     {
         Element.getElementsByClassName($("main-content"),"link").each(function(item)
         {
          	Event.observe(item,"click", showContent);
         });
     }

     function showContent(evt)
     {
	     var child = Event.element(evt);

          if (child)
          {
		      getContent(child.readAttribute('menuid'),true);
          }
     }


     function positionMainContent(delta)
     {
     	var elem = $("main-content");
          if (elem)
          {
 	        var orgTop  = parseFloat(elem.getStyle('top')  || '0');
             var cHeight = getContentHeight() +30;
		    var scrollMin = -cHeight+ Math.min(cHeight,mainHeight);
             var newTop = Math.max(scrollMin,Math.min(0,orgTop+delta));

             checkArrows(newTop,scrollMin);

			elem.setStyle({top: newTop+ "px"});
          }
     }

     function positionMainContentAbsolute(pos)
     {
     	var elem = $("main-content");
          if (elem)
          {
 	        var orgTop  = parseFloat(elem.getStyle('top')  || '0');
             var cHeight = getContentHeight() +30;
		    var scrollMin = -cHeight+ Math.min(cHeight,mainHeight);
             var newTop = Math.max(scrollMin,Math.min(0,pos));
             checkArrows(newTop,scrollMin);
			elem.setStyle({top: newTop+ "px"});
          }
     }

     function checkArrows(newTop,scrollMin)
     {
             if (newTop == 0)
             {
             	$('up').hide();
             	$('top').hide();
             }
             else
             {
             	$('up').show();
             	$('top').show();
             }


             if (newTop == scrollMin)
     		{
             	$('down').hide();
             	$('bottom').hide();
             }
             else
     		{
             	$('down').show();
             	$('bottom').show();
             }
     }


     function getContentHeight()
     {
     	var result = 0;
		var elem = $("main-content");
         if (elem)
         {
             var elemDims = elem.getDimensions();
             result = elemDims.height;
     	}

         return result;
     }

     function contentIsScrolling()
     {
     	return getContentHeight() > mainHeight;
     }

     function showHighlight(evt)
     {
		var item = Event.element(evt);
         if (item)
         {
	         var id = item.id;
              if (id[0] == "i")
              	id = id.substr(1);

	         setImg("i"+id,"./gfx/menu/menu_h"+id + ".gif");
         }
     }

     function hideHighlight(evt)
     {
		var item = Event.element(evt);
         if (item)
         {
	         var id = item.id;
              if (id[0] == "i")
              	id = id.substr(1);

	         setImg("i"+id,"./gfx/menu/menu_"+id + ".gif");
         }
     }

     function topArrow(evt)
     {
		positionMainContentAbsolute(0);
     }
     function bottomArrow(evt)
     {
		positionMainContentAbsolute(-(getContentHeight() + 30));
     }
     function upArrow(evt)
     {
		positionMainContent(100);
     }

     function downArrow(evt)
     {
		positionMainContent(-100);
     }

     function activeUp(evt)
     {
     	onDownArrow = false;
     	if (!onUpArrow && !onDownArrow)
         {
	         onUpArrow = true;

	         new PeriodicalExecuter(function(pe) {
	             if (onUpArrow && !onDownArrow)
                  {
	                 positionMainContent(6);
                  }
	             else
                  {
		             pe.stop();

                  }
	         },0.03);
         }
     }

     function activeDown(evt)
     {

     	onUpArrow = false;

     	if (!onUpArrow && !onDownArrow)
         {
	         onDownArrow = true;

	         new PeriodicalExecuter(function(pe) {
	             if (onDownArrow && !onUpArrow)
	                 positionMainContent(-6);
	             else
                  {
		             pe.stop();

                  }
	         },0.03);
         }
     }
     function deactiveUp(evt)
     {
     	onUpArrow = false;
     	onDownArrow = false;

     }
     function deactiveDown(evt)
     {
     	onUpArrow = false;
     	onDownArrow = false;
     }

     function fadeInBg()
     {
		$("d_backdrop").setStyle({backgroundImage : backdropUrl } );
         new Effect.Appear('d_backdrop',{duration:0.5});
     }

     function fadeOutBg()
     {
		new Effect.Fade('d_backdrop',{duration:0.2,queue:'end',afterFinish: fadeInBg});
     }

     function getContent(id,mode)
     {
     	var mEntry = menuIds[id];
		Event.unloadCache();

         if (mEntry)
     	{
              new Ajax.Request('content/'+mEntry.pg+'?d='+rand(32768), {
	            method: "get",
	            onSuccess: function(transport)
                 {
		             $("main-content").update(  transport.responseText);
		             $("main-content").setStyle({top: "0px"});

                      var mCaption = $("main-content").firstDescendant().readAttribute("caption")
                      $("main-caption").update(mCaption);
					 document.title = "BIRGIT GELBE - Persönlichkeitscoaching - " +mCaption;

                      var newTop = 0;
                      if (mEntry.mt)
                      	newTop = mEntry.mt;

                      if (mEntry.mh)
	                      mainHeight = mEntry.mh;
                      else
	                      mainHeight = defaultMainHeight - newTop;

                      $("main").setStyle({top: (newTop + 100) + "px", height: mainHeight + "px"});
                      $("main-caption").setStyle({top: (newTop + 80) + "px"});

                      refreshLinks();

	                   if (contentIsScrolling())
                        {
                            	$('top').hide();
                            	$('up').hide();
                            	$('down').show();
                            	$('bottom').show();
	                        $("nav").show();
                        }
	                   else
	                        $("nav").hide();


                        newBackdropUrl =  "url('gfx/bd_"+id+".jpg')";


                        if (newBackdropUrl != backdropUrl)
                        {
	                       	backdropUrl = newBackdropUrl;
	                        if (mode)
	                             fadeOutBg();
	                        else
	                            $("d_backdrop").setStyle({backgroundImage : backdropUrl } );

                        }

	            }
	          });

              new Ajax.Request('menus/'+mEntry.mn+'?d='+rand(32768), {
	            method: "get",
	            onSuccess: function(transport)
                 {
		             $("menu").update(  transport.responseText);
                      refreshMenuLinks();

	            }
	          });
         }
     }

     function loadPage()
     {

     	var target = "t1";
         if( location.search.length > 0 )
         {
         	target = location.search.slice(1);
             if (!menuIds[target])
             	target = "t1";

              getContent(target,true);
              $("introcontent").hide();
	         $("backdrop").show();
	         $("d_backdrop").show();
	         $("logo").show();
	         $("content").show();
	         $("main-caption").show();
	         $("main").show();
	         $("menu").show();

              if (contentIsScrolling())
                   $("nav").show();
              else
                   $("nav").hide();

         }
         else
         {
              getContent(target,false);
//		     new Effect.Appear('logo',{duration:0.5,queue:'end'});
		     new Effect.Appear('introcontent',{duration:0.5,queue:'end',afterFinish: showIntro});
         }
     }