var url = window.location.href.toLowerCase();
var sitelang = "en";
if ( url.indexOf("elizaweta") != -1 ) { sitelang = "de";}

function write_fullname() {
  if ( sitelang != "de" ){
      document.write ('Liza Stepanova');
  } else {
      document.write ('Elizaweta Stepanowa');
  }
}

function write_altspelling() {
  // Not used anymore -- replaced by toGerman
  if ( sitelang != "de" ) {
      document.write ('(sometimes spelled in Europe as <a href="http://elizaweta-stepanowa.com" target=_top>Elizaweta Stepanowa</a>)');
  } else {
      document.write ('(spelled <a href="http://liza-stepanova.com" target=_top>Liza Stepanova</a> in USA)');
  }
}

function write_lastname() {
  // Not used anymore -- replaced by toGerman
  if ( sitelang != "de" ) {
      document.write ('Ms. Stepanova');
  } else {
      document.write ('Ms. Stepanowa');
  }
}

function write_title(header) {
  if ( sitelang != "de" ) {
      document.write ('<title>Liza Stepanova, pianist - ' + header + '</title>');
  } else {
      document.write ('<title>Elizaweta Stepanowa, pianistin - ' + header + '</title>');
  }
}

function write_description() {
  if ( sitelang != "de" ) {
      document.write ('<META NAME="Description" CONTENT="Liza Stepanova (Elizaweta Stepanowa) is young critically acclaimed Russian-German-American pianist">');
  } else {
      document.write ('<META NAME="Description" CONTENT="Elizaweta Stepanowa (Liza Stepanova) is young critically acclaimed Russian-German-American pianist">');
  }
}

function toGerman () {
  if ( sitelang == "de" ){
    findAndReplace('Liza', 'Elizaweta');
    findAndReplace('Stepanova', 'Stepanowa');
  }
}

function altspelled () {
  if ( sitelang == "de" ){
    document.getElementById('altspelling').innerHTML = '(spelled in the USA as <a href="http://liza-stepanova.com" target=_top>Liza Stepanova</a>)';
  }
}

function findAndReplace(searchText, replacement, searchNode) {
//
// From: http://james.padolsey.com/javascript/find-and-replace-text-with-javascript/
//
    if (!searchText || typeof replacement === 'undefined') {
        // Throw error here if you want...
        return;
    }
    var regex = typeof searchText === 'string' ?
                new RegExp(searchText, 'g') : searchText,
        childNodes = (searchNode || document.body).childNodes,
        cnLength = childNodes.length,
        excludes = 'html,head,style,title,link,meta,script,object,iframe';
    while (cnLength--) {
        var currentNode = childNodes[cnLength];
        if (currentNode.nodeType === 1 &&
            (excludes + ',').indexOf(currentNode.nodeName.toLowerCase() + ',') === -1) {
            arguments.callee(searchText, replacement, currentNode);
        }
        if (currentNode.nodeType !== 3 || !regex.test(currentNode.data) ) {
            continue;
        }
        var parent = currentNode.parentNode,
            frag = (function(){
                var html = currentNode.data.replace(regex, replacement),
                    wrap = document.createElement('div'),
                    frag = document.createDocumentFragment();
                wrap.innerHTML = html;
                while (wrap.firstChild) {
                    frag.appendChild(wrap.firstChild);
                }
                return frag;
            })();
        parent.insertBefore(frag, currentNode);
        parent.removeChild(currentNode);
    }
}

