var Message = null;

if( registerEvent )
{
	registerEvent( window, 'load', function() {
		top.Message = new Dymek('Message', '<div class="accredhov">{MESSAGE}</div>');
		var images = document.getElementsByTagName('img');
		for (var i=0; i<images.length; i++){
			var image = images[i];
			
			var titleAttribute = String(image.getAttribute('alt'));
//			alert(titleAttribute);
			if( titleAttribute != '' && titleAttribute != null && titleAttribute != 'null' )
				image.onmouseover = showComment;
				image.onmouseout = hideComment;
				image.onmousemove = moveComment;
		}
	})
}

// Defs
function showComment(e)
{
	if (!e) var e = window.event;
	var tg = (window.event) ? e.srcElement : e.target;
	var posx = 0;
	var posy = 0;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	//alert( posx+ ':' + posy );
	Message.show(tg.getAttribute('alt')?tg.getAttribute('alt'):tg.getAttribute('alt'),posx+5, posy+10);
}

function moveComment(e)
{
	if (!e) var e = window.event;
	var tg = (window.event) ? e.srcElement : e.target;
	var posx = 0;
	var posy = 0;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	//alert( posx+ ':' + posy );
	Message.move(posx+5, posy+10);
}

function hideComment(e)
{
	Message.hide();
}

function getElementPosition(elem) {
    //var offsetTrail = document.getElementById(elemID);
    var offsetTrail = elem;
    var offsetLeft = 0;
    var offsetTop = 0;
    while (offsetTrail) {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
    }
    if (navigator.userAgent.indexOf("Mac") != -1 && 
        typeof document.body.leftMargin != "undefined") {
        offsetLeft += document.body.leftMargin;
        offsetTop += document.body.topMargin;
    }
    return {left:offsetLeft, top:offsetTop};
}

function Dymek(name, htmlString) {
	this.contObject;
	this.contObject = document.createElement('div');
	this.contObject = document.body.appendChild(this.contObject);
	this.contObject.style.visibility = 'hidden';
	this.contObject.style.display = 'none';
//	this.contObject.style.float = 'left';
	this.contObject.style.overflow = 'hidden';
	this.contObject.style.position = 'absolute';
	this.contObject.style.zIndex = '10';
	this.contObject.style.top = '1px';
	this.contObject.style.left = '1px';
	this.htmlString = new String(htmlString);
	this.name = name;
	this.showing = false;
	this.opacity = 0;
	
  this.contObject.style.opacity = (this.opacity / 100);
  this.contObject.style.MozOpacity = (this.opacity / 100);
  this.contObject.style.KhtmlOpacity = (this.opacity / 100);
  this.contObject.style.filter = "alpha(opacity=" + this.opacity + ")";
	
	this.show = function (message, x, y) {
		maxWidth = document.body.clientWidth;
		this.contObject.innerHTML = this.htmlString.replace("\{MESSAGE\}", message);
		this.contObject.style.visibility = 'visible';
		this.contObject.style.display = 'block';
		this.contObject.style.width = maxWidth-x;
//		this.contObject.style.borderWidth = '1px';
		this.contObject.style.overflow = 'hidden';
		this.contObject.style.top = y+'px';
		this.contObject.style.left = x+'px';
		if( !this.showing )
		{
			this.showing = true;
			this.highlight();
		}
	}
	
	this.highlight = function () {
		if( this.showing == true && this.opacity < 100 )
		{
			this.opacity += 10;
			this.setOpacity(this.opacity);
			setTimeout( this.name+'.highlight()', 10 );
		}
	}
	
	this.fade = function () {
		if( this.showing == false && this.opacity > 0 )
		{
			this.opacity -= 10;
			this.setOpacity(this.opacity);
			setTimeout( this.name+'.fade()', 10 );
		}
	}
	
	this.hide = function () {
		if( this.showing )
		{
			this.showing = false;
			this.fade();
		}
	}
	
	this.move = function (x,y){
		maxWidth = document.body.clientWidth;
		this.contObject.style.width = maxWidth-x;
		this.contObject.style.top = y+'px';
		this.contObject.style.left = x+'px';
	}
		
	this.setOpacity = function(opacity) {
		var object = this.contObject.style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
	}
}
