/*

  General scripts to animate and manage the pages

*/

// Says if the current web browser is Internet Explorer
var isIE = (document.attachEvent ? true : false);

// Shortcut to get an element from the page
function $(id) {
  return document.getElementById(id);
}

// Changes the style of a menu item when mouse enters it
function menu_over(item) {
  item.className = 'menu_over';
}

// Changes back the style of a menu item when the mouse leaves it
function menu_out(item) {
  item.className = 'menu_item';
}

// Launches every action that has to be taken upon page load
function body_load() {
  select_menuItem();
  //column_autosize();
}

// Sets the style for the menu item corresponding to current page displayed
function select_menuItem() {
  var currentPage = $('pageName').innerHTML;
  $(currentPage).className = 'menu_selected';
  if (isIE) {
    $(currentPage).onclick = '';
    $(currentPage).onmouseover = '';
    $(currentPage).onmouseout = '';
  } else {
    $(currentPage).setAttribute('onclick', '');
    $(currentPage).setAttribute('onmouseover', '');
    $(currentPage).setAttribute('onmouseout', '');
  }
}

// Resizes the shorter of 2 columns to match their height
function column_autosize() {
  if ($('column_left') == undefined || $('column_right') == undefined)
    return;
    
  var hL, hR, delta;
  hL = $('column_left').style.height;
  hR = $('column_right').style.height;
  delta = hL - hR;
  alert('l = '+hL+'\nr = '+hR+'\nd = '+delta+'\nbas = '+$('bottom_column').style.top );
  if (delta > 0) {
    hR += delta;
  } else {
    hL -= delta;
  }
  $('column_left').style.height = hL + 'px';
  $('column_right').style.height = hR + 'px';
}

// Sends to another location
function goto(elt) {
  var id = elt.getAttribute('id');
  document.location.replace(id);
}

// Gets the pictures information
function get_pictures() {
  var arrImg = document.getElementsByTagName('IMG');
  for (i = 0; i < arrImg.length; i++) {
    if (arrImg[i].getAttribute('alt') != null && arrImg[i].getAttribute('alt') != '') {
      id = arrImg[i].getAttribute('id');
      arrAlt[id] = arrImg[i].alt;
      arrSrc[id] = arrImg[i].src;
    }
  }
}

var arrAlt = new Array();
var arrSrc = new Array();
// Changes the displayed picture
function swap_picture(id) {
  key = id;
  if (key == undefined) {
    for (i in arrAlt) {
      key = i;
      break;
    }
  }
  $('titreApercu').innerHTML = arrAlt[key];
  $('imgApercu').alt = arrAlt[key];
  $('imgApercu').src = arrSrc[key];
  $('lnApercu').href = arrSrc[key];
  $('description').innerHTML = $('desc_'+key).innerHTML;
}

/* Removes borders on images */
function clean_borders() {
  var arrImg = document.getElementsByTagName('IMG');
  for (i = 0; i < arrImg.length; i++) {
    arrImg[i].style.border = '0';
  }
}

