var lineHeight;
var message="Right-clicking (ctrl-clicking) on ads has been disabled to reduce click fraud.\n\nPlease click on an ad to open it in a new window.";
var stop = false;
var currentTextValue;
var adjixad = "<a target=\"_blank\" href=\"http://web.adjix.com/AdjixAdvertiserInfo.html\">Adjix</a>&nbsp;&nbsp;Advertise with the Adjix ad network. Get paid to shrink a link.&nbsp&nbsp<a target=\"_blank\" href=\"http://web.adjix.com/AdjixAdvertiserInfo.html\">www.adjix.com</a>";

function getArgs()
{
	var args = new Object();
	var query = location.search.substring(1);
	var pairs = query.split(",");
	for (var i=0; i<pairs.length; i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos == -1) continue;
		var argname = pairs[i].substring(0,pos);
		var value = pairs[i].substring(pos+1);
		args[argname] = unescape(value);
	}
	return args;
}


function scrollIn()
{
	if (parseInt(lineHeight.bottom)<0)
	{
		lineHeight.bottom=parseInt(lineHeight.bottom) + 1 + "px";
	}
	else
	{
		lineHeight.bottom=0;
		clearInterval(start);
		if (!stop)
		{
			setTimeout("end=setInterval(\"scrollOut()\",50);", 25000);
		}
	}
}

function scrollOut()
{
	if (parseInt(lineHeight.bottom)<12)
	{
		lineHeight.bottom=parseInt(lineHeight.bottom) + 1 + "px";
	} else
	{
		if (parseInt(lineHeight.bottom)<32)
		{
			lineHeight.bottom=parseInt(lineHeight.bottom) + 2 + "px";
		} else
		{
			lineHeight.bottom=90;//33
			clearInterval(end);
			if (!stop)
			{
				setTimeout("loadAd()", 10);
				currentTextValue.innerHTML = "&nbsp;";
			} else
			{
				currentTextValue.innerHTML = adjixad;
//				currentTextValue.innerHTML = "This is the end.";
				lineHeight.bottom = "-20px";
				if (document.getElementById || document.all)
				{
					start=setInterval("scrollIn()",50);
				}
			}
		}
	}
}



function loadAd()
{
	if (document.getElementById || document.all)
	{
		lineHeight=document.getElementById? document.getElementById("ad").style : document.all.ad.style;
		var element = document.getElementById("ad");
		lineHeight.bottom = "-20px";
	}

	lineHeight.bottom = "-20px";
	currentTextValue = document.getElementById("ad");
	var req = false;
	// branch for native XMLHttpRequest object
	if(window.XMLHttpRequest && !(window.ActiveXObject))
	{
		try
		{
			req = new XMLHttpRequest();
		} catch(e)
		{
			req = false;
		}
		// branch for IE/Windows ActiveX version
	} else if(window.ActiveXObject) 
	{
		try
		{
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e)
		{
			try
			{
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e)
			{
				req = false;
			}
		}
	}
	
	
	if(req)
	{
		var lid;
		var args = getArgs();
		if (args.lid)
		{
			lid = args.lid;
		}
		req.open("GET", "http://ad.adjix.com/WebObjects/AdjixAdvertiser.woa/wa/ad?t=" + new Date().getTime() + "&lid=" + lid, false);
		req.send(null);
		if (req.status == 200)
		{
			if (!stop)
			{
				currentTextValue.innerHTML = req.responseText;
			} else
			{
				currentTextValue.innerHTML = adjixad;
			}
		}
		
	}
	if (document.getElementById||document.all)
	{
		start=setInterval("scrollIn();",50);
	}
}

function adSTO() // Ad stream timeout.
{
	setTimeout("stop = true;", 900000);
}


function eject()
{
	if (document.getElementById || document.all)
	{
	}

	var req = false;
	// branch for native XMLHttpRequest object
	if(window.XMLHttpRequest && !(window.ActiveXObject))
	{
		try
		{
			req = new XMLHttpRequest();
		} catch(e)
		{
			req = false;
		}
		// branch for IE/Windows ActiveX version
	} else if(window.ActiveXObject) 
	{
		try
		{
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e)
		{
			try
			{
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e)
			{
				req = false;
			}
		}
	}
	
	if(req)
	{
		var lid;
		var args = getArgs();
		if (args.lid)
		{
			lid = args.lid;
		}
		req.open("GET", "http://ad.adjix.com/WebObjects/AdjixAdvertiser.woa/wa/com.adjix.advertiser.EAAS/eaas?t=" + new Date().getTime() + "&lid=" + lid, false);
		req.send(null);
		if (req.status == 200)
		{
			top.location.replace(req.responseText);
		}
		
	}

}