// === Obarvovaci menu ===
var colorArray = new Array ('#ccc', '#D9D4B1', '#D2CB9B', '#E0D58A', '#fff', '#ccc', '#ddd', '#fff'); 
var colorTimer = "";
var uncolorTimer = "";
var uncolorTimerId = "";

var arrayUncolorTimerId = new Array();

function colorBG(objID) {
  if (colorTimer != "") clearTimeout(colorTimer);
  if (arrayUncolorTimerId[objID] != "") clearTimeout(arrayUncolorTimerId[objID]);
  cycledColorBG(objID, 0);
}

function cycledColorBG(objID, colorIndex) {
  document.getElementById(objID).style.backgroundColor = colorArray[++colorIndex];
  if (colorIndex < colorArray.length) {
    colorTimer =  setTimeout("cycledColorBG('" + objID + "', " + colorIndex + ")", 100);
  }
  else {

  }
}

function uncolorBG(objID) {
  if (colorTimer != "") clearTimeout(colorTimer);
  cycledUncolorBG(objID, colorArray.length);
}

function cycledUncolorBG(objID, colorIndex) {
  document.getElementById(objID).style.backgroundColor = colorArray[--colorIndex];
  if (colorIndex > 0) {
    arrayUncolorTimerId[objID] = setTimeout("cycledUncolorBG('" + objID + "', " + colorIndex + ")", 100);
  }
  else {
    document.getElementById(objID).style.backgroundColor = 'transparent';
    arrayUncolorTimerId[objID] = "";
  }
}

//Blikani loading
var blinkingColors = new Array("#999", "#aaa", "#bbb", "#ccc", "#ddd", "#eee", "#fff");
var blinkingElement = "";
var blinkingTimer = "";
var blinkIndex = 0;

function blinkOn(objID, iterate) {
  blinkingElement = objID;
  document.getElementById(blinkingElement).style.display = "block";  
  if(blinkIndex == 0) iterate=true;
  if(blinkIndex < blinkingColors.length && iterate==true) {
    document.getElementById(blinkingElement).style.color = blinkingColors[++blinkIndex];
    return blinkingTimer = setTimeout("blinkOn('" + objID + "', true)", 100);    
  }
  if(blinkIndex == blinkingColors.length) iterate=false;
  if(blinkIndex > 0 && iterate==false) {
    document.getElementById(blinkingElement).style.color = blinkingColors[--blinkIndex];
    return blinkingTimer = setTimeout("blinkOn('" + objID + "', false)", 100);
  }  
}

function blinkOff(objID) {
  clearTimeout(blinkingTimer);
  document.getElementById(blinkingElement).style.display = "none";
}

//Poblikavani uvodni stranky
var prvky = new Array(11, 12, 13, 21, 22, 23, 31, 32, 33);

function blinkFrontPage() {  
  index = Math.floor(Math.random() * prvky.length);
  if(document.getElementById("grid" + prvky[index] + "_green").style.backgroundImage == "") {
    document.getElementById("grid" + prvky[index] + "_green").style.backgroundImage = "url('./bitmaps/grid" + prvky[index] + "_green.jpg');";
  }
  else {
    document.getElementById("grid" + prvky[index] + "_green").style.backgroundImage = "";
  }
  timeout = Math.floor(Math.random() * 1000);
  return setTimeout("blinkFrontPage()", timeout);
}


//Filling picture area
function fillPictureArea(picture) {
  document.getElementById('picture_area_img').src = "./bitmaps/spacer.gif";
  document.getElementById('picture_area_img').src = picture;
  blinkOn('loading', true);
}

