// 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: 600px; height: 602px; background: none;' scrolling='no' frameborder='0' name='joinFrame'></iframe>";
	El("joinFormDiv").innerHTML = content;
}
function PopJoinForm(url)
{
	PopUpCenter("joinFormDiv", 604, 600);
}

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 PopJoin()
{
	if (El('playerDiv'))
	{
		HideElem('playerDiv');
		El('playerContent').innerHTML='';
	}

	PopJoinForm(joinLink);
	var d = El("trailerDiv");
	if (d) d.innerHTML = oldHTML;
}

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

var oldHTML = "";

function FlashTrailer(file, w, h)
{
	var code =
	"<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" " +
	"codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" " +
	"width=\"" + w + "\" height=\"" + (h + 15) + "\" id=\"f360Trailer\" align=\"middle\">\n" +
	"	<param name=\"allowScriptAccess\" value=\"sameDomain\" />\n" +
	"	<param name=\"movie\" value=\"/trailers/player.php?vid="  + file + "&amp;movieWidth=" + w + "&amp;movieHeight=" + (h + 15) + "&amp;autoStart=0&amp;initVolume=75\" />\n" +
	"	<param name=\"menu\" value=\"false\" />\n" +
	"	<param name=\"quality\" value=\"high\" />\n" +
	"	<param name=\"bgcolor\" value=\"#000000\" />\n" +
	"	<param name=\"allowFullScreen\" value=\"true\" />\n" +
	"	<embed src=\"/trailers/player.php?vid="  + file + "&amp;movieWidth=" + w + "&amp;movieHeight=" + (h + 15) + "&amp;autoStart=0&amp;initVolume=75\" menu=\"false\" quality=\"high\" " +
			"bgcolor=\"#000000\" width=\"" + w + "\" height=\"" + (h + 15) + "\" name=\"f360Trailer\" allowFullScreen=\"true\" " +
			"align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" " +
			"pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />\n" +
	"</object>";

	var d = El("playerDiv");
	d.style.width = (w + 21) + "px";
	d.style.height = (h + 5) + "px";
	El("playerClose").style.left = (w - 8) + "px";
	El("playerContent").innerHTML = code;
	d.style.display = "block";
	FixLocation("playerDiv", (w + 21), (h + 45));
	BlockBackgroundAccess();
}

function FlashTrailerLarge(trailerFile)
{
	FlashTrailer(trailerFile + "_best", 640, 480);
}

function FlashTrailerMedium(trailerFile)
{
	FlashTrailer(trailerFile + "_high", 480, 360);
}

function FlashTrailerSmall(trailerFile)
{
	FlashTrailer(trailerFile + "_med", 320, 240);
}

// Button images stuffs
function switchimage(imgDocID,imgObjName)
{
 document[imgDocID].src = eval(imgObjName + ".src");
}

btn_members1 = new Image(1,2);btn_members1.src  = "images/btn-members.png";
btn_members2 = new Image(1,2);btn_members2.src  = "images/btn-members-up.png";
btn_join_now1 = new Image(1,2);btn_join_now1.src  = "images/btn-join-now.png";
btn_join_now2 = new Image(1,2);btn_join_now2.src  = "images/btn-join-now-up.png";
btn_next_page1 = new Image(1,2);btn_next_page1.src  = "images/btn-next-page.png";
btn_next_page2 = new Image(1,2);btn_next_page2.src  = "images/btn-next-page-up.png";
btn_last_page1 = new Image(1,2);btn_last_page1.src  = "images/btn-last-page.png";
btn_last_page2 = new Image(1,2);btn_last_page2.src  = "images/btn-last-page-up.png";
btn_next_page_bottom1 = new Image(1,2);btn_next_page_bottom1.src  = "images/btn-next-page-bottom.png";
btn_next_page_bottom2 = new Image(1,2);btn_next_page_bottom2.src  = "images/btn-next-page-bottom-up.png";
btn_join_now_bottom1 = new Image(1,2);btn_join_now_bottom1.src  = "images/btn-join-now-bottom.png";
btn_join_now_bottom2 = new Image(1,2);btn_join_now_bottom2.src  = "images/btn-join-now-bottom-up.png";

