
var curDiv = 0;
//var totalPicRows = 2;
//var totalPicRows = "<?php echo $total_com_rows; ?>";

lastDiv = 0;


//alert('commercial_'+(curDiv+1));
//alert("Total rows: "+totalPicRows);


function addDivCount()
{
curDiv=curDiv+1;
//alert(curDiv);

      if (curDiv == totalPicRows)
      {
 //     alert("Ajee, viimane juba! "+curDiv);
 //     curDiv = 0;
 //     alert("Nüüd uus div nr: "+curDiv);
      lastDiv = 1;
      }

}



function changeDiv()
{

      if (lastDiv == "1")
      {
      oldDivCount=curDiv;
      curDiv = 0;
      
      //alert("Old dir count: "+oldDivCount+"New div count: "+curDiv);
      
      activeDiv = totalPicRows;
      nextDiv = curDiv;

      }
      else
      {
      activeDiv = curDiv;
      nextDiv = curDiv+1;
      
      //alert("Active dir count: "+activeDiv+"Next div count: "+nextDiv);
      }

//alert("enne muutmist!");






//    SHOW NEW DIV
nextdivid = document.getElementById('commercial_'+nextDiv);
nextdivid.style.display="block";


//alert("kahe muutmise vahel!");


//    HIDE SECOND
thisdivid = document.getElementById('commercial_'+activeDiv);
thisdivid.style.display="none";




//alert ("muudame commercial_"+nextDiv+"blockiks ja commercial_"+activeDiv+"noneks");
 
//alert("pärast muutmist!");

//headerBackground="url(images/page/"+headerPicUrl+"_"+curDiv+")";
//alert (curDiv+1);

//var headerBackground=headerPicUrl[curDiv+1];
//// GET NEXT HEADER IMAGE

//alert(headerPicUrl[curDiv]);


//document.getElementById('header_banner_holder').style.backgroundImage = "url('modules/mod_front_picbar/images/"+headerPicUrl[nextDiv]+"')";


setupTimeout();


      if (lastDiv == "1")
      {
      lastDiv = 0;
      }
      else 
      {
      addDivCount();
      }


}



function setupTimeout()
{

  if (totalPicRows != "0")
  {
loopTimer=setTimeout("changeDiv()", timeoutSetting); // TIMEOUT IN SECONDS

loopTimer;
  } 
  

    //alert("Ajee, set timeout: "+timeoutSetting+"millisec");
}



window.onload=setupTimeout();



function cancelTimeout()
{
clearTimeout(loopTimer);

}
