﻿function BuildMenu() {
    try {
        $('main-menu').childElements().each(function(i) {
            if (i.firstChild.tagName && i.firstChild.tagName.toLowerCase() == 'a') {
                var txt = $(i.firstChild).innerHTML.toLowerCase();
                txt = txt.replace(/ /ig, '-');
                txt += '.png';
                txt = 'tti-' + txt;
                //var img = document.createElement("img");
                //img.src = 'images/' + txt;
                //$(this.firstChild).empty();
                i.firstChild.innerHTML = '<img src="' + 'images/' + txt + '" />';
            }
        });
        if (Prototype.Browser.IE) {
            $('main-menu').lastChild.className = 'last-child';
        }
    } catch (er) { alert(er.message); }
}

function TextToImage() {
    $$('.text-to-image').each(function(i) {
        var txt = $(i).innerHTML.toLowerCase();
        txt = txt.replace(/^\s+|\s+$/g,"");
        txt = txt.replace(/ /ig, '-').replace(/&/ig, '').replace(/\?/ig, '');
        txt = 'tti-' + txt + '.png';
       // var img = document.createElement("img");
        //img.src = 'images/' + txt;
        $(i).innerHTML = '<img src="images/' + txt + '" />';
        //$(i).appendChild(img);
    });
}

Element.addMethods({  
  getInnerText: function(element) {
    element = $(element);
    return element.innerText && !window.opera ? element.innerText
      : element.innerHTML.stripScripts().unescapeHTML().replace(/[\n\r\s]+/g, ' ');
  }
});

Event.observe(window, "load", BuildMenu);
Event.observe(window, "load", TextToImage);