// Common Javascript functions for my homepage
// Created by Chiezo (chiezo@onego.ru)
// Last modified 2005.12.29

function titles() // Managing pop-up hints
{
  if (document.getElementsByTagName){
    var x = document.getElementsByTagName('IMG'); // Duplicating ALT text to TITLE in images
    for (var i = 0; i < x.length; i++){
      var s = x[i].alt;
      if (s) x[i].title = s;
    }
    x = document.getElementsByTagName('A'); // Creating 'smart' links TITLE
    for (var i = 0; i < x.length; i++){
      var a = x[i];
      if ((a.parentNode.nodeName != 'IMG') && (!a.name)){
        if (a.hash) a.title = 'Закладка "' + a.hash.substr(1) + '" на этой странице';
        else if (a.protocol == 'file:') a.title = a.href.substr(a.href.lastIndexOf('/') + 1);
        else if (a.protocol == 'mailto:') a.title = 'Послать письмо: ' + a.href.substr(7);
        else a.title = a.href; // .substr(a.href.indexOf('//') + 2);
      }
    }
  }
}
function adjustBody() // Trying to get more slim and centered page context
{
  var pW = 750; // Max page content width

  if (document.body){
    var w = Math.ceil((document.body.clientWidth - pW) / 2);
    if (w < 0) w = 0;
    if (document.body.style){
      var x = document.body.style;
      x.marginLeft = w;
      x.marginRight = w;
    }
  }
}
function init()
{
  titles();
  adjustBody();
}
window.onload = init;
window.onresize = adjustBody;


