//////////////////////////////////////////////////////////////////////////////////////////////////////////
// preloading 
//////////////////////////////////////////////////////////////////////////////////////////////////////////
function ie6init() {
	         var imagesNodes = document.getElementsByClassName('scene', $('slideshow_0'))[0].getElementsByTagName('fieldset');
          	for(var i=0; i<imagesNodes.length; i++) {
          		imagesNodes[i].style.position='absolute';
            }
}

function ie6fix() {
  		document.getElementsByClassName('thumbnails', $('slideshow_0'))[0].style.display='none';
  		document.getElementsByClassName('thumbnails', $('slideshow_0'))[0].style.display='block';
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////
// maps, europe and world
//////////////////////////////////////////////////////////////////////////////////////////////////////////
function launchMap() {
	zespots = document.getElementsByClassName('slideshow', document);

	for(var i=0; i<zespots.length; i++) {
		// slideshow
		zespots[i].style.display = 'none';
		zespots[i].style.position = 'absolute';
		// the legend
		zespots[i].getElementsByTagName('legend')[0].style.display = 'none';
		// the title 
		zespots[i].getElementsByTagName('h2')[0].style.display = 'none';
		// the dot
		var zeDot = zespots[i].previousSibling.childNodes[0];
		zeDot.style.position = 'absolute';
		zeDot.onmouseover = function () {
			Effect.Appear(this.parentNode.nextSibling,{duration:1});
		}
		zeDot.onmouseout = function () {
			Effect.Fade(this.parentNode.nextSibling,{duration:1});
		}
	}
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////
// thumbnail functions
//////////////////////////////////////////////////////////////////////////////////////////////////////////
function launchThumbnails(slideshowId, f_topTxtStr, f_bottomTxtStr) {
		var slideshowNode = document.getElementById('slideshow_'+slideshowId);

		// initialize thumbnail scroll
		var zethumb = document.getElementsByClassName('thumbnails', slideshowNode)[0];
		scrolledElt = zethumb.getElementsByTagName('ul')[0];
		scrolledElt.style.overflow = 'hidden';
	
		var topNode = document.createElement('a');
		topNode.className = 'to_top';
		topNode.setAttribute('title',f_topTxtStr);
    addEvent(topNode, 'mouseover', startScrollTop);
    addEvent(topNode, 'mouseout', clearScroll);
		var altNode = document.createElement('span');
		altNode.className = 'alternate';
		var altTxt = document.createTextNode(f_topTxtStr);
		altNode.appendChild(altTxt);
		topNode.appendChild(altNode);
		zethumb.appendChild(topNode);
	
		var bottomNode = document.createElement('a');
		bottomNode.className = 'to_bottom';
		bottomNode.setAttribute('title',f_bottomTxtStr);
    addEvent(bottomNode, 'mouseover', startScrollBottom);
    addEvent(bottomNode, 'mouseout', clearScroll);
		var altNode = document.createElement('span');
		altNode.className = 'alternate';
		var altTxt = document.createTextNode(f_bottomTxtStr);
		altNode.appendChild(altTxt);
		bottomNode.appendChild(altNode);
		zethumb.appendChild(bottomNode);
}

var thumbScrollStep = 10;
var scrolledElt = null;
var scrollInterval = null;

function startScrollBottom () {
	scrollInterval = window.setInterval("scrollBottom()", 20);
}	
function scrollBottom () {
	scrolledElt.scrollTop += thumbScrollStep;
}
function startScrollTop () {
	scrollInterval = window.setInterval("scrollTop()", 20);
}	
function scrollTop () {
	scrolledElt.scrollTop -= thumbScrollStep;
}
function clearScroll () {
  clearInterval(scrollInterval);
}


////////////////////////////////////////////////////////////////////////////////
//  menu 
////////////////////////////////////////////////////////////////////////////////
var is_node_active = false;
var tm_len = 2000;

function activate_menu() {
	var zebody = document.getElementById('menu');
	var nodes = zebody.getElementsByTagName('ul')[0].childNodes;

	for(var i=0; i<nodes.length; i++) { 
		// adds rollover button
		addEvent(nodes[i].childNodes[0], 'mouseover', show_level1);
//		nodes[i].childNodes[0].onmouseover = 'show_level1()';
		addEvent(nodes[i].childNodes[0], 'mouseout', hide_level1);
//		nodes[i].childNodes[0].onmouseout = function () { hide_level1(); };

		if(nodes[i].childNodes[1]) {
			var level = nodes[i].childNodes[1];
			for(var j=0; j<level.childNodes.length; j++) { 
				var sublink = level.childNodes[j].childNodes[0];
				addEvent(sublink, 'mouseover', show_level2);
//		      sublink.onmouseover = function () { show_level2(); };
				addEvent(sublink, 'mouseout', hide_level2);
//		      sublink.onmouseout = function () { hide_level2(); };
				if(nodes[i].childNodes[1].childNodes[j].childNodes[1]) {
					var level2 = level.childNodes[j].childNodes[1];
					for(var k=0; k<level2.childNodes.length; k++) { 
						sublink = level2.childNodes[k].childNodes[0];
				addEvent(sublink, 'mouseover', show_level3);
//		      sublink.onmouseover = function () { show_level3(); };
				addEvent(sublink, 'mouseout', hide_level3);
//		      sublink.onmouseout = function () { hide_level3(); };
					}
				}
			}
		}
	}
}
var ht1;
function hide_level1(e) {
//	alert('hide');
	if (is_node_active) {
		is_node_active = false;
		ht1 = window.setTimeout("clear_level()", tm_len);
	}
//	cancelEvent(e, false);
}
function show_level1(e) {
//	alert('show');
	clear_level();
	if (this.className!='selected') this.className='hover';
	if (this.nextSibling) this.nextSibling.style.display = 'block';
	window.clearTimeout(ht1);
	is_node_active = true;
//	cancelEvent(e, false);
}

function hide_level2(e) {
//	alert('hide2');
//	is_node_active = false;
	if (is_node_active) {
		if (this.nextSibling) this.nextSibling.style.display = 'none';
		is_node_active = false;
		ht1 = window.setTimeout("clear_level()", tm_len);
	}
//	ht2 = window.setTimeout("clear_level1()",1000);
//	cancelEvent(e, false);
}
function show_level2(e) {
//	alert('show2');
//	clear_node();
	if (this.nextSibling) this.nextSibling.style.display = 'block';
	window.clearTimeout(ht1);
	is_node_active = true;
//	if (ht2!=null) window.clearTimeout(ht2);
//	cancelEvent(e, false);
}


function hide_level3(e) {
//	alert('hide3');
//	is_node_active = false;
	if (is_node_active) {
		is_node_active = false;
		ht1 = window.setTimeout("clear_level()", tm_len);
	}
//	if (this.nextSibling) this.nextSibling.style.display = 'none';
//	ht2 = window.setTimeout("clear_level1()",1000);
}
function show_level3(e) {
//	alert('show3');
	this.parentNode.parentNode.style.display = 'block';
	window.clearTimeout(ht1);
	is_node_active = true;
//	cancelEvent(e, false);
}
function clear_level() {
//	alert('clear');
	if (is_node_active == false) {
		var zebody = document.getElementById('menu');
		var nodes = zebody.getElementsByTagName('ul')[0].childNodes;
  		for(var i=0; i<nodes.length; i++) {
			if (nodes[i].childNodes[0].className!='selected') nodes[i].childNodes[0].className='';
			if (nodes[i].getElementsByTagName('ul').length>0) {
				nodes[i].getElementsByTagName('ul')[0].style.display='none';
			}
		}
	}
}

/*
AddEvent Manager (c) 2005-2006 Angus Turnbull http://www.twinhelix.com
Free usage permitted as long as this credit notice remains intact.
*/

if (typeof addEvent != 'function')
{
 var addEvent = function(o, t, f, l)
 {
  var d = 'addEventListener', n = 'on' + t, rO = o, rT = t, rF = f, rL = l;
  if (o[d] && !l) return o[d](t, f, false);
  if (!o._evts) o._evts = {};
  if (!o._evts[t])
  {
   o._evts[t] = o[n] ? { b: o[n] } : {};
   o[n] = new Function('e',
    'var r = true, o = this, a = o._evts["' + t + '"], i; for (i in a) {' +
     'o._f = a[i]; r = o._f(e||window.event) != false && r; o._f = null;' +
     '} return r');
   if (t != 'unload') addEvent(window, 'unload', function() {
    removeEvent(rO, rT, rF, rL);
   });
  }
  if (!f._i) f._i = addEvent._i++;
  o._evts[t][f._i] = f;
 };
 addEvent._i = 1;
 var removeEvent = function(o, t, f, l)
 {
  var d = 'removeEventListener';
  if (o[d] && !l) return o[d](t, f, false);
  if (o._evts && o._evts[t] && f._i) delete o._evts[t][f._i];
 };
}
function cancelEvent(e, c)
{
 e.returnValue = false;
 if (e.preventDefault) e.preventDefault();
 if (c)
 {
  e.cancelBubble = true;
  if (e.stopPropagation) e.stopPropagation();
 }
};

// 		thanks to 
//		- http://simon.incutio.com/archive/2004/05/26/addLoadEvent

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}