dojo.require("dijit.layout.BorderContainer");
    dojo.require("dijit.layout.ContentPane");
    dojo.require("dojox.fx._base");
    /*dojo.require("dijit.Editor");
    dojo.require("dijit._editor.plugins.TextColor");*/
    /*dojo.require("dojo.io.iframe");*/
	dojo.require("dojox.timing._base");

    
    
    var imgButtonAlleFotos = new Image();
    var imgButtonAlleFotosGrey=new Image();
    imgButtonAlleFotos.src = 'menu/button_alle_fotos.gif';
    imgButtonAlleFotosGrey.src='menu/button_alle_fotos_grey.gif';
    var blackImg = new Image();
    var downloadImg = new Image();
    blackImg.src = 'blackimg.gif';
    downloadImg.src = 'image/downloadImg.gif';
	
	/* Bilder für Werbung */
    var werbungAnzahl=3;
	var werbungCurrent=0;
	var werbungImg = new Array();
	var werbungLink=new Array();
	werbungImg[0]=new Image();
	werbungImg[0].src='werbung/SuFresh-Logo__1.gif';
	werbungLink[0] = 'romena.ch';
	werbungImg[1]=new Image();
	werbungImg[1].src='werbung/brasilien_li_80.jpg';
	werbungLink[1] = 'brasilien.li';
	werbungImg[2]=new Image();
	werbungImg[2].src = 'werbung/waldfest_2011.jpg';
	werbungLink[2] = null;
	/*werbungImg[2]=new Image();
	werbungImg[2].src = 'werbung/waldfest2010_22.jpg';
	werbungLink[2] = null;*/
	/*werbungImg[4]=new Image();
	werbungImg[4].src='werbung/zoastore.jpg';
	werbungLink[4] = 'www.zoastore.com';*/
	
	
    var rightContentPane;
    var leftDivContainer;
    var mainDivContainer;
    var leftMenuContentPane;
    var happyhourContentPane;

    var fotosBorderContainer;
    var fotosSmallContentPane;
    var fotosBigContentPane;
    
    var gesamtBreite = 1025;
    var gesamtBreiteLinks = 322;
    var gesamtBreiteRechts = gesamtBreite-gesamtBreiteLinks;
    var gesamtHoehe = 610;
    
    var actualFotosTable = 0;
    var actualFotoRow = 0;
    var actualImg = 0;
    var actualImgNo = -1;
    var fotoBig;
    var fotoBigLeft;
    var fotoBigRight;
    var sImage = new Array();
    var imageFile= new Array();
    //var imageFileOrientation=new Array();
    var imageFileWidth=new Array();
    var img = new Array();
    var imgt = new Array();
    var tdimg = new Array();
    var tdimgt = new Array();
    var fotoRowTable = new Array();
    var showGalleryOnLoadOld;
    var getImageFileDone=false;
    var galleryLoadDone=false;
    var eventPath;
    var fotosScrollAnimation=null;
    var isFotosSmallDIVMinimized = false;
    var dxFotosRow=660;
    var isMenuMinimized=new Array(true,true,true,true,true);
    var menuHeight=new Array(20,0,0,20,0);
    var isgugus=false;
    var isgbsmiliesDivMinimized=true;
    var flyerInfoAnimation=null;
    var gbRange =null;
  
    dojo.addOnLoad(function(){
      mainDivContainer = new dijit.layout.BorderContainer({"design": "sidebar", "gutters":false, "style": "height: "+gesamtHoehe+"px; width: "+gesamtBreite+"px; padding:0px; margin:0px;  border: 0px solid #333333;"}, "mainDivContainer");
      leftDivContainer = new dijit.layout.BorderContainer({"design": "headline", "gutters":false, "region": "left", "style": "height: 100%; width:"+gesamtBreiteLinks+"px; border: 0px; padding:0px; margin:0px;"}, "leftDivContainer");
      var leftImgContentPane  = new dijit.layout.ContentPane({"region": "top","style": "width: 100%; height: 270px; background-color: black; border: 0px; padding: 0px; margin:0px;"}, "leftImgContentPane");
      leftMenuContentPane = new dijit.layout.ContentPane({"region": "center","style": "width: 100%; height: "+(gesamtHoehe-270)+"px; text-align: left; background-color: black; border: 0px; padding: 40px 0px 0px 0px; margin:0px;overflow:hidden;"}, "leftMenuContentPane");
      //leftMenuContentPane.onDownloadEnd=leftMenuContentPaneOnEnd;
      rightContentPane    = new dijit.layout.ContentPane({"region": "center", "style": "text-align:left; font-family:arial; width: 100%; height: 100%; background-color: black; color:white; padding: 0px; margin: 0px; border: 0px solid #333333; overflow:hidden;", "loadingMessage":"Die Seite wird geladen! Bitte um etwas Geduld!!"}, "rightContentPane");
      //rightContentPane = new dojox.layout.FloatingPane({"region": "center", "title":"gugus", "style": "text-align:right; width: 100px; height: 200px; background-color: yellow; border: 0; padding:0; margin:0;"}, "rightContentPane");
      happyhourContentPane = new dijit.layout.ContentPane({"region": "center", "style": "text-align:left; font-family:arial; width: 100%; height: 100%; background-color: black; color:white; padding: 0px; margin: 0px; border: 0px solid #333333; overflow:hidden;", "loadingMessage":"Die Seite wird geladen! Bitte um etwas Geduld!!"}, "happyhourContentPane");
      happyhourContentPane.attr('href', 'happyhour.html?g='+Math.random());
      //fotosBorderContainer = new dijit.layout.BorderContainer({"design": "headline", "gutters":false, "region": "center", "style": "height: 100%; width:100%; border: 0; padding:0; margin:0;"}, "fotosBorderContainer");
      //fotosSmallContentPane = new dijit.layout.ContentPane({"region": "top", "style": "text-align:right; width: 630px; height: 120px; background-color: black; border: 0; padding:0; margin:0; overflow: hidden;"}, "fotosSmallContentPane");
      //fotosBigContentPane = new dijit.layout.ContentPane({"region": "center", "style": "text-align:right; width: 100%; height: 100%; background-color: black; border: 0; padding:0; margin:0;"}, "fotosBigContentPane");
      //fotosContentPane = new dijit.layout.ContentPane({"region": "center", "style": "text-align:right; width: 100%; height: 100%; background-color: black; border: 0; padding:0; margin:0; overflow: hidden;"}, "fotosSmallContentPane");
      
      //fotosSmallContentPane.attr('href', 'fotos2.html');
      //fotosBigContentPane.attr('href', 'fotobig.html');
      //fotosBorderContainer.addChild(fotosSmallContentPane);
      //fotosBorderContainer.addChild(fotosBigContentPane);
      //fotosContentPane.attr('href', 'fotos2.html');
      
      leftImgContentPane.attr("content", '<IMG SRC="coco_brasil_kopf.jpg" width="320" />');
      leftMenuContentPane.attr('href', 'menu.html?g='+Math.random());
      rightContentPane.attr("content", "rechts..");
      
      leftDivContainer.addChild(leftImgContentPane);
      leftDivContainer.addChild(leftMenuContentPane);
      mainDivContainer.addChild(leftDivContainer);
      mainDivContainer.addChild(rightContentPane);
    
      setContentIMG('content/home.jpg');
      
      mainDivContainer.startup(); 
      werbungTimer = new dojox.timing.Timer();
	  werbungTimer.setInterval(3000);
	  werbungTimer.onTick = werbungTimerOnTick;
	  werbungTimer.start();
     
    });
	
   function werbungTimerOnTick() {
	   werbungCurrent = (werbungCurrent+1)%werbungAnzahl;
       var tmp = dojo.byId('imgwerbung2');
	   tmp.src = werbungImg[werbungCurrent].src;
       if(werbungLink[werbungCurrent]==null) tmp.style.cursor='default';
	   else tmp.style.cursor='pointer';
   }
   
   function leftMenuContentPaneOnEnd() {
      var gg =dojo.byId('divwerbung');
      var g1= dojo.byId('imgwerbung1');
      
      alert('top: '+dojo._abs(gg).y);
      g1.style.top=dojo._abs(gg).y-50;
      g1.style.left=0;
   }
   
   function afterLoadingGallery() {
      if(!getImageFileDone || !galleryLoadDone) return;
      initializeImg();
      rightContentPane.onLoad = showGalleryOnLoadOld;
      initializeSmallImages();
      //rightContentPane.style.visibility = 'visible';
   }
   
   function checkFotosDIV() {
      var b = dojo.byId('buttonAllFotos');
      var bl = dojo.byId('bigfotoleft');
      var br = dojo.byId('bigfotoright');
      if(isFotosSmallDIVMinimized) {
         b.src = imgButtonAlleFotos.src;
         bl.style.visibility='visible';
         br.style.visibility='visible';
      }
      else {
         b.src = imgButtonAlleFotosGrey.src;
         bl.style.visibility='hidden';
         br.style.visibility='hidden';
      }
   }
   
   function checkMenuOnClick(mi) {
      var nh=1;
      for(var i=0; i<isMenuMinimized.length; i++) {
         if(i==mi) continue;
         if(!isMenuMinimized[i]) {
            dojox.fx.wipeTo({node: 'subMenu'+i, duration:500, height: 1}).play();
            isMenuMinimized[i]=true;
         }
      }
      if(mi==-1) return;
      if(menuHeight[mi]==0) return;
      if(isMenuMinimized[mi]) nh=menuHeight[mi];
      dojox.fx.wipeTo({node: 'subMenu'+mi, duration:500, height: nh}).play();
      isMenuMinimized[mi]=!isMenuMinimized[mi];
   }
   
   function downloadActBigImg() {
      downloadBigImg(fotoBigRight, actualImgNo);
   }
   
   function downloadBigImg(bigImg, imgNo) {
      if(imgNo<0 || imgNo>=imageFile.length) return;
      bigImg.src = getImageFile(imgNo);
      /*var bWidth=640;
      var bHeight=480;
      if(imageFileOrientation[imgNo]=='h') {
         bWidth = 360; //338;
         bHeight= 480;
      }*/
      bigImg.width=imageFileWidth[imgNo];
      bigImg.height=480;
   }
   
   function downloadNextBigImg() {
      downloadBigImg(fotoBigRight, actualImgNo+1);
   }
   
   function downloadPrevBigImg() {
      downloadBigImg(fotoBigLeft, actualImgNo-1);
   }
   
   function downloadSmallImages(from, to) {
        //alert('download from: '+from+'   to: '+to);
        var imgWidth;
        var imgHeight;
        
        for(var i=from; i<=to && i<imageFile.length; i++) {
            if(!sImage[i]) {
                sImage[i] = new Image();
                sImage[i].src = eventPath+'s'+imageFile[i]; /*+'?g='+Math.random();*/
            }
        }
    } 
    
   function gbEditorOnKeyDown()
   {
   return true;
      if(window.event && window.event.keyCode) {
         var kc = window.event.keyCode;
         
         if(kc==13 || kc==10) {
            /*window.event.shiftKey = true;
            window.event.keyCode=13;
            return true;*/
            var gbeditor = dojo.byId('gbeditordiv');
            gbeditor.focus();
            var range = gbeditor.document.selection.createRange();
            range.pasteHTML("<BR>");
            gbeditor.focus();
            return false;
         }
      }
      return true;
   }
   
   function getImageFile(imgNo) {
      return eventPath+imageFile[imgNo];
   }
   
   
   function getImageFileJSON() {
      dojo.xhrPost({
         url: eventPath+'getImageFile.php?g='+Math.random(),
         load: getImageFileCallback,
         error: getImageFileError,
         preventCache: true
         /*content: {'g': Math.random()}*/
      });
   }
   
   function getImageFileCallback(data,ioArgs) {
      //alert('data: '+data);
      var obj = eval('('+data+')');
      imageFile = obj.imgFile;
      //imageFileOrientation = obj.orientation;
      imageFileWidth=obj.widths;
      getImageFileDone=true;
      afterLoadingGallery();
   } 
   
   function getImageFileError(data, ioArgs) {
      alert('Ein Fehler trat auf.... :-(');
      alert('data: '+data.message);
   }
   
   function happyhourVisible(visible) {
      if(visible) {
          mainDivContainer.removeChild(rightContentPane);
          mainDivContainer.addChild(happyhourContentPane);
      }
      else {
          mainDivContainer.removeChild(happyhourContentPane);
          mainDivContainer.addChild(rightContentPane);
      }
   }
   
   function hitImage() {
      var fn = imageFile[actualImgNo];
      dojo.xhrPost({
         url: 'hitImage.php',
         preventCache: true,
         content: { 'g':Math.random(), 'todo':'hit', 'fn': fn}
      });
   }
   
   function hitImageOnLoad() {
      alert('hit...');
   }
   function hitImageOnError() {
      alert('hit error');
   }
  
   function initializeImg() {
      for(var i=0; i<=39; i++)
         img[i] = dojo.byId('img'+i);
      for(var i=0; i<=3; i++)
         imgt[i] = dojo.byId('imgt'+i);
      for(var i=0; i<=39; i++)
         tdimg[i] = dojo.byId('tdimg'+i);
      for(var i=0; i<=3; i++)
         tdimgt[i] = dojo.byId('tdimgt'+i);
      for(var i=0; i<=9; i++)
         fotoRowTable[i] = dojo.byId('t'+i);
      
      fotoBig= dojo.byId('fotoBig');
      fotoBigLeft = dojo.byId('fotoBigLeft');
      fotoBigRight = dojo.byId('fotoBigRight');
   }
    
   function initializeSmallImages() {
      //TODO: was wenn weniger als 19 bilder??
      var to = 39;
      downloadSmallImages(0, to);
      setSmallImages(0);
   }
    
   function moveSmily(node) {
      var imgSmily = dojo.byId('smily');
      var dy = dojo._abs(node).y - dojo._abs(imgSmily).y-7;
      //var cImg = dojo.coords(imgSmily);
      //var cNode = dojo.coords(node);
      //alert('i: '+cImg.h+'   n: '+cNode.h);
      //var dy = cNode.y - cImg.y-10;// + (cImg.h-cNode.h)/2;
      dojox.fx.slideBy({node: "smily", duration:400, top: dy}).play();
      //node.src = node.src;
   }
   
   function partyNewsLetterOnClick() {
      var el = dojo.byId('formpartynewsletter').elements;
      
      dojo.xhrPost({
           url: 'partynewsletter.php',
           load: partyNewsLetterOnLoad,
           error: partyNewsLetterOnError,
           preventCache: true,
           content: { 'g':Math.random(), 'todo':'registrieren', 'vorname': escape(el['vorname'].value),
                      'nachname':escape(el['nachname'].value), 'email':escape(el['email'].value),
                      'partyCB':el['partyCB'].checked, 'fotoCB': el['fotoCB'].checked }});
   }
   
   function partyNewsLetterOnError(data, ioArgs) {
      alert('es trat ein Fehler auf: '+data.message);
   }
   
   function partyNewsLetterOnLoad(data, ioArgs) {
       rightContentPane.attr("content", data);
   }
   
   function scrollAllFotosToLeft() {
      //TODO: ist das hier ueberhaupt noetig?? pruefen, ob ueberhaupt noch 5 foto-rows vorhanden sind....
      
      //for(var i=0; i<20 && i<imageFile.length; i++) {
      //   setSImg(img[i+20], img[i]);
      //}
      for(var i=0; i<20; i++) {
         if(i<imageFile.length) setSImg(img[i+20], img[i], i+20, tdimg[i].innerHTML);
         else setSImg(img[i+20], null, i+20);
      }
      for(var i=0; i<5; i++) {
         fotoRowTable[i+5].style.left=0;
         fotoRowTable[i].style.left=-dxFotosRow;
      }
      var di= actualFotoRow*4-20;
      for(var i=0; i<20; i++) {
         setSImg(img[i], sImage[i+di], i, i+di+1);
      }
      
      fotosScrollAnimation = dojo.fx.combine([
         dojox.fx.slideBy({node: 't0', duration:500, left: dxFotosRow}),
         dojox.fx.slideBy({node: 't1', duration:500, left: dxFotosRow}),
         dojox.fx.slideBy({node: 't2', duration:500, left: dxFotosRow}),
         dojox.fx.slideBy({node: 't3', duration:500, left: dxFotosRow}),
         dojox.fx.slideBy({node: 't4', duration:500, left: dxFotosRow}),
         dojox.fx.slideBy({node: 't5', duration:500, left: dxFotosRow}),
         dojox.fx.slideBy({node: 't6', duration:500, left: dxFotosRow}),
         dojox.fx.slideBy({node: 't7', duration:500, left: dxFotosRow}),
         dojox.fx.slideBy({node: 't8', duration:500, left: dxFotosRow}),
         dojox.fx.slideBy({node: 't9', duration:500, left: dxFotosRow})
      ]);
      //fotosScrollAnimation.onEnd = scrollAllFotosToLeftOnEnd;
      fotosScrollAnimation.play();
      
      actualFotoRow-=5;
      
   }
   
   function scrollAllFotosToRight(){
      if(actualFotoRow+5> imageFile.length/4) return;
      
      actualFotoRow+=5;
      var temp = (actualFotoRow+5)*4;
      downloadSmallImages(temp, temp+19);
      
      fotosScrollAnimation = dojo.fx.combine([
         dojox.fx.slideBy({node: 't0', duration:500, left: -dxFotosRow}),
         dojox.fx.slideBy({node: 't1', duration:500, left: -dxFotosRow}),
         dojox.fx.slideBy({node: 't2', duration:500, left: -dxFotosRow}),
         dojox.fx.slideBy({node: 't3', duration:500, left: -dxFotosRow}),
         dojox.fx.slideBy({node: 't4', duration:500, left: -dxFotosRow}),
         dojox.fx.slideBy({node: 't5', duration:500, left: -dxFotosRow}),
         dojox.fx.slideBy({node: 't6', duration:500, left: -dxFotosRow}),
         dojox.fx.slideBy({node: 't7', duration:500, left: -dxFotosRow}),
         dojox.fx.slideBy({node: 't8', duration:500, left: -dxFotosRow}),
         dojox.fx.slideBy({node: 't9', duration:500, left: -dxFotosRow})
      ]);
      fotosScrollAnimation.onEnd = scrollAllFotosToRightOnEnd;
      fotosScrollAnimation.play();
   }
   
   function scrollAllFotosToRightOnEnd() {
      for(var i=20; i<39; i++) {
         if(i<imageFile.length) {
            //img[i-20].src = img[i].src;
            //img[i-20].width = img[i].width;
            //img[i-20].height = img[i].height;
            setSImg(img[i-20], img[i], i-20, tdimg[i].innerHTML);
         }
         else
             setSImg(img[i-20], null, i-20);
      }
      for(var i=0; i<5; i++) {
         fotoRowTable[i].style.left=0;
         fotoRowTable[i+5].style.left=dxFotosRow;
      }
      setSmallImages(actualFotoRow*4); //TODO: die funktion macht die doppelte arbeit...
   }
   
   function scrollBigFotoToLeft() {
      if(!isFotosSmallDIVMinimized) return;
      if(fotosScrollAnimation!=null && fotosScrollAnimation.status()=="playing") //"paused", "playing", "stopped"
         return;
      //if(actualFotoRow+actualImg<=0) return;
      if(actualImgNo<=0) return;
      
      //TODO: aktuelle fotoRow event. wieder zurückschieben....
      
      setActImgBorderToNormal();
      
      if(actualImgNo%4==0) {
         //--actualFotoRow;
         actualImg=3;
         --actualImgNo;
         if(Math.floor(actualImgNo/4)==actualFotoRow-1)
            scrollFotosToLeft();
      }
      else { --actualImg; --actualImgNo; }
      
      var dx= 700+Math.floor((640-imageFileWidth[actualImgNo])/2);
      fotosScrollAnimation = dojo.fx.combine([
         dojox.fx.slideBy({node: 'fotoBigLeft', duration:500, left: dx}),
         dojox.fx.slideBy({node: 'fotoBig', duration:500, left: 700})
      ]);
      fotosScrollAnimation.onEnd = scrollBigFotoToLeftOnEnd;
      fotosScrollAnimation.play();
      hitImage();
   }
   
   function scrollBigFotoToLeftOnEnd() {
      setActImgBorderToActive();
      fotoBig.src = fotoBigLeft.src;
      fotoBig.width = fotoBigLeft.width;
      fotoBig.height = fotoBigLeft.height;
      fotoBig.style.left=fotoBigLeft.style.left;
      fotoBigLeft.style.left=-675;
      downloadPrevBigImg();
      downloadNextBigImg();
   }
   
   function scrollBigFotoToRight() {
      if(!isFotosSmallDIVMinimized) return;
      if(fotosScrollAnimation!=null && fotosScrollAnimation.status()=="playing") //"paused", "playing", "stopped"
         return;
      //if(actualFotoRow*4+actualImg+1 >= imageFile.length) return;
      if(actualImgNo+1 >= imageFile.length) return;
      
      //TODO: falls aktuelles neues Foto
      
      setActImgBorderToNormal();
      
      if(actualImgNo%4==3) {
         //++actualFotoRow;
         actualImg=0;
         ++actualImgNo;
         if(Math.floor(actualImgNo/4)==actualFotoRow+1)
            scrollFotosToRight();
      }
      else { ++actualImg; ++actualImgNo; }
      
      var dx= -700+Math.floor((640-imageFileWidth[actualImgNo])/2);
      fotosScrollAnimation = dojo.fx.combine([
         dojox.fx.slideBy({node: 'fotoBig', duration:500, left: -700}),
         dojox.fx.slideBy({node: 'fotoBigRight', duration:500, left: dx})
      ]);
      fotosScrollAnimation.onEnd = scrollBigFotoToRightOnEnd;
      fotosScrollAnimation.play();
      hitImage();
   }
   
   function scrollBigFotoToRightOnEnd() {
      setActImgBorderToActive();
      fotoBig.src = fotoBigRight.src;
      fotoBig.width= fotoBigRight.width;
      fotoBig.height=fotoBigRight.height;
      fotoBig.style.left= fotoBigRight.style.left;
      fotoBigRight.style.left=725;
      downloadPrevBigImg();
      downloadNextBigImg();
   }
   
   function scrollFotosToLeft() {
      if(fotosScrollAnimation!=null && fotosScrollAnimation.status()=="playing") //"paused", "playing", "stopped"
         return;
      if(actualFotoRow<=0) return;
      
      setActImgBorderToNormal();
      
      if(!isFotosSmallDIVMinimized) {
         scrollAllFotosToLeft();
         return;
      }
      
      var t0 = dojo.byId('t0');
      var tt = dojo.byId('tt');
      
      var di=actualFotoRow*4-4;
      for(var i=0; i<=3; i++) {
         //imgt[i].src = sImage[i+di].src;
         //imgt[i].width = sImage[i+di].width;
         //imgt[i].height = sImage[i+di].height;
         setSImg(imgt[i], sImage[i+di], -i, i+di+1);
      }
      tt.style.left=-dxFotosRow;
      //t5.style.top=0;
      
      fotosScrollAnimation = dojo.fx.combine([
         dojox.fx.slideBy({node: 'tt', duration:500, left: dxFotosRow}),
         dojox.fx.slideBy({node: 't0', duration:500, left: dxFotosRow})
      ]);
      fotosScrollAnimation.onEnd = scrollFotosToLeftOnEnd;
      fotosScrollAnimation.play();
      --actualFotoRow;
   }
    
    function scrollFotosToLeftOnEnd() {
        var t0 = dojo.byId('t0');
        var tt = dojo.byId('tt');    
        var di=actualFotoRow*4;
        
        setSmallImages(di);
        t0.style.left=0;
        tt.style.left=-dxFotosRow;
    }
    
    function scrollFotosToRight() {
       if(fotosScrollAnimation!=null && fotosScrollAnimation.status()=="playing") //"paused", "playing", "stopped"
           return;
       if(actualFotoRow*4+4 >= imageFile.length) return;
       
       setActImgBorderToNormal();
       
       if(!isFotosSmallDIVMinimized) {
           scrollAllFotosToRight();
           return;
       }
       
       var t0 = dojo.byId('t0');
       //var t1 = dojo.byId('t1');
       var tt = dojo.byId('tt');
       var di=actualFotoRow*4+4;
        
       tt.style.left=dxFotosRow;
       tt.style.top=0;
       
       for(var i=0; i<=3; i++) {
           if( i+di < imageFile.length) {
               //imgt[i].src = sImage[i+di].src;
               //imgt[i].width = sImage[i+di].width;
               //imgt[i].height = sImage[i+di].height;
               setSImg(imgt[i], sImage[i+di], -i, i+di+1);
           }
           else
               setSImg(imgt[i], null, -i);
       }
       
       fotosScrollAnimation = dojo.fx.combine([
          dojox.fx.slideBy({node: 'tt', duration:500, left: -dxFotosRow}),
          dojox.fx.slideBy({node: 't0', duration:500, left: -dxFotosRow})
       ]);
       fotosScrollAnimation.onEnd = scrollFotosToRightOnEnd;
       fotosScrollAnimation.play();
       ++actualFotoRow;
       //TODO: event in scrollFotosToRightOnEnd()
       var temp = (actualFotoRow+9)*4;
       downloadSmallImages(temp, temp+3);
    }
    
    function scrollFotosToRightOnEnd() {
        //var temp = (actualFotoRow+9)*4;
        //downloadSmallImages(temp, temp+3);
        var t0 = dojo.byId('t0');
        var tt = dojo.byId('tt');
        var di=actualFotoRow*4;
        
        setSmallImages(di);
        
        t0.style.left=0;
        tt.style.left=dxFotosRow;
    }
    
   function setActImgBorderToActive() {
      //alert('Active - actualFotoRow: '+actualFotoRow+'\nactualImgNo: '+actualImgNo);
      if(actualImgNo==-1) return;
      if(Math.floor(actualImgNo/4) == actualFotoRow  && isFotosSmallDIVMinimized)
         img[actualImgNo%4].style.borderColor= 'green';//'red';
      else if(!isFotosSmallDIVMinimized) {
         img[actualImgNo%20].style.borderColor='green';
      }
   }
   
   function setActImgBorderToNormal() {
      //alert('Normal - actualFotoRow: '+actualFotoRow+'\nactualImgNo: '+actualImgNo);
      if(actualImgNo==-1) return;
      if(Math.floor(actualImgNo/4) == actualFotoRow && isFotosSmallDIVMinimized)
         img[actualImgNo%4].style.borderColor='#555555';
      else if(!isFotosSmallDIVMinimized)
         img[actualImgNo%20].style.borderColor='#555555';
      
   }
    
   function setBigFlyer(flyer) {
      var bigFyler = dojo.byId('bigFlyer');
      bigFyler.src = flyer;
   }
   
   function setBigFoto(imgSmall) {
      setActImgBorderToNormal();
      var id_table = parseInt(imgSmall.parentNode.parentNode.parentNode.parentNode.id.substring(1));
      actualFotosTable = id_table;
      actualFotoRow = actualFotoRow + parseInt(id_table);
      actualImg = parseInt(imgSmall.id.substring(3))%4;
      actualImgNo = actualFotoRow*4+actualImg;
      //setActImgBorderToActive();
      
      var temp = (actualFotoRow+5)*4;
      downloadSmallImages(temp, temp+19);
      
      downloadActBigImg();
      
      var a = new Array();
      //TODO: fadeOut nur machen, wenn isFotosSmallDIVMinimized==true
      a.push(dojo.fadeOut({node: "fotoBig", duration:500, onEnd: setBigFotoFadeOutOnEnd}));
      
      var dy = id_table*122;
      
      if(id_table!=0) {
         for(var i=id_table; i >=0; i--) {
            a.push(dojox.fx.slideBy({node: 't'+i, duration:500, top: -dy}));
         }
      }
      
      if(!isFotosSmallDIVMinimized)
         a.push(dojox.fx.wipeTo({node: "fotosSmallDIV", duration:500, height: 110}));
      
      if(a.length!=0) {
          var gugus = dojo.fx.combine(a);
          gugus.onEnd = setBigFotoOnEnd;
          gugus.play();
      }
      isFotosSmallDIVMinimized = true;
      checkFotosDIV();
      hitImage();
      //alert('done setBigFoto()');
   }
   
   function setBigFotoFadeOutOnEnd() {
      setActImgBorderToActive();
      fotoBig.src = fotoBigRight.src;
      fotoBig.width= fotoBigRight.width;
      fotoBig.height= fotoBigRight.height;
      fotoBig.style.left = 25+Math.floor((640-imageFileWidth[actualImgNo])/2);
      dojo.fadeIn({node: "fotoBig", duration:500}).play();
      downloadNextBigImg();
      downloadPrevBigImg();
      fotoBig.style.borderWidth=1;
   }
   
   function setBigFotoOnEnd() {
      if(actualFotosTable==0) return;
      var tt = dojo.byId('tt');
      var di = actualFotoRow*4;
      for(var i=0; i<4; i++) {
         if( i+di < imageFile.length) {
            //imgt[i].src = sImage[i+di].src;
            //imgt[i].width = sImage[i+di].width;
            //imgt[i].height = sImage[i+di].height;
            setSImg(imgt[i], sImage[i+di], -i, i+di+1);
         }
         else
            setSImg(imgt[i], null, -i);
      }
      tt.style.left=0;
      for(var i=1; i<5; i++) {
         fotoRowTable[i].style.top= i*122;
      }
      setSmallImages(di);
      fotoRowTable[0].style.top=0;
      tt.style.left=-dxFotosRow;
      actualFotosTable=0;
   }
   
   function setContentHREF(doc, p) {
       if(typeof p=="undefined") rightContentPane.attr('href', doc+'?g='+Math.random());
       else rightContentPane.attr('href', doc+'&g='+Math.random());
   }
   
   function setContentIMG(img) {
      rightContentPane.attr('content', '<IMG STYLE="position:absolute;left:100px;top:0px;" SRC="'+img+'" />');
   }
   
   function setContentMap(doc) {
      rightContentPane.onLoad = setContentMapOnLoad;
      rightContentPane.attr('href', doc+'?g='+Math.random());
   }
   
   function setContentMapOnLoad(e) {
      var searchMap= new SearchChMap({ center:"Winterthur, Schauffhauserstr. 4" });
      searchMap.set({ center:"Winterthur, Schauffhauserstr. 4" });
      searchMap.showPOIGroup("verkehr,bar");
      rightContentPane.onLoad = null;
   }
   
   function setSImg(dest, source, i, no){
       if(source==null || source.src==null || source.src.indexOf('null')!=-1) {
          dest.src=null
          dest.style.visibility = 'hidden';
          if(i>=0) tdimg[i].style.visibility='hidden';
          else tdimgt[-i].style.visibility='hidden';
          return;
       }
       dest.src = downloadImg.src;
       dest.style.visibility = 'visible';
       dest.src=source.src;
       dest.alt = 'Bild-Nr: '+no;
       if(i>=0) {setSImgNo(tdimg[i], no);tdimg[i].style.visibility='visible'; }
       else {setSImgNo(tdimgt[-i], no);tdimgt[-i].style.visibility='visible'}
   }
   
   function setSImgNo(tdImg, no) {
      tdImg.innerHTML=''+no;
   }
   
   function setSmallImages(di) {
      for(var i=0; i<=39; i++) {
         try {
            if((i+di)<imageFile.length) {setSImg(img[i], sImage[i+di],i, i+di+1); }
            else setSImg(img[i], null, i);
         }
         catch(err) {
            alert('err: '+err.description);
         }
      }
      setActImgBorderToActive();
   }
   
   function showFotosOverwiev() {
      if(!isFotosSmallDIVMinimized) return;
      setActImgBorderToNormal();
      
      var id_table = actualFotoRow%5;
      var firstRowNo = actualFotoRow-id_table;
      var dy = id_table*122;
      for(var i=4; i>=0; i--)
          fotoRowTable[i].style.top= -(id_table-i)*122;
      isFotosSmallDIVMinimized=false;
      actualFotoRow -=id_table;
      setSmallImages(firstRowNo*4);
      
      var a = new Array();
      if(id_table!=0) {
         for(var i=4; i >=0; i--) a.push(dojox.fx.slideBy({node: 't'+i, duration:500, top: dy}));
      }
      a.push(dojox.fx.wipeTo({node: "fotosSmallDIV", duration:500, height: 608, onEnd:showFotosOverwievOnEnd}));
      dojo.fx.combine(a).play();
      checkFotosDIV();
   }
   
   function showFotosOverwievOnEnd() {
      fotoBig.src=blackImg.src;
      fotoBig.style.borderWidth=0;
   }
   
   function showGallery(ep) {
      eventPath= 'fotos/'+ep+'/';
      imageFile.length=0;
      sImage.length=0;
      imageFileWidth.length=0;
      img.length=0;
      imgt.length=0;
      tdimg.length=0;
      tdimgt.length=0;
      fotoRowTable.length=0;
    
      actualFotosTable=0;
      actualFotoRow=0;
      actualImg = 0;
      actualImgNo = -1;
      isFotosSmallDIVMinimized=false;
      getImageFileDone=false;
      galleryLoadDone=false;
      
      //rightContentPane.style.visibility="hidden";
      
      showGalleryOnLoadOld = rightContentPane.onLoad;
      rightContentPane.onLoad = showGalleryOnLoad;
      rightContentPane.attr('href', 'fotos.html?g='+Math.random());
      
      getImageFileJSON();
   }
    
   function showGalleryOnLoad(e) {
      galleryLoadDone = true;
      afterLoadingGallery();
   }
   
    
    
    
    function printObjectValues(obj) {
        //alert('id: '+obj.id);
        var text = "";
        var i=0;
        for(o in obj) {
           text += "\n\n"+o+' - '+obj[o];
           ++i;
           if(i==5) {
               i=0;
               alert(text);
               text="";
           }
        }
        alert(text);
    }

    function printStatus(funk) {
       alert(funk+'\ngetImageFileDone: ' +getImageFileDone +'\ngalleryLoadDone: '+galleryLoadDone);
    
    }
    
    function dogugus2() {
       setContentHREF('guestbook.php?todo=listEntries2', true)
    return;
    }
    
    function dogugus() {
       setContentHREF('guestbook.php?todo=listEntries', true)
       return;    
    }
    
   function doinsert() {
      /* EnterKeyHandling
         blockNodeForEnter 
      */
      var gbe2 = dojo.byId("gbeditor2");
      gbe2.focus();
      //document.execCommand('inserthtml',false, 'allo <img src="smily/smilie_happy_008.gif">');
      document.execCommand('InsertImage', false, 'smily/smilie_happy_008.gif');
      return;
       
      var gbe = dijit.byId("gbeditor");
      //gbe.setValue('dfs<img src="smily/smilie_happy_008.gif">');
      gbe.execCommand('inserthtml', 'allo <img src="smily/smilie_happy_008.gif">');
   }
   
   function doinsert2() {
      var gbe = dijit.byId("gbeditor");
      //gbe.execCommand('paste', 'hallo');
      gbe.execCommand('insertImage', 'smily/smilie_happy_008.gif');
      //var r = gbe.document.selection.createRange();
      //printObjectValues(r);
      //r.text = '<img src="smily/smilie_happy_008.gif">';
      //r.htmlText = '<img src="smily/smilie_happy_008.gif">';
   }
   
  
  
   function setBigDJ(no) {
      var img = dojo.byId('imgbigdj'+no);
      var div = dojo.byId('divdj'+no);
      
      img.style.visibility='visible';
      div.style.visibility='visible';
      
      for(var i=1; i<=4; i++) {
         if(i==no) continue;
         var aimg = dojo.byId('imgbigdj'+i);
         var adiv = dojo.byId('divdj'+i);
         aimg.style.visibility='hidden';
         adiv.style.visibility='hidden';
      }
   }
   
   function gbNewEntryOnClick() {
      var el = dojo.byId('gbform').elements;
      
      dojo.xhrPost({
         url: 'guestbook.php',
         load: gbNewEntryOnLoad,
         error: gbNewEntryOnError,
         preventCache: true, 
         content: { 'g':Math.random(), 'todo':'saveNewEntry', 'user': escape(el['gbuser'].value),
                    'passwort':escape(el['gbpasswort'].value),
                    'message':escape(dojo.byId('gbeditordiv').innerHTML)}
      });
   }
   
   function gbNewEntryOnError(data, ioArgs) {
      alert('es trat ein Fehler auf: '+data.message);
   }
   
   function gbNewEntryOnLoad(data, ioArgs) {
       rightContentPane.attr("content", data);
   }
   
   function insert(src) {
      //var input = document.forms['formular'].elements['eingabe'];
      //---var input = document.getElementById('divEditable'); 
      var gbeditor = dojo.byId('gbeditordiv');
      gbeditor.focus();
      /* für Internet Explorer */
      
      if(typeof gbeditor.document != 'undefined' && typeof gbeditor.document.selection != 'undefined') {
         var range = gbeditor.document.selection.createRange();
         
         //var selText = range.htmlText;
         //---range.text = aTag + selText + eTag;
         var imgText='<img src="'+src+'">';
         range.pasteHTML(imgText);
         //range.htmlText = "<B>halloooo</B>";  //'<img src="smily/smilie_happy_008.gif">';
         
         /* Anpassen der Cursorposition */
         //range = document.selection.createRange();
         //if (selText.length == 0) {
         //   range.move('character', -eTag.length);
         //}
         //else {
         //if(selText.length != 0) {
         //   range.moveStart('character', imgText.length - selText.length);      
         //}
         //range.select();
         if(!isgbsmiliesDivMinimized) gbZoomDivOnClick();
      }
      else alert('Das einfügen der Smilies funktioniert zur Zeit nur im Microsoft IE');
   }
   
   function gbZoomDivOnClick() {
      var zoomDiv = dojo.byId('gbzoomdiv');
      var gbsmiliesDiv = dojo.byId('gbsmiliesdiv');
      
      var nh=300;
      var dy=240;
     dojo.byId('gbeditordiv').focus();
      if(isgbsmiliesDivMinimized) {
         //gbRange = dojo.byId('gbeditordiv').document.selection.createRange();
      }
      else {
         nh=60;
         dy=-240;
      }
      
      var a = new Array();
      a.push(dojox.fx.wipeTo({node: "gbsmiliesdiv", duration:500, height: nh}));
      a.push(dojox.fx.slideBy({node: 'gbzoomdiv', duration:500, top: dy}));
      dojo.fx.combine(a).play();
      isgbsmiliesDivMinimized = !isgbsmiliesDivMinimized;
   }
   
   

   function isInputLeer(feld) {
      //if(dojo.byId(feld).value.replace(new RegExp('[ ]+', 'g'),'').length==0) return true;
      if(dojo.byId('djform').elements[feld].value.replace(new RegExp('[ ]+', 'g'),'').length==0) return true;
      return false;
   }
   
   function FApp(f,feld) {
      f.v += 'Feld "'+feld+'" muss ausgefüllt werden.\n';
   }
   
   function djSendenOnClick() {
      var fehler = new Object();
      fehler.v ="";
      
      if(isInputLeer('djvorname')) FApp(fehler,'Vorname');
      if(isInputLeer('djname')) FApp(fehler,'Name');
      if(isInputLeer('djstrasse')) FApp(fehler,'Strasse');
      if(isInputLeer('djplz')) FApp(fehler,'PLZ');
      if(isInputLeer('djort')) FApp(fehler,'Ort');
      if(isInputLeer('djemail')) FApp(fehler,'eMail');
      if(isInputLeer('djtelnr')) FApp(fehler,'Telefon-Nr');
      if(isInputLeer('djalter')) FApp(fehler,'Alter');
      
      var el= dojo.byId('djform').elements;
      if(!el['djtag[0]'].checked && !el['djtag[1]'].checked && !el['djtag[2]'].checked && !el['djtag[3]'].checked)
         fehler.v += '\n\nMindestens ein Tag muss ausgewählt werden.';
      
      var djstatus =dojo.byId('djform').elements['djstatus'];
      if(!djstatus[0].checked && !djstatus[1].checked && !djstatus[2].checked)
         fehler.v +='\n\nBitte auswählen: profi, semi-profi oder newcomer!';
      
      if(fehler.v.length!=0) {
          alert(fehler.v);
          return;
      }
      if(!dojo.byId('djform').elements['djagb'][0].checked) {
         alert('Für die Anmeldung müssen die Wettbewerbsbedingungen gelesen und akzeptiert werden.');
         return;
      }
      
      dojo.xhrPost({
         url: 'djwettbewerb.php',
         /*multipart:true,*/
         load: djSendenOnLoad,
         error: djSendenOnError,
         preventCache: true,
         form: dojo.byId('djform'),
         //contentType: 'multipart/form-data',
         content: { 'g':Math.random(), 'todo': 'newdj' }
         /*content: { 'g':Math.random(), 'todo':'saveNewEntry', 'user': escape(dojo.byId('gbuser').value),
                    'email':escape(dojo.byId('gbemail').value), 'passwort':escape(dojo.byId('gbpasswort').value),
                    'message':escape(dojo.byId('gbeditordiv').innerHTML)}
                    */
      });
   }
   
   function djSendenOnError(data, ioArgs) {
      alert('es trat ein Fehler auf: '+data.message);
   }
   
   function djSendenOnLoad(data, ioArgs) {
      
       rightContentPane.attr("content", data);
       //rightContentPane.innerHTML = data;
   }
   
   function djAGBvisible(visible) {
     var v='hidden';
     if(visible) v='visible';
     dojo.byId('djagbdiv').style.visibility=v;
     dojo.byId('djagbclosediv').style.visibility=v;
     
      //var djagb = new dijit.Dialog({href:'djagb.html', width:'600px'}, "djagbdialog");
      //djagb.style.backgroundColor = "red";
      //djagb.show();
   }
   