// JavaScript Document

//---------------------------------------------------------------------
// Javascript Bildwechsler, Diashow
// Script copyright 2009 by Johanna Bindgen
// jo-bi@t-online.de
// Verwendung nur mit Zustimmung der Autorin
//---------------------------------------------------------------------

var resize_on         = 0;
window.onresize=resize;

var Millisec     = 40; //Timer Zeitintervall

var Max            = 100;
var Nenner         = 100;

var setgdliburl  = "setgdliburl";
var globPath     = "dummy";
var globWidth    = 0;
var globHeight   = 0;
var globText     = "x";

var merkeWidth   =0;
var merkeHeight  =0;


var BoZielBreite     = 0;
var BoZielMarginleft = 0;
var BoZielHoehe      = 0;
var BoZielMargintop  = 0;

var merkeBoZielBreite     = 0;
var merkeBoZielMarginleft = 0;
var merkeBoZielHoehe      = 0;
var merkeBoZielMargintop  = 0;

var ChBreite         =0;
var ChMarginleft     =0;
var ChDelta_x        =0;

var ChHoehe          =0;
var ChMargintop      =0;
var ChDelta_y        =0;	

var oneStepX         =0;
var oneStepY         =0;
var Rand             =1;//innerer Rahmen
var Rand2            =6;//äusserer Rahmen
var infoDivTxHoehe   =68;

var Rand2unten       =Rand2+infoDivTxHoehe;//Platz für Untertitel

var diashow_schliessen_bottom_dy=-16;
var text_bottom_dy=6;
//var RandBild         =3;

var bild_overlay     = "bild_overlay";

var glob_bildstore_aktuell       =0;
//var merke_glob_bildstore_aktuell =-1;

//------------ abdunkeln ; count_blende()------------------------
var infoDivBl      = "infoDivBl";  //id in html
var ZaehlerBlStart = 80;  //Beginn des Zaehlers
var ZaehlerBl      = ZaehlerBlStart;
var ZaehlerBlMax   = 90;
var DeltaBl        = 5; // Schrittweite
var aktivBl;




//------------ Event Hintergrund 2 ; Bg()------------------------
var infoDivBg2      = "infoDivBg2";  //id in html
//------------ Event Hintergrund ; Bg()------------------------
var infoDivBg      = "infoDivBg";  //id in html
var ZaehlerBgStart = 80;  //Beginn des Zaehlers
var ZaehlerBg      = ZaehlerBgStart;
var ZaehlerBgMax   = 100;
var DeltaBgFirst   = 5;
var DeltaBg        = DeltaBgFirst; // Schrittweite
var aktivBg;

//------------ Event Content ; OverlayContent()---bild---------------------
var infoDivCo      = "infoDivCo"; //id in html
var ZaehlerCoStart = 40;  //Beginn des Zaehlers
var ZaehlerCo      = ZaehlerCoStart;
var ZaehlerCoMax   = 100;
var DeltaCo        = 10; // Schrittweite
var aktivCo;


//------------ Event Content ; OverlayContent()--text zum bild-----------------
var infoDivTx      = "infoDivTx"; //id in html
var ZaehlerTxStart = 50;  //Beginn des Zaehlers
var ZaehlerTx      = ZaehlerTxStart;
var ZaehlerTxMax   = 60;
var DeltaTx        = 10; // Schrittweite
//------------ Event Content ; -text zum bild- untertitle----------------
var infoDivTxBottom= "infoDivTxBottom"; //id in html

//------------ Event Exit ; ExitOverlay()------------------------
var infoDivEx      = "infoDivEx"; //id in html
var ZaehlerExStart = 100;  //Beginn des Zaehlers
var ZaehlerEx      = ZaehlerExStart;
var ZaehlerExMax   = 40;
var DeltaEx        = 20; // Schrittweite



//------------ Event Exit ; ExitOverlayLastPic()------------------------
//var infoDivEx             = "infoDivEx"; //id in html
var ZaehlerExLastPicStart = 100;  //Beginn des Zaehlers
var ZaehlerExLastPic      = ZaehlerExLastPicStart;
var ZaehlerExLastPicMax   = 40;
var DeltaExLastPic        = 20; // Schrittweite


//-----------------------------------
var ZaehlerNoStart = 0;  //Beginn des Zaehlers
var ZaehlerNo      = ZaehlerNoStart;
var ZaehlerNoMax   = 100;
var DeltaNo        = 20; // Schrittweite


var rectFaderFactor=3000;


var move_highlight_picture=0;
var move_highlight_picture_soll=0;

var korrektur_counter=0;
var aktivkorrektur;
var korrektur_running=0;
var continue_korr=0;

var stepper_w=0;

var scroll_update_counter=0;
var aktivScrollUpdate_timer;

//------------ einfacher Zähler()------------------------
var ZaehlerNStart = 0;  //Beginn des Zaehlers
var ZaehlerN      = ZaehlerNStart;
var ZaehlerNMax   = 100;
var DeltaN        = 10; // Schrittweite

var infospanText       = "infospanText";
var infospanTextBottom = "infospanTextBottom";

var InitFensterBreite  = 0;
var InitFensterHoehe   = 0;

var FensterBreite  = 0;
var FensterHoehe   = 0;
var Zoom           = 100;

var MaxBildRandx    = 20;
var MaxBildRandy    = 50;

var bild_original_width = 0;
var bild_original_height= 0;
var Untertitel     = "";

var enable_bild_overlay   =0;
//var glob_part_of_diashow  =7;

var ibn;       //Reset Timer Diashow
var diaTime   =3; //wird von php gesetzt
var autoplay  =0;
var forward   =0;
var backward  =0;


var busy                          =0;
var autoplay_after_first_picture  =1;

var globPageTitle;
var busy_exit_overlayLastPic=0;

var glob_diashow_nr;
var glob_diashow_name;
var aktivExLastPic;
var aktivEx;
var aktivCh;
var ds;

//var merke_ds;


         
//--------------------------------

if(checkBrowserName('MSIE')){
var browser='MSIE';
}




function init()
{
}
//------------------------------
function get_screen_width()
{
  //return window.innerWidth; dat get so nich bei aaln brausern
  return  xClientWidth(); // dat is besser
}

//------------------------------
function get_screen_height()
{
  //return window.innerHeight;
  return xClientHeight();
}
//------------------------------

function resize()
{
if (!enable_bild_overlay){return;}
resize_on=1;
move_highlight_picture=0;
init_fader(ds,glob_bildstore_aktuell);
}



//--------------------------------------
function get_max_zoom(width,height)
{
var ZoomY;
var ZoomX;
             ZoomY=100;
             if(height>(InitFensterHoehe-MaxBildRandy*2))
             {
             ZoomY=(InitFensterHoehe-MaxBildRandy*2)/height*100;
             }
             ZoomX=100;
             if(width>(InitFensterBreite-MaxBildRandx*2))
             {
             ZoomX=(InitFensterBreite-MaxBildRandx*2)/width*100;
             }


return   Math.min(ZoomX,ZoomY);
}

function stop_dia()
{
clearInterval(ibn);
autoplay=0;
backward=0;
forward=0;

}
//------------------------------------------------------------------------
function set_dia_time(setdiaTime)
{
//if (glob_part_of_diashow==0){return;}
diashow_settime_unvisible();
diaTime=setdiaTime;
status="";
highlight_diashow_buttons(diaTime,status);
if (autoplay==1 && forward==1){clearInterval(ibn);ibn=setInterval("diashow_next()",diaTime*diaTimeFaktor);}

}
//------------------------------------------------------------------------
function dec_bild_nr()
{
diashow_stop();
glob_bildstore_aktuell--;
if (glob_bildstore_aktuell<0){glob_bildstore_aktuell=pics_je_diashow[ds]-1;}
stepper_w=0;
other_picture(glob_bildstore_aktuell);
}
//-----------------------------------------------------------------------
function inc_bild_nr()
{
diashow_stop();
glob_bildstore_aktuell++;
if (glob_bildstore_aktuell>pics_je_diashow[ds]-1){glob_bildstore_aktuell=0;}
other_picture(glob_bildstore_aktuell);
}
//-----------------------------------------------------------------------
function diashow_back()
{
if (autoplay==1 ){diashow_stop();}
glob_bildstore_aktuell--;
if (glob_bildstore_aktuell<0){glob_bildstore_aktuell=pics_je_diashow[ds]-1;}
stepper_w=0;
other_picture(glob_bildstore_aktuell);
}
//-----------------------------------------------------------------------
function diashow_next()
{
if (pics_je_diashow[ds]<2)
{exit_overlay();}
else
{
glob_bildstore_aktuell++;
if (glob_bildstore_aktuell>pics_je_diashow[ds]-1){glob_bildstore_aktuell=0;}
stepper_w=0;
other_picture(glob_bildstore_aktuell);
}
}
//-----------------------------------------------------------------------
function diashow_go(setdiaTime)
{
//if (glob_part_of_diashow==0){return;}
if (diaTime<diaTimeMin || diaTime>diaTimeMax){diaTime=setdiaTime;}
   
   
if (autoplay==1 ){
        clearInterval(ibn);
                          
}

                          glob_bildstore_aktuell=0;
                          
                          stepper_w=0;
                          autoplay=1;
                          forward=1;
                          ibn=setInterval("diashow_next()",diaTime*diaTimeFaktor);
                          document.getElementById("id_cl_infoDivEx_bi_stepper").style.display="block";                     
                          
        highlight_diashow_buttons(diaTime,"diashow_go");
        other_picture(glob_bildstore_aktuell);


}

//------------------------------------------------------------------------
function diashow_stop()
{
if (autoplay==0 ){//Cont
  stepper_w=0;
  autoplay=1;
  forward=1;
  ibn=setInterval("diashow_next()",diaTime*diaTimeFaktor);
  document.getElementById("id_cl_infoDivEx_bi_stepper").style.display="block";     
  highlight_diashow_buttons(diaTime,"diashow_go");
  other_picture(glob_bildstore_aktuell);
}
else
{ //stop/pause
  diashow_end();
}
}
//--------------------------
function diashow_end()
{
  highlight_diashow_buttons(0,"diashow_stop");
  clearInterval(ibn);
  autoplay=0;
  backward=0;
  forward=0;
  document.getElementById("id_cl_infoDivEx_bi_stepper").style.display="none";

}



//------------------------------------------------------------------------
function highlight_diashow_buttons(diaTime,status)
{
var i;



if (diaTime!=0 && enable_diaTime_fast_slow==1){
  i=diaTimeMin;while(i<=diaTimeMax)
  {
  document.getElementById("id_dia_time_nr_"+i).className=diaTime_low;
  i=i+diaTimeStep;
  }
  document.getElementById("id_dia_time_nr_"+diaTime).className=diaTime_high;
}

if (status=="diashow_go")
{
document.getElementById("id_cl_infoDivEx_bi_bg").className="cl_infoDivEx_bi_start";
document.getElementById("id_small_play_go").style.display="none";
document.getElementById("id_small_play_stop").style.display="inline";
}
if (status=="diashow_stop")
{
document.getElementById("id_cl_infoDivEx_bi_bg").className="cl_infoDivEx_bi_stop";
document.getElementById("id_small_play_go").style.display="inline";
document.getElementById("id_small_play_stop").style.display="none";
}


//document.getElementById("id_cl_infoDivEx_bi_clip").className="abc";
//document.getElementById("id_cl_infoDivEx_bi_bg").style.backgroundColor="green";

if(status!=""){
//document.getElementById("diashow_go").className=play_low;
//document.getElementById("diashow_stop").className=play_low;
//document.getElementById(status).className=play_high;
}

}
//-------------------------------------------
function diashow_settime_visible()
{
if (document.getElementById("id_small_play_settime").style.display!="inline")
{document.getElementById("id_small_play_settime").style.display="inline";}
else
{
diashow_settime_unvisible();
}
}
//-------------------------------------------
function diashow_settime_unvisible()
{
document.getElementById("id_small_play_settime").style.display="none";
}

//-------------------------------------------------------------------------
function get_picture_data(i)
{    
               
             
}
//---------------------------
function change_to_other_diashow(dsnr,bnr)
{

diashow_end();
finish_diashow_reset_values();


init_fader(dsnr,bnr);
}

//--------------------------------------------------------- 
function init_fader(dsnr,bnr)
{

var x;
var w;
var height;
var width;
var i;

ds=dsnr;
glob_bildstore_aktuell=bnr;




           i=glob_bildstore_aktuell;
             globPath=bildstore[ds][i][0];
             globWidth=bildstore[ds][i][1];
             globHeight=bildstore[ds][i][2];
             globText=bildstore[ds][i][3];
             globPageTitle=bildstore[ds][i][4];
             glob_diashow_nr=bildstore[ds][i][5];
             glob_diashow_name=bildstore[ds][i][6];


             
        

diaTime=diaTimeStart;

move_highlight_picture=0;



if (single_bild_modus[ds]==1)
{
PreviewHeight=single_bild_modus_PreviewHeight;
document.getElementById("id_diashow_scliessen_weiter").style.display="none";
document.getElementById("id_diashow_scliessen_zurueck").style.display="none";
}
else
{
PreviewHeight=multi_bild_modus_PreviewHeight;
document.getElementById("id_diashow_scliessen_weiter").style.display="inline";
document.getElementById("id_diashow_scliessen_zurueck").style.display="inline";

}


InitFensterHoehe  = get_screen_height()-PreviewHeight-infoDivTxHoehe;//window.innerHeight;
InitFensterBreite = get_screen_width();//window.innerWidth;



//Diashow name anzeigen
if (diashow_counter>0){
i=0;while(i<=diashow_counter && pics_je_diashow[i]>0)
{
document.getElementById("id_ds_name_"+i).className="diashow_name_low";
i++;
}
document.getElementById("id_ds_name_"+ds).className="diashow_name_high";
}


//Bilder je Diashow aktivieren
i=0;while(i<=diashow_counter)
{
document.getElementById("id_ds_"+i).style.display="none";
i++;
}
document.getElementById("id_ds_"+ds).style.display="block";



w=(pics_je_diashow[ds])*width_highlight_picture;
document.getElementById("id_cl_infoDivEx_bi").style.width=w+"px";



if (enable_stepper){
x=(pics_je_diashow[ds])*width_highlight_picture/2-move_highlight_picture;
document.getElementById("id_cl_infoDivEx_bi_stepper").style.marginLeft=-x+"px";
}

             highlight_diashow_buttons(diaTime,"diashow_stop");
             autoplay_after_first_picture=1;
           
             enable_bild_overlay=1;            
 
             Untertitel=globText;

             Zoom=get_max_zoom(globWidth,globHeight);

             height=globHeight/100*Zoom;
             width=globWidth/100*Zoom;

              
              document.getElementById(setgdliburl).src = globPath;


              BoZielBreite=width;
              BoZielMarginleft=width/2;

              BoZielHoehe=height;
              BoZielMargintop=height/2;


              document.getElementById(infoDivEx).style.height = PreviewHeight+'px';
              document.getElementById(bild_overlay).style.display="block";
              document.getElementById(infoDivBl).style.display="block";
              document.getElementById(infoDivCo).style.display="none";
              document.getElementById(infoDivEx).style.display="none";
              document.getElementById(infoDivBg2).style.display="none";
              document.getElementById(infoDivBg).style.display="none";
              document.getElementById(infoDivTx).style.display="none";
              document.getElementById(infoDivTxBottom).style.display="none";
              document.getElementById("id_diashow_schliessen_bottom").style.display="none";

document.getElementById("id_diashow_big_text_next").style.display="none";
document.getElementById("id_diashow_exit").style.display="none";


              document.getElementById(setgdliburl).style.width  = (BoZielBreite)+'px';
              document.getElementById(setgdliburl).style.height = (BoZielHoehe)+'px';


             
              document.getElementById(setgdliburl).src = globPath;
              
              if (korrektur_running==0){aktivkorrektur = setInterval("korr()",korrTimerMillisec);korrektur_running=1;}

              count_blende();
        




}

//-----------------------------------------------------
function count_blende()//Website Hintergrund
{
var R;
var Ralpha;
var W;
var Ml;
var H;
var Mt;
if (enable_transparent_background>0)
{//mit Timer


  R = ZaehlerBl/Nenner;
  Ralpha = R*100;



     if (ZaehlerBl <= ZaehlerBlMax) {

      	 aktivBl = setTimeout("count_blende()", Millisec);
         opacity(infoDivBl,R);
         ZaehlerBl += DeltaBl;
    }
    else
    {
	       clearTimeout(aktivBl);
         overlay_content_highlight_picture();
         DeltaBg = DeltaBgFirst;
         bg();
    }
}
else
{//ohne Timer
         overlay_content_highlight_picture();
         DeltaBg = DeltaBgFirst;
         bg();

}



}

//----------------------------------------------------

function bg()//Bildhintergrund 1 und 2
{
var R;
var Ralpha;
var W;
var Ml;
var H;
var Mt;

 R = ZaehlerBg/Nenner;
  Ralpha = R*100;
  
 if (!enable_soft_change || resize_on==1 )
 {

  R = 1;//ZaehlerBgMax/Nenner;
  Ralpha = R*100;
                document.getElementById(infoDivBg2).style.display="block";
                document.getElementById(infoDivBg).style.display="block";
                
                W=Math.min(BoZielBreite,(BoZielBreite/Max)*Ralpha);
                Ml=Math.max(-BoZielMarginleft,-(BoZielMarginleft/Max)*Ralpha);
  
                H=Math.min(BoZielHoehe,(BoZielHoehe/Max)*Ralpha);
                Mt=Math.max(-BoZielMargintop,-(BoZielMargintop/Max)*Ralpha);

                document.getElementById(infoDivBg2).style.marginLeft =(Ml-Rand-Rand2)+'px';
                document.getElementById(infoDivBg2).style.width = (W+Rand*2+Rand2*2)+'px';
                document.getElementById(infoDivBg2).style.marginTop = (Mt-Rand-Rand2)+PreviewHeight/2-infoDivTxHoehe/2+'px';
                document.getElementById(infoDivBg2).style.height = (H+Rand*2+Rand2+Rand2unten)+'px';

                document.getElementById(infoDivBg).style.marginLeft = (Ml-Rand)+'px';
                document.getElementById(infoDivBg).style.width = (W+Rand*2)+'px';
                document.getElementById(infoDivBg).style.marginTop = (Mt-Rand)+PreviewHeight/2-infoDivTxHoehe/2+'px';
                document.getElementById(infoDivBg).style.height = (H+Rand*2)+'px';
                DeltaBg = DeltaBgFirst;
                ZaehlerBg=ZaehlerBgStart;
                overlay_content_text();
  
  
 }
 else
 {

     if (ZaehlerBg <= ZaehlerBgMax) {

           aktivBg = setTimeout("bg()", Millisec);
           if (ZaehlerBg==ZaehlerBgStart)
             {
                document.getElementById(infoDivBg2).style.display="block";
                document.getElementById(infoDivBg).style.display="block";
                document.getElementById(infoDivCo).style.display="none";
                
             }

                W=Math.min(BoZielBreite,(BoZielBreite/Max)*Ralpha);
                Ml=Math.max(-BoZielMarginleft,-(BoZielMarginleft/Max)*Ralpha);
  
                H=Math.min(BoZielHoehe,(BoZielHoehe/Max)*Ralpha);
                Mt=Math.max(-BoZielMargintop,-(BoZielMargintop/Max)*Ralpha);

                document.getElementById(infoDivBg2).style.marginLeft = (Ml-Rand-Rand2)+'px';
                document.getElementById(infoDivBg2).style.width = (W+Rand*2+Rand2*2)+'px';
                document.getElementById(infoDivBg2).style.marginTop = (Mt-Rand-Rand2)+PreviewHeight/2-infoDivTxHoehe/2+'px';
                document.getElementById(infoDivBg2).style.height = (H+Rand*2+Rand2+Rand2unten)+'px';

                document.getElementById(infoDivBg).style.marginLeft = (Ml-Rand)+'px';
                document.getElementById(infoDivBg).style.width = (W+Rand*2)+'px';
                document.getElementById(infoDivBg).style.marginTop = (Mt-Rand)+PreviewHeight/2-infoDivTxHoehe/2+'px';
                document.getElementById(infoDivBg).style.height = (H+Rand*2)+'px';

            ZaehlerBg += DeltaBg;
         
    }
    else
    {

         
	       clearTimeout(aktivBg);
         DeltaBg = DeltaBgFirst;
         ZaehlerBg=ZaehlerBgStart;
         overlay_content_text();
    }


 }

}


//----------------------------------------------------
function overlay_content_text()
{

var W;
var Ml;
var H;
var Mt;


 

  
         if (single_bild_modus[ds]==0){  
         //seitentitel
         document.getElementById("id_cl_infoDivEx_ue").style.display="block";
         document.getElementById("infospanPageText").innerHTML=glob_diashow_name;//globPageTitle ;
         //bild-titel
         //document.getElementById(infoDivTx).style.display="block";
         //document.getElementById(infospanText).innerHTML=Untertitel ;
         //untertitel
         document.getElementById(infoDivTxBottom).style.display="block";
         document.getElementById(infospanTextBottom).innerHTML=Untertitel ;
         
         document.getElementById("id_single_text").style.display="none";
         document.getElementById(infoDivEx).style.display="block";
         
         

         }
         else
         {
         // Single bild modus 
         document.getElementById("id_single_text").style.display="none";// immer weg ! vorher block
         //seitentitel
         document.getElementById("id_single_text1").style.display="block";
         document.getElementById("id_single_text1").innerHTML=glob_diashow_name;//globPageTitle;
         //bild-titel
         //document.getElementById("id_single_text2").style.display="block";
         //document.getElementById("id_single_text2").innerHTML= Untertitel;
         
         document.getElementById(infoDivTxBottom).style.display="block";
         document.getElementById(infospanTextBottom).innerHTML=Untertitel ;
         }

    document.getElementById("id_diashow_schliessen_bottom").style.display = "block";
    document.getElementById("id_diashow_exit").style.display="block";
    
    document.getElementById("id_diashow_big_text_next").style.display="none"; 
    document.getElementById("id_diashow_big_text_back").style.display="block"; 
        
    overlay_content();


}
//----------------------------------------------------
function overlay_content_highlight_picture()
{
var i;
i=0;while(i<pics_je_diashow[ds])
{
   document.getElementById("id_bildstore_img_rahmen_inner_"+ds+"_"+i).className=diashow_bild_low;
i++;
}

document.getElementById("id_bildstore_img_rahmen_inner_"+ds+"_"+glob_bildstore_aktuell).className=diashow_bild_high; 

         
}

//-----------------------------------
function scroll_right_left(wert)
{
//diashow_end();
glob_bildstore_aktuell=glob_bildstore_aktuell+wert;

if (glob_bildstore_aktuell>pics_je_diashow[ds]-1){glob_bildstore_aktuell=pics_je_diashow[ds]-1;}
if (glob_bildstore_aktuell<0){glob_bildstore_aktuell=0;}


overlay_content_highlight_picture();

if(scroll_update_counter==0){
      
          
          aktivScrollUpdate_timer=window.setInterval("update_counter()",scroll_update_timer);
          
          }
if (scroll_update_counter>1){scroll_update_counter=1;}
}
//-----------------------------------
function click_to_other_picture(dsnr,bnr)
{

glob_bildstore_aktuell=bnr;
ds=dsnr;

overlay_content_highlight_picture();             

       diashow_end();


other_picture(glob_bildstore_aktuell);


}
//-----------------------
function update_counter()
{
scroll_update_counter+=1;
         
         
      
if (scroll_update_counter>scroll_update_counter_max)
{
  
   window.clearInterval(aktivScrollUpdate_timer);scroll_update_counter=0;
 //hilfe
 //document.getElementById("id_cl_infoDivEx_ue").style.display="block";
 //document.getElementById("infospanPageText").innerHTML="timer deaktiviert" ;
 
 
   scroll_update_counter=0;
  other_picture(glob_bildstore_aktuell);
}
}
//---------------------------------------------------------------------------
function korr() // Bildschirm schieben, damit aktives Bild zu sehen ist
{
var x;
var xa;
var xhigh;
var stepper_wmax;
var stepper_wb;     
if (single_bild_modus[ds]==1){return;} 

//x=(1+globBild_store_max)*width_highlight_picture/2;
//pics_of_this_diashow
x=(pics_je_diashow[ds])*width_highlight_picture/2;
xa=(0+glob_bildstore_aktuell)*width_highlight_picture;         
xhigh=InitFensterBreite/2-x+xa;



//if ((1+globBild_store_max)*width_highlight_picture>InitFensterBreite-40)
//pics_of_this_diashow
if ((pics_je_diashow[ds])*width_highlight_picture>InitFensterBreite-40)
{
//--     


 

       
       //hartes waagerechtes scrolling, nur, wenn Bildreihe breiter als Fenster
         if (xhigh+move_highlight_picture<0+10)
         { 
           while(xhigh+move_highlight_picture<0+200)
           {
            move_highlight_picture+=width_highlight_picture;
           }  
           korrektur_counter=0;
         }
       
        
//--  
   if (xhigh+move_highlight_picture>InitFensterBreite-width_highlight_picture-10)
   {
       while(xhigh+move_highlight_picture>InitFensterBreite-width_highlight_picture-InitFensterBreite/3)
       {
       move_highlight_picture-=width_highlight_picture;
       }
       korrektur_counter=0;
   }
 
//--
}

if (single_bild_modus[ds]==0)
{
        //x=(1+globBild_store_max)*width_highlight_picture/2-move_highlight_picture;
        x=(pics_je_diashow[ds])*width_highlight_picture/2-move_highlight_picture;
        
        document.getElementById("id_cl_infoDivEx_bi").style.marginLeft=-x+"px";  
}

korrektur_counter++;

 
         //hilfe timercontrol  
         //document.getElementById(infoDivTx).style.display="block";
         //document.getElementById(infospanText).innerHTML= "Stepper="+korrektur_counter+" scroll_update_counter="+scroll_update_counter; 
 
if (single_bild_modus[ds]==0 && enable_stepper && autoplay==1){
 
  //stepper_wmax=(1+globBild_store_max)*width_highlight_picture;
  stepper_wmax=(pics_je_diashow[ds])*width_highlight_picture;
  stepper_wb=glob_bildstore_aktuell*width_highlight_picture;
  stepper_w+=width_highlight_picture/(diaTimeFaktor/korrTimerMillisec)/diaTime;
  if (stepper_w>stepper_wmax){stepper_w=0;}
   document.getElementById("id_cl_infoDivEx_bi_stepper").style.display="block";
  document.getElementById("id_cl_infoDivEx_bi_stepper").style.marginLeft=-x+(stepper_wb+stepper_w)+"px";
}

if (0){
document.getElementById(infoDivTx).style.display="block";
document.getElementById(infospanText).innerHTML= "diaTime="+diaTime+" (diaTimeFaktor/korrTimerMillisec)="+(diaTimeFaktor/korrTimerMillisec);     
}

}



//----------------------------------------------------
function overlay_content()
{
var R;
var Ralpha;
var W;
var Ml;
var H;
var Mt;
//var diashow_schliessen_bottom_dy;

 if (!enable_soft_change || resize_on==1)
 {
     R = 1;//ZaehlerCo/Nenner;
     Ralpha =R*100;
                document.getElementById(infoDivCo).style.display="block";
                document.getElementById(setgdliburl).style.display="block";
                document.getElementById(setgdliburl).style.width  = BoZielBreite+'px';
	              document.getElementById(setgdliburl).style.height = BoZielHoehe+'px';
	
                W=BoZielBreite;
                Ml=-BoZielMarginleft;
                H=BoZielHoehe;
                Mt=-BoZielMargintop;

                document.getElementById(infoDivCo).style.marginLeft = Ml+'px';
                document.getElementById(infoDivCo).style.width = W+'px';
                document.getElementById(infoDivCo).style.marginTop = Mt+PreviewHeight/2-infoDivTxHoehe/2+'px';
                document.getElementById(infoDivCo).style.height = H+'px';
                
                document.getElementById(infoDivTxBottom).style.marginLeft =Ml+'px';
                document.getElementById(infoDivTxBottom).style.width =W+'px';
                document.getElementById(infoDivTxBottom).style.marginTop =text_bottom_dy+BoZielMargintop+PreviewHeight/2-infoDivTxHoehe/2+'px';
                
        //        document.getElementById("id_diashow_schliessen_bottom").style.marginTop = infoDivTxHoehe+diashow_schliessen_bottom_dy+BoZielMargintop+PreviewHeight/2-infoDivTxHoehe/2+'px';
 }
 else
 {
 
     R =ZaehlerCo/Nenner;
     Ralpha =R*100;




    if (ZaehlerCo <= ZaehlerCoMax) {

     	 aktivCo = setTimeout("overlay_content()", Millisec);
     	
          if (ZaehlerCo == ZaehlerCoStart)
              {

               document.getElementById(infoDivCo).style.display="block";
               document.getElementById(setgdliburl).style.display="block";
               document.getElementById(setgdliburl).style.width  = BoZielBreite+'px';
	             document.getElementById(setgdliburl).style.height = BoZielHoehe+'px';
	
                W=BoZielBreite;
                Ml=-BoZielMarginleft;
                H=BoZielHoehe;
                Mt=-BoZielMargintop;

                document.getElementById(infoDivCo).style.marginLeft = Ml+'px';
                document.getElementById(infoDivCo).style.width = W+'px';
                document.getElementById(infoDivCo).style.marginTop = Mt+PreviewHeight/2-infoDivTxHoehe/2+'px';
                document.getElementById(infoDivCo).style.height = H+'px';

                document.getElementById(infoDivTxBottom).style.marginLeft =Ml+'px';
                document.getElementById(infoDivTxBottom).style.width =W+'px';
                document.getElementById(infoDivTxBottom).style.marginTop =text_bottom_dy+BoZielMargintop+PreviewHeight/2-infoDivTxHoehe/2+'px';
               

              }

              opacity(infoDivCo,R);

          ZaehlerCo += DeltaCo;
    }
    else
    {

	 clearTimeout(aktivCo);
      
    }
         



 }
         resize_on=0;
         merkeBoZielBreite=BoZielBreite;
	       merkeBoZielMarginleft=BoZielMarginleft;
         merkeBoZielHoehe=BoZielHoehe;
         merkeBoZielMargintop=BoZielMargintop;
         if (single_bild_modus[ds]==0){
           document.getElementById(infoDivEx).style.display="block";
           
           if (autoplay_after_first_picture==1 && enable_diashow_autostart==1){
              autoplay_after_first_picture=0;
              diashow_go(diaTime);
              autoplay=1;
           }
           
         }
         
         
         
         if (enable_links_to_other_diashows && diashow_counter>0){
           document.getElementById("id_link_to_other_diashows").style.display = "block";
         }      
                W=BoZielBreite;
                Ml=-BoZielMarginleft;
                H=BoZielHoehe;
                Mt=-BoZielMargintop;

                document.getElementById(infoDivCo).style.marginLeft = Ml+'px';
                document.getElementById(infoDivCo).style.width = W+'px';
                document.getElementById(infoDivCo).style.marginTop = Mt+PreviewHeight/2-infoDivTxHoehe/2+'px';
                document.getElementById(infoDivCo).style.height = H+'px';
                //document.getElementById("id_diashow_schliessen_bottom").style.marginTop = Mt+PreviewHeight/2-infoDivTxHoehe/2+'px';
                document.getElementById("id_diashow_schliessen_bottom").style.marginTop = infoDivTxHoehe+diashow_schliessen_bottom_dy+BoZielMargintop+PreviewHeight/2-infoDivTxHoehe/2+'px';
        
        document.getElementById("id_diashow_exit").style.marginLeft = Ml+W+20+'px';
        document.getElementById("id_diashow_exit").style.marginTop = Mt+PreviewHeight/2-infoDivTxHoehe/2+'px';

        //document.getElementById("id_diashow_exit").style.marginLeft = Ml+W/2+'px';
        //document.getElementById("id_diashow_exit").style.marginTop = Mt-30+'px';
        
        document.getElementById("id_diashow_big_text_next").style.marginLeft = Ml+W+20+'px';
        document.getElementById("id_diashow_big_text_next").style.marginTop = Mt+30+PreviewHeight/2-infoDivTxHoehe/2+'px';
        
        document.getElementById("id_diashow_big_text_next").style.marginLeft = 0+'px';
        document.getElementById("id_diashow_big_text_next").style.marginTop = PreviewHeight+'px';
        



        document.getElementById("id_diashow_big_text_back").style.marginLeft = Ml-40+'px';
        document.getElementById("id_diashow_big_text_back").style.marginTop = Mt+30+PreviewHeight/2-infoDivTxHoehe/2+'px';
        
        
         document.getElementById(infoDivCo).style.display="block";
         
  if (continue_korr==1 && korrektur_running==0){
        continue_korr=0;
        aktivkorrektur = setInterval("korr()",korrTimerMillisec);
        korrektur_running=1;
        }
       


}
//---------------------------------------------------------------------------
function nothing()
{

    if (ZaehlerNo <= ZaehlerNoMax) {

     	 aktivNo = setTimeout("nothing()", Millisec);
         ZaehlerNo += DeltaNo;
    } else {

	 clearTimeout(aktivNo);
	 alert(ZaehlerNo);
         ZaehlerNo=ZaehlerNoStart;
    }



}

//---------------------------------------------------------------------------
function exit_overlay()
{
var R;
var Ralpha;
var W;
var Ml;
var H;
var Mt;

clearInterval(ibn);
if (korrektur_running>0){clearInterval(aktivkorrektur);korrektur_running=0;}

//clearTimeout(aktivEx);
//clearTimeout(aktivCo);
//clearTimeout(aktivBl);



autoplay=0;
backward=0;
forward=0;
if  (enable_soft_change)
{//mit Timer
  R = ZaehlerEx/Nenner;
  Ralpha = R*100;




  if (ZaehlerEx >= ZaehlerExMax) {
         
              opacity(infoDivCo,R);
              ZaehlerEx += -DeltaEx;
              aktivEx = setTimeout("exit_overlay()", Millisec);
  }
  else
  {
              clearTimeout(aktivEx);
	            finish_diashow_reset_values();
  }
}
else
{//ohne Timer
finish_diashow_reset_values();
}    
    
}
//---------------------------------------------------------------------------
function finish_diashow_reset_values()
{
clearTimeout(aktivBl);

clearTimeout(aktivBg);

clearInterval(ibn);

clearInterval(aktivkorrektur);
korrektur_running=0;

clearInterval(aktivScrollUpdate_timer);


              document.getElementById(infoDivBl).style.display="none";
              document.getElementById(infoDivBg2).style.display="none";
              document.getElementById(infoDivBg).style.display="none";
              document.getElementById(infoDivCo).style.display="none";
              document.getElementById(infoDivEx).style.display="none";
              document.getElementById(infoDivTx).style.display="none";
              document.getElementById(infoDivTxBottom).style.display="none";
              document.getElementById("id_diashow_schliessen_bottom").style.display="none";
              
              document.getElementById(infospanText).innerHTML="";
              document.getElementById(infospanTextBottom).innerHTML="";
              
              
              document.getElementById("id_cl_infoDivEx_ue").style.display="none";
              
              document.getElementById("id_single_text").style.display="none";
              document.getElementById("id_single_text1").style.display="none";
              document.getElementById("id_single_text2").style.display="none";
              document.getElementById("id_single_text2").innerHTML="";
              document.getElementById("id_diashow_exit").style.display="none";
              document.getElementById("id_diashow_big_text_next").style.display="none";
              document.getElementById("id_diashow_big_text_back").style.display="none";
              
              document.getElementById("id_diashow_schliessen_bottom").style.display="none";

              if (diashow_counter>0){
              document.getElementById("id_link_to_other_diashows").style.display = "none";
              }
              
              
              document.getElementById(setgdliburl).src = "";
             
              ZaehlerBl      = ZaehlerBlStart;
              ZaehlerBg      = ZaehlerBgStart;
              ZaehlerCo      = ZaehlerCoStart;
              ZaehlerEx      = ZaehlerExStart;
              ZaehlerExLastPic= ZaehlerExLastPicStart;
              ZaehlerTx      = ZaehlerTxStart;
              enable_bild_overlay=0;
}

//------------------------------------------------------------------------
function other_picture(bnr)
{
var i;
glob_bildstore_aktuell=bnr;

get_picture_data(glob_bildstore_aktuell);
i=glob_bildstore_aktuell;
             globPath=bildstore[ds][i][0];
             globWidth=bildstore[ds][i][1];
             globHeight=bildstore[ds][i][2];
             globText=bildstore[ds][i][3];
             globPageTitle=bildstore[ds][i][4];
             glob_diashow_nr=bildstore[ds][i][5];
             glob_diashow_name=bildstore[ds][i][6];


document.getElementById(infoDivTx).style.display="none";
document.getElementById(infoDivTxBottom).style.display="none";
document.getElementById("id_diashow_schliessen_bottom").style.display = "none";

document.getElementById("id_diashow_big_text_next").style.display="none";
document.getElementById("id_diashow_exit").style.display="none";


korrektur_running=0;
clearInterval(aktivkorrektur);
continue_korr=1;

overlay_content_highlight_picture();
 

if (busy_exit_overlayLastPic==0){
  document.getElementById("id_cl_infoDivEx_bi_stepper").style.display="none";  
  exit_overlayLastPic();
  }


}


//------------------------------------------------------------------------
function exit_overlayLastPic()
{
var R;
var Ralpha;
var W;
var Ml;
var H;
var Mt;

busy_exit_overlayLastPic=1;

if (enable_soft_change)
{
//mit Timer
  R = ZaehlerExLastPic/Nenner;
  Ralpha = R*100;

  if (ZaehlerExLastPic >= ZaehlerExLastPicMax) {

     opacity(infoDivCo,R);
     ZaehlerExLastPic += -DeltaExLastPic;

     aktivExLastPic = setTimeout("exit_overlayLastPic()", Millisec);	
    } else {
          clearTimeout(aktivExLastPic);

              //document.getElementById(setgdliburl).src = globPath;
              ZaehlerBl      = ZaehlerBlStart;
              ZaehlerBg      = ZaehlerBgStart;
              ZaehlerCo      = ZaehlerCoStart;
              ZaehlerEx      = ZaehlerExStart;
              ZaehlerExLastPic= ZaehlerExLastPicStart;
              ZaehlerTx      = ZaehlerTxStart;
      busy_exit_overlayLastPic=0;
      set_new_picture();
    }
}
else
{
//ohne Timer
              //document.getElementById(setgdliburl).src = globPath;
              ZaehlerBl      = ZaehlerBlStart;
              ZaehlerBg      = ZaehlerBgStart;
              ZaehlerCo      = ZaehlerCoStart;
              ZaehlerEx      = ZaehlerExStart;
              ZaehlerExLastPic= ZaehlerExLastPicStart;
              ZaehlerTx      = ZaehlerTxStart;
      busy_exit_overlayLastPic=0;
      set_new_picture();


}    
    
    
    
}
//------- set next pic ---------------------
function set_new_picture()
{
var path;
var text;
var groessenDiff;
var height;
var width;

path=globPath;
width=globWidth;
height=globHeight;
text=globText;

              //ZaehlerBl      = ZaehlerBlStart;
              ZaehlerBg      = ZaehlerBgStart;
              ZaehlerCo      = ZaehlerCoStart;
              ZaehlerEx      = ZaehlerExStart;
              ZaehlerExLastPic= ZaehlerExLastPicStart;
              ZaehlerTx      = ZaehlerTxStart;
  //document.getElementById(setgdliburl).src = path;

             Untertitel=text;

             bild_original_width=width;
             bild_original_height=height;

             InitFensterHoehe  = get_screen_height()-PreviewHeight-infoDivTxHoehe;//window.innerHeight;
             InitFensterBreite = get_screen_width();//window.innerWidth;

             Zoom=get_max_zoom(bild_original_width,bild_original_height);

             height=height/100*Zoom;
             width=width/100*Zoom;

              //globPath=path;
              //document.getElementById(setgdliburl).src = globPath;


              BoZielBreite=width;
              BoZielMarginleft=width/2;

              BoZielHoehe=height;
              BoZielMargintop=height/2;

              document.getElementById(bild_overlay).style.display="block";
              document.getElementById(infoDivBl).style.display="block";
              
              document.getElementById(setgdliburl).style.width  = (BoZielBreite)+'px';
              document.getElementById(setgdliburl).style.height = (BoZielHoehe)+'px';

              document.getElementById(infoDivBg2).style.display="block";
              document.getElementById(infoDivBg).style.display="block";

              document.getElementById(setgdliburl).src = globPath;
              oneStepX=0;
              oneStepY=0;            
              ChBreite=merkeBoZielBreite;
	            ChMarginleft=merkeBoZielMarginleft;
	            ChDelta_x=0;
             	
	            if (BoZielBreite>merkeBoZielBreite){oneStepX=(BoZielBreite-merkeBoZielBreite)/2/100;}
              if (BoZielBreite<merkeBoZielBreite){oneStepX=-(merkeBoZielBreite-BoZielBreite)/2/100;}

              ChHoehe=merkeBoZielHoehe;
	            ChMargintop=merkeBoZielMargintop;
	            ChDelta_y=0;
	
	            if (BoZielHoehe>merkeBoZielHoehe){oneStepY=(Math.abs(BoZielHoehe-merkeBoZielHoehe))/2/100;}
              if (BoZielHoehe<merkeBoZielHoehe){oneStepY=-(Math.abs(merkeBoZielHoehe-BoZielHoehe))/2/100;}
	    
              	document.getElementById(infoDivBg2).style.display="block";
                document.getElementById(infoDivBg).style.display="block";
                document.getElementById(infoDivCo).style.display="none";
              
              ZaehlerN=ZaehlerNStart;
              
              groessenDiff=Math.max(Math.abs(BoZielHoehe-merkeBoZielHoehe),Math.abs(BoZielBreite-merkeBoZielBreite));
        
              if(groessenDiff!=0){
                 DeltaN=Math.floor(Math.min(30,Math.max(1,(rectFaderFactor/groessenDiff))));
              }
              else
              {
                 DeltaN=0;
              }
              
              //hilfe
              //document.getElementById("id_cl_infoDivEx_ue").style.display="block";
              //document.getElementById("infospanPageText").innerHTML="delta n="+DeltaN+"<br>rectFaderFactor="+rectFaderFactor+"<br> groessenDiff="+groessenDiff ;
          
              ChDelta_y = oneStepY*DeltaN;
              ChDelta_x = oneStepX*DeltaN;         
            
              if ( BoZielBreite!=merkeBoZielBreite || BoZielHoehe!=merkeBoZielHoehe) {
               if (diashow_fade_to_next_picture==1)
               {
               //document.getElementById(setgdliburl).src = globPath;
               //set_bg();
               //document.getElementById(infoDivBg).style.display="none";
               change_bg_percent();
               
               }
               else
               {
               //document.getElementById(setgdliburl).src = globPath;
               set_bg();
               }
               
              }
              else
              {
               //document.getElementById(setgdliburl).src = globPath;
               set_bg();
              }

}
//----------------------------------------------------------------
function change_bg_percent()// Fade Rahmen auf neue Grösse, wenn neues Bild gewählt wird
{

var R;
var Ralpha;
var W;
var Ml;
var H;
var Mt;

 if (diashow_fade_to_next_picture==0 && ((ChDelta_x==0) && (ChDelta_y==0)))
 {
 document.getElementById(setgdliburl).src = globPath;
 set_bg();
 }
 else
 {
     if (ZaehlerN<=ZaehlerNMax){
     
       
     	 aktivCh = setTimeout("change_bg_percent()", Millisec);

                W=ChBreite;
                Ml=-ChMarginleft;

                H=ChHoehe;
                Mt=-ChMargintop;

                document.getElementById(infoDivBg2).style.marginLeft = (Ml-Rand-Rand2)+'px';
                document.getElementById(infoDivBg2).style.width = (W+Rand*2+Rand2*2)+'px';
                document.getElementById(infoDivBg2).style.marginTop = (Mt-Rand-Rand2)+PreviewHeight/2-infoDivTxHoehe/2+'px';
                document.getElementById(infoDivBg2).style.height = (H+Rand*2+Rand2+Rand2unten)+'px';
               
                document.getElementById(infoDivBg).style.marginLeft = (Ml-Rand)+'px';
                document.getElementById(infoDivBg).style.width = (W+Rand*2)+'px';
                document.getElementById(infoDivBg).style.marginTop = (Mt-Rand)+PreviewHeight/2-infoDivTxHoehe/2+'px';
                document.getElementById(infoDivBg).style.height = (H+Rand*2)+'px';

         //timercontrol  
         //document.getElementById(infoDivTx).style.display="block";
         //document.getElementById(infospanText).innerHTML= korrektur_counter; 
 
         ChBreite     += (ChDelta_x*2);
         ChMarginleft += ChDelta_x;
         ChHoehe      += (ChDelta_y*2);
         ChMargintop  += ChDelta_y;
         
         
         ZaehlerN += DeltaN;

    } else
    {

	       clearTimeout(aktivCh);
         document.getElementById(setgdliburl).src = globPath;
         set_bg();

    }

 }
 
}


//----------------------------------------------------------------
function set_bg()
{
var R;
var Ralpha;
var W;
var Ml;
var H;
var Mt;

  ZaehlerBg = ZaehlerBgMax;
  R = ZaehlerBg/Nenner;
  Ralpha = R*100;


document.getElementById(setgdliburl).src = globPath;
                document.getElementById(infoDivBg2).style.display="block";
                document.getElementById(infoDivBg).style.display="block";
     	
                W=Math.min(BoZielBreite,(BoZielBreite/Max)*Ralpha);
                Ml=Math.max(-BoZielMarginleft,-(BoZielMarginleft/Max)*Ralpha);

                H=Math.min(BoZielHoehe,(BoZielHoehe/Max)*Ralpha);
                Mt=Math.max(-BoZielMargintop,-(BoZielMargintop/Max)*Ralpha);


                document.getElementById(infoDivBg2).style.marginLeft = (Ml-Rand-Rand2)+'px';
                document.getElementById(infoDivBg2).style.width = (W+Rand*2+Rand2*2)+'px';
                document.getElementById(infoDivBg2).style.marginTop = (Mt-Rand-Rand2)+PreviewHeight/2-infoDivTxHoehe/2+'px';
                document.getElementById(infoDivBg2).style.height = (H+Rand*2+Rand2+Rand2unten)+'px';


                document.getElementById(infoDivBg).style.marginLeft = (Ml-Rand)+'px';
                document.getElementById(infoDivBg).style.width = (W+Rand*2)+'px';
                document.getElementById(infoDivBg).style.marginTop = (Mt-Rand)+PreviewHeight/2-infoDivTxHoehe/2+'px';
                document.getElementById(infoDivBg).style.height = (H+Rand*2)+'px';





        
        overlay_content_text();

}

//-------------------------------------------------------------------
function opacity(id,R)
{

var Ralpha;
var W;
var Ml;
var H;
var Mt;


    Ralpha = R*100;
    if (browser=='MSIE')
    {
     //Sorry, he is not fast enough !!!!!
    //document.getElementById(id).style.filter = 'alpha(opacity=' + Ralpha + ')';
    }
    else
    {
    document.getElementById(id).style.opacity = (R);
    document.getElementById(id).style.MozOpacity = (R);
    document.getElementById(id).style.KhtmlOpacity = (R);
    }

}
//-------------------------------------------------------------------







