// Short cut for getElementById()
function El(id)
{
	return document.getElementById(id);
}

function HideElem(elemId)
{
	var tmp = El(elemId);
	if (tmp) tmp.style.display = 'none';
}

function FixLocation(divId, w, h)
{
	var tmpDiv = El(divId);
	if (tmpDiv == null) return;

	var topDelta;
	// Get the scrolly delta
	if (self.pageYOffset)
		topDelta = self.pageYOffset;
	else if (document.documentElement && document.documentElement.scrollTop)
		topDelta = self.document.documentElement.scrollTop;
	else if (document.body)
		topDelta = document.body.scrollTop;
	else
		topDelta = Math.floor(h / 2);

	topDelta -= Math.floor(h / 2);

	// set the position
	if (window.innerHeight)
		tmpDiv.style.top = (window.innerHeight / 2 + topDelta) + "px";
	else if (document.documentElement.clientHeight)
		tmpDiv.style.top = (document.documentElement.clientHeight / 2  + topDelta) + "px";
	else
		tmpDiv.style.top = (300 + topDelta) + "px";

	if (window.innerWidth)
		tmpDiv.style.left = (window.innerWidth / 2 - Math.floor(w / 2)) + "px";
	else if (document.documentElement.clientWidth)
		tmpDiv.style.left = (document.documentElement.clientWidth / 2 - Math.floor(w / 2)) + "px";
}

function BlockBackgroundAccess()
{
	// block access to elements on the back
	var tmpDiv = El("fullPageBlankDiv");
	tmpDiv.style.opacity = 0.4;
	tmpDiv.style.filter = "alpha(opacity=40)";
	tmpDiv.style.top = "0px";
	tmpDiv.style.left = "0px";

	var h = 0;
	if (window.innerHeight)
		h = window.innerHeight;
	else if (document.documentElement.clientHeight)
		h = document.documentElement.clientHeight;

	if (document.body.scrollHeight > document.body.offsetHeight)
	{
		tmpDiv.style.width = document.body.scrollWidth + "px";
		tmpDiv.style.height = Math.max(h, document.body.scrollHeight) + "px";
	}
	else
	{
		tmpDiv.style.width = document.body.offsetWidth + "px";
		tmpDiv.style.height = Math.max(h, document.body.offsetHeight) + "px";
	}
	tmpDiv.style.display = "block";
}
// PopUp a div and position it at the center of the page, w and h are the width and height
function PopUpCenter(divId, w, h)
{
	// set the location
	FixLocation(divId, w, h);

	var tmpDiv = El(divId);
	if (tmpDiv == null) return;
	// show the div
	tmpDiv.style.display = "block";
	BlockBackgroundAccess();
}

function PreloadJoinForm(url)
{
	var content = "<iframe src='" + url + "' style='border: none; width: 596px; height: 536px;' scrolling='no' frameborder='0' name='joinFrame'></iframe>";
	El("joinFormDiv").innerHTML = content;
}
function PopJoinForm(url)
{
	PopUpCenter("joinFormDiv", 596, 536);
}

function ReplaceJoinLinks(url)
{
	var links = document.getElementsByTagName("A"); // get an array of all the links.
	for (var i = 0; i < links.length; i++)
	{
   		if (links[i].className == "joinPageLink")
			links[i].href = url;
	}
}

function KeepCenter(divId, w, h)
{
	FixLocation(divId, w, h);
	setTimeout("KeepCenter('" + divId + "', " + w + ", " + h + ")", 50);
}

function ShowTrailer()
{
	var cnt = "<iframe src='http://www.analdriveway.com/en/popup%20text/trailer.html' width='490' height='400' scrolling='no' frameborder='0'></iframe>"
	var tmpDiv = El("trailerMovieDiv");
	if (tmpDiv) tmpDiv.innerHTML = cnt;
	setTimeout("PopUpCenter('trailerDiv', 490, 420);", 200);
}

function HideTrailer()
{
	HideElem('trailerDiv');
	HideElem('fullPageBlankDiv');
	var tmpDiv = El("trailerMovieDiv");
	if (tmpDiv) tmpDiv.innerHTML = "&nbsp;";
}