/* 
Sweet Titles (c) Dustin Diaz <http://www.dustindiaz.com>
Creative Commons 2005 <http://creativecommons.org/licenses/by-sa/2.5/>
*/
Array.prototype.inArray = function (value) {
    for (var i = 0; i < this.length; i += 1) {
        if (this[i] === value) {
            return true;
        }
    }
    return false;
};
var sweetTitles = {
    x: 0,
    y: 0,
    obj: null,
    tip: null,
    active: 0,
    init: function () {
        this.tip = document.createElement('div');
        this.tip.id = 'toolTip';
        this.tip.style.top = '0';
        this.tip.style.visibility = 'hidden';
        document.getElementsByTagName('body')[0].appendChild(this.tip);
        var area, areas = document.getElementsByTagName('area'), i;
        for (i = 0; (area = areas[i]); i += 1) {
            area.onmouseover = this.tipOver;
            area.onmouseout = this.tipOut;
            area.setAttribute('state', area.title);
            area.removeAttribute('title');
            area.setAttribute('rep', area.getAttribute('alt'));
            area.removeAttribute('alt');
        }
    },
    updateXY: function (e) {
        if (document.captureEvents) {
            sweetTitles.x = e.pageX;
            sweetTitles.y = e.pageY;
        } else if (window.event.clientX) {
            sweetTitles.x = window.event.clientX + document.documentElement.scrollLeft;
            sweetTitles.y = window.event.clientY + document.documentElement.scrollTop;
        }
    },
    tipOut: function () {
        if (window.tID) {
            clearTimeout(window.tID);
        }
        if (window.opacityID) {
            clearTimeout(window.opacityID);
        }
        sweetTitles.tip.style.visibility = 'hidden';
    },
    checkNode: function () {
        var trueObj = this.obj;
        if (trueObj.nodeName.toLowerCase() == 'area') {
            return trueObj;
        } else {
            return trueObj.parentNode;
        }
    },
    tipOver: function (e) {
        sweetTitles.obj = this;
        window.tID = window.setTimeout('sweetTitles.tipShow()', 500);
        sweetTitles.updateXY(e);
    },
    tipShow: function () {		
        var tipTop = parseInt(Number(this.y) + 15, 10);
        var tipLeft = parseInt(Number(this.x) + 10, 10);
        var element = this.checkNode();
        var state = element.getAttribute('state');
        var salesRep = 'Sales Rep: <strong>' + element.getAttribute('rep') + '</strong>';
        var salesText = '';//'<em>View products for ' + state + '</em>';
        this.tip.innerHTML = '<h5>' + state + '</h5><p>' + salesRep + salesText + '</p>';
        if (parseInt(document.documentElement.clientWidth + document.documentElement.scrollLeft, 10) < parseInt(this.tip.offsetWidth + tipLeft, 10)) {
            this.tip.style.left = parseInt(tipLeft - (this.tip.offsetWidth + 10), 10) + 'px';
        } else {
            this.tip.style.left = tipLeft + 'px';
        }
        if (parseInt(document.documentElement.clientHeight + document.documentElement.scrollTop, 10) < parseInt(this.tip.offsetHeight + tipTop, 10)) {
            this.tip.style.top = parseInt(tipTop - (this.tip.offsetHeight + 10), 10) + 'px';
        } else {
            this.tip.style.top = tipTop + 'px';
        }
        this.tip.style.visibility = 'visible';
        this.tip.style.opacity = '.1';
        this.tipFade(10);
    },
    tipFade: function (value) {
        value = parseInt(value + 10, 10);
        if (value < 90) {
            this.tip.style.opacity = '.' + value;
            this.tip.style.filter = 'alpha(opacity: ' + value + ')';
            window.opacityID = window.setTimeout('sweetTitles.tipFade(' + value + ')', 20);
        } else { 
            this.tip.style.opacity = '.90';
            this.tip.style.filter = 'alpha(opacity: 90)';
        }
    }
};
document.addEvent('ready', function () {
    document.getElementById('content-sidebar').getElementsByTagName('img')[0].removeAttribute('alt');
    document.getElementById('content-sidebar').getElementsByTagName('img')[1].removeAttribute('alt');
    sweetTitles.init();
});
