/*
 * Common javascript resources for www.samuelmurez.com
 *
 */
 
// walk all elements of DOM tree at and below e, 
// run function fn for each element with parameters param
// not suitable for fn's which change a node  
function walkTree(e, fn, param) {

  fn(e, param);
  
  var eChild = e.firstChild
  while (eChild) {
    walkTree(eChild, fn, param);    
    eChild = eChild.nextSibling;
  }
}

// slideshow details
var slideshows = {
  slide_background : Array('images/donq.jpg','images/4e.jpg'),
  slide_2004 : Array("images/mc14_regard_simon.jpg","images/mc14main_alex.jpg","images/mc14debut_rail_recadre.jpg","images/mc14rail_tlm.jpg"),
  slide_2003 : Array("images/fantome_maquillage.jpg","images/fantome_apparition.jpg","images/fantome_pointe_derriere.jpg"),
  slide_2002 : Array("images/sacre1.jpg","images/sacre2.jpg"),
  slide_2001 : Array("images/chanteur1.jpg","images/chanteur2.jpg")
} 
// install a Dojo slideshow (with our own template & css)
// note: the paths are relative to dojo baseRelativePath
function createSlideShow(id,images, transition, delay) {
    
  var obj = document.getElementById(id);
  var properties = {
  templatePath : dojo.uri.dojoUri('../dojo-custom/templates/HtmlSlideShow.html'),
  templateCssPath : dojo.uri.dojoUri('../dojo-custom/templates/HtmlSlideShow.css'),
  imgUrls : images,
  transitionInterval : (transition || 3000),
  delay : (delay || 4000),
  imgWidth : obj.width,
  imgHeight : obj.height
  }
    
  dojo.widget.fromScript("SlideShow", properties, obj);
}

// treewalker callback function for installing slideshows
function walker_slideshow(e, param) {

  if (e.nodeType != 1) return;
  if (!e.className.match(/\bslideshow\b/)) return;
  if (!e.id) return;
  if (!slideshows[e.id]) return;
  
  createSlideShow(e.id, slideshows[e.id]);
}

function init() {
  walkTree(document.body, walker_slideshow, null);
}

// initialise Dojo
// dojo.require("dojo.event.*");
// dojo.require("dojo.widget.*");
try {
  if (dojo) {
    dojo.require("dojo.widget.SlideShow");
    dojo.require("dojo.event.browser");
  
    dojo.event.connect(dojo, "loaded", "init");
  }
} catch(e) {
  // nothing to do
}



