var obrazky = new Array();
var img = document.getElementById("fotouvodbgd");

var maxObrazku = 0;
var obrazek = 1;
var otoceni = 0;
var timerCele;
var krok = 0.6;

//**************** class **************************//

function ImageWithTitle (image_filename,title_Id)
{
  var posunuto = 0;
  var newImg;
  var title;
  var titleId;
  var filename;
  var timerPosun;
  var order;
  var color = 0;
  
  this.addImage = function addImage (image_filename,title_id)
  {
         this.newImg = document.createElement ("img");
         this.newImg.setAttribute("src",filename);
         this.title = document.getElementById(title_id)
         this.titleId = title_id;
         this.filename = image_filename;
         this.order = obrazky.length;
         this.okraj = 0;
  }
  
  this.posun = function posun ()
  {    
    this.posunuto ++;
    //this.title.style.backgroundColor = "#800";  
    if (this.posunuto <= 10)
      {
        this.okraj = this.okraj + krok;
        this.color = 250 - (this.posunuto * 25);
        this.title.style.color = "rgb("+this.color+","+this.color+","+this.color+")";        
      }
      else if (this.posunuto <= 20)      
      {
        this.okraj = this.okraj - (krok);
      }
    this.title.style.marginLeft = this.okraj+"em";
    if (this.posunuto <= 20)
       {
       this.timerPosun = setTimeout ("obrazky["+this.order+"].posun();", 50);
       } 
  }
  
  this.change2Selected = function change2Selected ()
  {
        this.posunuto = 0;
        this.title.style.color = "white";
        this.title.style.fontWeight = "bold";
        this.title.style.marginRight = "0em";
        this.posun(this.titleId);
        this.title.style.visibility = "visible";
        img.src = this.filename;
        this.title.style.borderBottom = "#500 0.1em solid"; 
  }
  
  this.change2Unselected = function change2Unselected ()
  {
        posunuto = 0;
        this.title.style.color = "#FFF";
        this.title.style.fontWeight = "normal";
        this.title.style.border = "0";
  }
  
  this.finalize = function finalize ()
  {
        this.title.style.color = "#500";
        this.title.style.fontWeight = "bold"; 
        this.title.style.backgroundColor = "white";
        this.title.style.border = "0";      
  }   
  // vyvolani inicializace
  this.addImage (image_filename,title_Id);
}

// *********************** hlavni volani ****************************

function zmena ()
    {          

    if (obrazek > 0)
      {
      var obr_old = obrazky[obrazek-1];
      obr_old.change2Unselected ();
      }
                                                                                                                                
    if (otoceni > 0) // finální select pro všechny, nebo dalsi obrazek 
      { // konec
      img.src = obrazky[0].filename;  
      for (var x = 0; x < maxObrazku + 1; x++) 
        {obrazky[x].finalize();}
      obrazky = null;      
      } 
      else
      { // pretaceni
      obrazky[obrazek].change2Selected();
      timerCele = setTimeout ("zmena()", 2500);
      }
      
    obrazek = obrazek + 1;
    if (obrazek > maxObrazku) {obrazek = 0; otoceni ++ } // pretocil jsem se pres max                
    }


if (obrazky.length == 0) 
  {
  obrazky[obrazky.length] = new ImageWithTitle ("images-web/trojice.jpg","codelame0"); // skeče
  obrazky[obrazky.length] = new ImageWithTitle ("images-web/lucka.jpg","codelame1");  // písničky
  obrazky[obrazky.length] = new ImageWithTitle ("images-web/loupeznik.jpg","codelame2");  // scénky
  obrazky[obrazky.length] = new ImageWithTitle ("images-web/showdance_white.jpg","codelame3"); // showdance
  obrazky[obrazky.length] = new ImageWithTitle ("images-web/tomas.jpg","codelame4"); // kontakt s publikem
  obrazky[obrazky.length] = new ImageWithTitle ("images-web/urednik.jpg","codelame5"); // satira
  obrazky[obrazky.length] = new ImageWithTitle ("images-web/trojice.jpg","codelame6"); // průvodní slovo      
  maxObrazku = obrazky.length - 1; // pole je cislovane od 0

   for (var x = 0; x < maxObrazku + 1; x++) 
    {
    obrazky[x].title.style.visibility = "hidden";
    }
  
  obrazky[0].change2Selected();
  timerCele = setTimeout ("zmena()", 2500);   
  }
      
