// JavaScript Document

function imgmap_rollover(hover, container, img, area) {
 var o = document.getElementById(hover);

 //play sound file
// if (navigator.appName != 'Netscape') {document.sndfile.play();}
	 
  if (document.getElementById('countryinfo')) {
    if (typeof(area) != 'undefined') {
      if (area.mytext) {
        document.getElementById('countryinfo').innerHTML = area.mytext;
			} else {
        document.getElementById('countryinfo').innerHTML = '';
			}
    } 	
  }

  if(typeof(container) != 'undefined') {
    var c = document.getElementById(container);
    var g = document.getElementById(img);
  
    c.style.width = g.width;
    c.style.height = g.height;
    c.style.position = 'relative';

    if(typeof(area) != 'undefined') {// if there is an argument, show it 
      var coords = area.coords.split(',');
      o.style.position = 'absolute';
      o.style.left = coords[0];
      o.style.top = coords[1];
      o.style.width = coords[2] - coords[0];
      o.style.height = coords[3] - coords [1];
      o.style.display = 'block';
      o.style.cursor = 'hand'; // mimic a hyperlink

      // use this for testing
      //   o.style.backgroundColor = 'red'; 

      // or use image background?
      // I used the area's title to store the image url
      o.style.backgroundImage='url('+area.title+')';

      // onmouseout should be here to avoid the flicker, not in <area>
      o.onmouseout=Function('imgmap_rollover(\''+hover+'\');'); 

      // also consider other potential problems, below are some possible fixes...

      // lost hyperlink?
      o.onclick=Function('window.open(\''+area.href+'\',\''+area.target+'\');');

      // lost alt text?
      o.title=g.alt;

    }
  } else {// hide it
    o.style.display = 'none';
  }
}

function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

function update_string_value(obj_id, FirstText, SecondText, NewValue) {
 var c = document.getElementById(obj_id);
 var string = c.title;
// Replaces text with by in string

    var strLength = string.length, FirstLength = FirstText.length, SecondLength = SecondText.length
    if ((strLength == 0) || (FirstLength == 0)) return string;

    var i = string.indexOf(FirstText);
    if ((!i) && (FirstText != string.substring(0,FirstLength))) return string;
    if (i == -1) return string;

    var j = string.indexOf(SecondText,i+strLength+1);
    if ((!j) && (SecondText != string.substring(i+strLength+1,SecondLength))) return string;
    if (j == -1) return string;

    var newstr = string.substring(0,i+FirstLength) + NewValue + string.substring(j,strLength);

    return newstr;

}

function margin_left(obj_id, newValue) {
  var o = document.getElementById(obj_id).style;
	o.marginLeft = newValue + 'px';
}

function switch_all(id) {
  switch_obj(id+'people','people');
  switch_obj(id+'work','work');
  switch_obj(id+'venue','venue');
}

function switch_obj(obj_id,obj_type) {
  var newO = getObjById(obj_id);
  var mL = getObjById(obj_id + 'h');
	var oldO = getObjById('current' + obj_type);
	if ((oldO) && (obj_id != oldO.title)) {
    oldO.id = oldO.title;
//	  oldO.style.marginLeft = '-1000px';
	  oldO.style.left = '-1000px';
	}
  if (newO) {
//alert('hello');
	  newO.title = newO.id;
	  newO.id = 'current' + obj_type;
//alert(newO.style.marginLeft);
	  newO.style.background = 'url(../imagenes/fondodiv.jpg)';
  	  newO.style.color = '#FFFFFF';
	  newO.style.left = mL.value + 'px';
//alert(obj_id + ' left= ' + newO.style.left + ' hidden= ' + mL.value);
//alert('hidden= ' + mL.value);
//alert('name' + newO.name);
//alert('hello1');
//	  newO.style.margin-left = '10px';
		
	}
}

function getObjById(id) {
	if (document.getElementById) {
		x = document.getElementById(id);
	}	else if (document.all) {
		x = document.all[id];
	}
	if  (x != null) {
    return x;
	} else {
	  return false;
	}
}

function info_box_move(curr_box_id, new_box_id) {
 var c = document.getElementById(curr_box_id);
 var n = document.getElementById(new_box_id);
  alert(c.title);
  c.title = 'current';
  alert(c.title);
}
