
function setHotlinkPos(myobject, myname, myval){
	document.getElementById(myobject).style[myname] = myval;
}


// PROCEDURAL FUNCTIONS
var hotlinkTimer = 0;
var hotlinksStamp = 0;
var myxPOS = 0;
var myyPOS = 0;
var verPos = new Array();
var horPos = new Array();


function getRealPos(ele,dir)
{
	(dir=="x") ? pos = ele.offsetLeft : pos = ele.offsetTop;
	tempEle = ele.offsetParent;
	while(tempEle != null)
	{
		pos += (dir=="x") ? tempEle.offsetLeft : tempEle.offsetTop;
		tempEle = tempEle.offsetParent;
	}
	return pos;
}

function hideLayer() {
}

function getScrollX(){
	if(window.pageXOffset != null){
		return window.pageXOffset;
	} else {
		return document.body.scrollLeft;
	}
}

function getScrollY(){
	if(window.pageYOffset != null) {
		return window.pageYOffset;
	} else {
		return document.body.scrollTop;
	}
}

function hideAd(){
	clearInterval(hotlinkTimer);
	hotlinkTimer = setInterval(slowerInterval, 3000);
	hotlinkStr = "hotlink" + hotlinksStamp;
}

function slowerInterval(){
	setHotlinkPos('hotlinks', 'visibility', 'hidden');
	clearInterval(hotlinkTimer);
}

function ReplaceAll(varb, replaceThis, replaceBy){
    newvarbarray=varb.split(replaceThis);
    newvarb=newvarbarray.join(replaceBy);
    return newvarb;
}

function displayAd(indexNum,mycontent){
	verPos[indexNum] = indexNum;
	horPos[indexNum] = indexNum;

	var hotlinkStr = "hotlink" + indexNum;
	var linkRef =  document.getElementById(hotlinkStr);
        mycontent = ReplaceAll(mycontent,"dmnobieblank", "");
        mycontent = ReplaceAll(mycontent,"dmnobie", "'");
        mycontent = ReplaceAll(mycontent,"dmndoubleobie", "\"");

	clearInterval(hotlinkTimer);

	hotlinksStamp = indexNum;
	hotlinksContent  = mycontent;
        if (mycontent.indexOf("<div class=popheadtd>SPONSOR</div>") == -1)
           hotlinksContent = "<div class='pop2table'><div class='pop2headtd'>HOTLINKS</div><div class='pop2maintd'>"+mycontent+"</div><span class='pop2what'><a href='http://www.digitalmediaonlineinc.com/articles/abouthotlinksarticle.jsp' target='_blank'>add your link</a></span></div>";
		
	document.getElementById('hotlinks')['innerHTML'] = hotlinksContent;
	setHotlinkPos('hotlinks');

	var hotlinksWidth = document.getElementById('hotlinks')['offsetWidth'];
	var hotlinksHeight = document.getElementById('hotlinks')['offsetHeight'];
	var linkPosX = getRealPos(linkRef,'x') + myxPOS;
	var linkPosY = getRealPos(linkRef,'y') - hotlinksHeight + myyPOS;

	if(getScrollY() > linkPosY){
		var tempName = document.getElementById("hotlink" + hotlinksStamp);
		var tempOffset = tempName.offsetHeight;
		linkPosY += hotlinksHeight - (2*myyPOS) + tempOffset + 4;
	}

	if((getScrollX() + document.body.clientWidth) < (linkPosX + hotlinksWidth)){
		var tempOffset = (linkPosX + hotlinksWidth) - (getScrollX() + document.body.clientWidth);
		linkPosX -= tempOffset + 6;
	}

	linkPosX += verPos[hotlinksStamp];
	linkPosY += horPos[hotlinksStamp];

	var linkPosXString = linkPosX + "px";
	var linkPosYString = linkPosY + "px";
	setHotlinkPos('hotlinks', 'top', linkPosYString);
	setHotlinkPos('hotlinks', 'left', linkPosXString);
	setHotlinkPos(hotlinkStr, 'borderBottomWidth', '3px');
	setHotlinkPos('hotlinks', 'visibility', 'visible');
}
