var bb_curImg=-1, bb_Images, bb_imgCnt, bb_Thumbs;
var bb_imgPath = "";

function bb_rand (min, max) {  
    return Math.floor(Math.random() * (max - min + 1)) + min;  
} 

function bb_setImg(imgNr) {
  var bgImg = "url(" + bb_imgPath + bb_Images[imgNr] + ")";
  // document.getElementById("hdr_img_container").style.backgroundImage=bgImg;
  document.getElementById("hdr_img").src=bb_imgPath + bb_Images[imgNr];
}

function bb_headerGallery() {
  bb_curImg = (-1 == bb_curImg) ? bb_rand(0, bb_imgCnt) : bb_curImg+1;
  if (bb_curImg >= bb_imgCnt) bb_curImg=0;
  bb_setImg(bb_curImg);
}

function bb_headerThumbs(thmbs) {
  var i, thmbs=thmbs.split(",");
  for(i=0;i<bb_imgCnt;i++) {
    var im = document.createElement("img");
    with (im) {
      src=thmbs[i];
      className="headerThmb";
      id="headerImage_"+i;
      onclick=function() { bb_setImg(this.id.split("_")[1]); };
    }
    
    // document.getElementById("header_visual_container").offsetParent
    with(document.getElementById("header_thmb_container")) {
      appendChild(im);
      var br=document.createElement("br");
      appendChild(br);
    }
  }
}

function bb_initImages(imgs, thmbs, p) {
  bb_Images= imgs.split(",");
  bb_imgCnt= bb_Images.length;
  bb_imgPath = p;
  bb_headerThumbs(thmbs);
  bb_headerGallery();
}


