function add_artist (id,name) {
  add(id);
  showLocation(name);
}

function my_wat () {
var foo5 = document.getElementById('foo5');

var tif  = new Array();
var leg  = new Array();

var randomnumber=Math.floor(Math.random()*10);

tif [0] = 'CARAVAGE.tif';
tif [1] = 'jeb3.tif';
tif [2] = 'fayoum_portrait_famille.tif';
tif [3] = 'daddi.tif';
tif [4] = 'Jan_van_Eyck_0011.tif';
tif [5] = 'jinan.tif';
tif [6] = 'latour7.tif';
tif [7] = 'ranakpur.tif';
tif [8] = 'Salomon.tif';
tif [9] = 'xxl_street.tif';

leg [0] = 'Michelangelo Merisi da Caravaggio (29 September 1571 - 18 July 1610)';
leg [1] = '';
leg [2] = 'Fayum mummy portraits';
leg [3] = '';
leg [4] = 'Jan van Eyck or Johannes de Eyck';
leg [5] = 'Jinan -China';
leg [6] = 'LA TOUR, Georges de';
leg [7] = 'Ranakpur - India';
leg [8] = "The Jacques-Édouard Berger collection contains over four hundred objects, of which a good hundred are amulets. Although these may be less spectacular than other significant pieces in the collection, they bear witness to a collector in quest of objects that reveal a popular sensibility, far removed from the grand theologicalspeculations elaborated by a priestly elite in the seclusion of the 'houses of life'";
leg [9] = 'Johannes Vermeer';

var legend = leg[randomnumber];
var name   = tif[randomnumber];

var code = "<hr><object id=\"fsiviewer\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,42,0\" width=\"320\" height=\"223\">";
code    += "<param name=\"movie\" value=\"http://empc50.epfl.ch/erez3/fsi3/fsi.swf?FPXBase=http://empc50.epfl.ch/erez3%2Ferez%3Fsrc%3D&FPXSrc=Samples/Macbeth%2520color%2520samples/" + name + "&ViewerWidth=320&ViewerHeight=223&NoNav=1\"/>";        
code    += "<param name=\"menu\"  value=\"FALSE\" />";
code    += "<embed src=\"http://empc50.epfl.ch/erez3/fsi3/fsi.swf?FPXBase=http://empc50.epfl.ch/erez3%2Ferez%3Fsrc%3D&FPXSrc=Samples/Macbeth%2520color%2520samples/" + name + "&ViewerWidth=320&ViewerHeight=223&NoNav=1\"width=\"320\"height=\"223\" name=\"fsiviewer\" menu=\"false\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\">";
code    += '</object><br>' + legend + ' -  <a href="javascript:my_hide()">Hide</a>';


foo5.innerHTML=code;

}

function my_hide() {
 var foo5 = document.getElementById('foo5');
 while (foo5.firstChild) {
  foo5.removeChild(foo5.firstChild);
 }
}

function add_menu(name,num) {

var tree = document.getElementById('dtree');
while (tree.firstChild) {
  tree.removeChild(tree.firstChild);
}
d = new dTree('d');
d.add(0,-1,'&nbsp; <strong><a href="javascript:my_init()">Art and Civilization</a></strong> (<a href="javascript: d.openAll();">open all</a> | <a href="javascript: d.closeAll();">close all</a>)');
d.add(1,0,'Region','');
d.add(2,0,'Painter','');
d.add(3,0,'Period','');
d.add(4,0,'Lecture-course cycles (French only)','');
d.add(5,0,'Itineraries','');
d.add(6,0,'Essays','');

var url = '/slideshow/' + name + '.json';

dojo.xhrGet({
    url: url ,
    load: function(response, ioArgs){
        var len = response.items.length; 
        for(i=0;i<len;i++){
        var src = response.items[i].menu;      
            eval(src);	  				
        }
        tree.innerHTML=d;
      return response;
    },
    error: function(response, ioArgs){
      dojo.byId('thumbarea').innerHTML = 
        "An error occurred, with response: " + response;
      return response;
    },
    handleAs: "json"
  });
  
  //Attention !!!
  
  if ( num > 0   ) {        
  if ( num < 40 ) {
    my_map(num);
    add(my_slideshow[num]);
  } else {
    my_map3(my_zoom[num],my_lat[num],my_long[num],num);
  }
  }
    
}


function add_regard(name,conf,latitude,longitude,num) {
    
site(conf);
my_map3(13,latitude,longitude,num);

var tree = document.getElementById('dtree');
while (tree.firstChild) {
  tree.removeChild(tree.firstChild);
}

d = new dTree('d');
d.add(0,-1,'&nbsp; <strong>Art and Civilization</strong> (<a href="javascript: d.openAll();">open all</a> | <a href="javascript: d.closeAll();">close all</a>)');
d.add(1,0,'Region','');
d.add(2,0,'Painter','');
d.add(3,0,'Period','');
d.add(4,0,'Lecture-course cycles (French only)','');
d.add(5,0,'Itineraries','');
d.add(6,0,'Essays','');

var url = '/slideshow/' + name + '.json';
dojo.xhrGet({
    url: url ,
    load: function(response, ioArgs){
        var len = response.items.length; 
        for(i=0;i < len;i++){
        var src = response.items[i].menu;      
            eval(src);	  				
        }
        tree.innerHTML=d;
      return response;
    },
    error: function(response, ioArgs){
      dojo.byId('thumbarea').innerHTML = 
        "An error occurred, with response: " + response;
      return response;
    },
    handleAs: "json"
  });   	              
}

function my_init() {                       
    dojo.xhrGet({
    url: '/wat1/Itineraries.pl',
    load: function(response, ioArgs){ 
       
       var theAlert = new Array();
       var theUrl = new Array();
       
       theAlert[0] = 'Akhenaten-Tell El-Amarna';   
       theUrl[0]   = 'http://www.bergerfoundation.ch/Akhenaton/en/';   
       
       theAlert[1] = 'Abydos';   
       theUrl[1]   = 'http://www.bergerfoundation.ch/Abydos/';   
           
       theAlert[2] = 'Roman Portraits from Egypt';   
       theUrl[2]   = 'http://www.bergerfoundation.ch/Fayoum/';  
       
       theAlert[3] = 'Angkor: The Divine Breath of Stones';   
       theUrl[3]   = 'http://www.bergerfoundation.ch/Angkor/index_eng.html';   
       
       theAlert[4] = 'Borobudur';   
       theUrl[4]   = 'http://www.bergerfoundation.ch/Borobudur/E/';   
       
       theAlert[5] = 'The enchanted gardens of the Renaissance';   
       theUrl[5]   = 'http://www.bergerfoundation.ch/Jardin/index_english.html';  
       
       theAlert[6] = 'Sandro Botticelli';   
       theUrl[6]   = 'http://www.bergerfoundation.ch/Sandro/1frontispice_english.html';  
       
       theAlert[7] = 'Caravaggio - The Night Prince';   
       theUrl[7]   = 'http://www.bergerfoundation.ch/Caravage/E/index.html';  
             
       theAlert[8] = 'Johannes Vermeer';   
       theUrl[8]   = 'http://www.bergerfoundation.ch/Vermeer/english/';  
       
       theAlert[9] = 'G. de la Tour';   
       theUrl[9]   = 'http://www.bergerfoundation.ch/LaTour/english/';  
       
       theAlert[10] = 'Rococo';   
       theUrl[10]   = 'http://www.bergerfoundation.ch/Vertige/english/index.html';  
       
       theAlert[11] = 'The Enlightening Remarks on Painting by Shih-T\'ao';   
       theUrl[11]   = 'http://www.bergerfoundation.ch/Shitao/enlightening.html';  
       
       theAlert[12] = 'What is an amulet?';   
       theUrl[12]   = 'http://www.bergerfoundation.ch/Amulets/germondII.html';                      
      
                     
      var my_param = response.split(";");     
      var pg       = my_param[1];        
      var my_url   = theUrl[pg]; 
      var foo5 = document.getElementById('foo5');
                                               
      while (foo5.firstChild) {
         foo5.removeChild(foo5.firstChild);
      }
      
      var message =  theAlert[pg];
      var my_src;
                                         
      var pattern = /\//;
      if ( pattern.test(my_param[0])  )   {         
         my_src="/cgi-bin/scale2.pl?ref=" + my_param[0] + "&scale=40x40";
      } else {
         my_src="/cgi-bin/slideshow2.pl?ref=" + my_param[0] + "&ico=80";
      }
                        
      var code = "<hr><a href=\"javascript:my_hide();\"><img title=\"Hide\" class=\"floatLeft\" border=\"0\" src=\"" + my_src + "\"></a><a href=\"" + my_url + "\">" + message + "</a>";
     
      foo5.innerHTML = code;
                               
      return response;
    },
    error: function(response, ioArgs){
      dojo.byId('thumbarea').innerHTML = 
        "An error occurred, with response: " + response;
      return response;
    },
    handleAs: "text"
  });
              
                    
}; 

function my_note(url,id,ref,posx,posy){

var popNote   = document.getElementById(id);
if ( popNote) { 
  delpopNote(ref,id);
}

var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request,id,ref,posx,posy)
}
page_request.open('GET', url, true)
page_request.send(null)
}

function loadpage(page_request,id,ref,posx,posy){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
 
 var pop  = document.createElement('DIV');
 pop.id   = id;
 
  var popnote = 'margin    :0; position:relative;width:480px;height:480px;  background:#e2ded4;';
  popnote +=    'border-top    :0px solid black;';
  popnote +=    'display   :block;';
  popnote +=    'padding   :0 0 0 5px;'; 
  popnote +=    'font      :14px verdana, arial, sans-serif;'; 
  popnote +=    'left      :' + posx + 'px;';
  popnote +=    'top       :' + posy + 'px;';
 
 document.getElementById(ref).appendChild(pop);
 _setStyle(document.getElementById(id), popnote);

 var code = '<a href="javascript:delpopNote(\'' + ref + '\',\''  + id + '\');">Close</a><hr>' + page_request.responseText + ''; 
 pop.innerHTML= code;
 
}

function delpopNote(id1,id2) {
  var console   = document.getElementById(id1);
  var popNote   = document.getElementById(id2);
  var removed   = console.removeChild(popNote); 
} 



function rzCC(s){
   // thanks http://www.ruzee.com/blog/2006/07/\
   // retrieving-css-styles-via-javascript/
   for(var exp=/-([a-z])/; 
       exp.test(s); 
       s=s.replace(exp,RegExp.$1.toUpperCase()));
   return s;
 }

 function _setStyle(element, declaration) {
   if (declaration.charAt(declaration.length-1)==';')
     declaration = declaration.slice(0, -1);
   var k, v;
   var splitted = declaration.split(';');
   for (var i=0, len=splitted.length; i<len; i++) {
      k = rzCC(splitted[i].split(':')[0]);
      v = splitted[i].split(':')[1];
      eval("element.style."+k+"='"+v+"'");

   }
 }
