/***************************************************************************
 *                                L2Spirit V7
 *                            ********************
 *   begin                : Monday, Nov 1, 2008
 *   copyright            : (C) 2008-2009 Skatershi <admin@l2spirit.com>
 *   author               : Skatershi
 *
 ***************************************************************************/
/* ########################################################################
Get the ID of the selected element (Main function).
######################################################################## */
var dodefault = document.getElementById;

function getId(id)
{
	return (dodefault) ? document.getElementById(id) : document.all[id] || document.layers[id];
}
/* ########################################################################
Load and write the selected flash object in a specified div Id.
######################################################################## */
var swfobj;
var swfpath    = new String();
var swfname    = new String();
var swfwidth   = new String();
var swfheight  = new String();
var swffullscr = new String();

function getFlashObj(obj)
{
	if (obj == "gallery")
	{
		swfpath    = "common/swf/L2SpiritGEngine.swf";
		swfname    = "L2SpiritGEngine";
		swfwidth   = "500";
		swfheight  = "350";
		swffullscr = "true";
	}
	else if (obj == "donate")
	{
		swfpath    = "common/swf/Donate.swf";
		swfname    = "Donate";
		swfwidth   = "380";
		swfheight  = "100";
		swffullscr = "false";
	}
	else
	{
		swfpath    = "common/swf/Discover.swf";
		swfname    = "Discover";
		swfwidth   = "391";
		swfheight  = "89";
		swffullscr = "false";
	}
	//Load and define the SWF file and his parameters
	swfobj = new SWFObject(swfpath, swfname, swfwidth, swfheight, "9", "#FFFFFF");
	swfobj.addVariable("flashVarText", "");
	swfobj.addParam("allowFullScreen", swffullscr);
	swfobj.addParam("wmode", "transparent");
	swfobj.write(obj);
}

/* ########################################################################
Hide/Show a <div> content like a hint text/images/table.
######################################################################## */
var hdivLeft = new String();                  // X Position
var hdivTop  = new String();                  // Y Position
var hdivName = new String();                  // Hint div name
var hMSIE    = 'Microsoft Internet Explorer'; // Bullshit M$ Browser
var hBool    = false;                         // Common Boolean
var hdMove   = document.onmousemove;          // Get the current mouse position

function hintMove(e)
{
	if (hBool && hdivName != null)
	{
		if (navigator.appName != hMSIE) // The browser is not Internet Explorer
		{
			if (hdivName != 'imghint') // The imghint div is different, because image != text
			{
				hdivLeft = e.pageX + 5  + "px";  // Write the X position of the div
				hdivTop  = e.pageY + 10 + "px";  // Write the Y position of the div
			}
			else
			{
				hdivLeft = e.pageX + 5   + "px";
				hdivTop  = e.pageY - 285 + "px";
			}
    			getId(hdivName).style.left = hdivLeft;
    			getId(hdivName).style.top  = hdivTop;
		}
		else // M$ Browser come !
		{
			if (hdivName != 'imghint')
			{
				hdivLeft = 20 + event.clientX + document.body.scrollLeft + "px";
				hdivTop  = 10 + event.clientY + document.body.scrollTop  + "px";
			}
			else
			{
				hdivLeft = event.clientX + document.documentElement.scrollLeft + "px";
				hdivTop  = event.clientY + document.documentElement.scrollTop  + "px";
			}
			getId(hdivName).style.left = hdivLeft;
			getId(hdivName).style.top  = hdivTop;
		}
	}
}

function getHint(text, div) // Show the hint with the text and div ref.
{
	if (!hBool)
	{
		hdivName = div;
		getId(hdivName).style.visibility  = "visible"; // Show the div
		if (text != 'null') // Used by the 'sArea" div only
			getId(hdivName).innerHTML = text; // Write the text into the div :)
		hBool = true;
	}
	document.onmousemove = hintMove; // The div follow the mouse, it's so funny heh ?
}

function hideHint(div) // Hide the selected hint
{
	if (hBool)
	{
		getId(hdivName).style.visibility = "hidden"; // Hide the div
		hBool = false;
	}
	hdivName = null;
	document.onmousemove = hdMove; // Return to default move
}

/* ########################################################################
Change a <div> content on the html "onclick" event.
######################################################################## */
var scdiv;
var sctarget;

function switchCnt(div, id)
{
	scdiv = getId(div);
	sctarget = getId(div + id).innerHTML;
	scdiv.innerHTML = sctarget;
	scdiv.style.visibility  = "visible";
}

/* ########################################################################
Change a <div> content on the html "onclick" event.
######################################################################## */
var swaccdiv = null;
var swtarget = null;

function switchDiv(id)
{
	swaccdiv = getId("AccCnt");
	swtarget = getId((id == 1) ? "hAccCnt1" : "hAccCnt2").innerHTML;
	swaccdiv.innerHTML = swtarget;
}

/* ########################################################################
Change the image source on "onmouseover" and "onmouseout" events.
######################################################################## */
var imginit = false;
var imgcache;

function switchImg(imgn, imgom)
{
	if (!imginit)
	{
		imgn      = document[imgn];
		imgom     = document[imgom];
		imgcache  = imgn.src;
		imgn.src  = imgom.src;
		imginit   = true;
	}
	else
	{
		imgom     = document[imgom];
		imgom.src = imgcache;
		imgcache  = null;
		imginit   = false;
	}
}

/* ########################################################################
Get the donate window layer in the donate page. Using JWin and WPro lib.
######################################################################## */
var dfunc;

function showDonate(dId, dTitle)
{
	dfunc = (navigator.appName == hMSIE) ? showWindow('D', dId, dTitle) : showWindow('wDwl_' + dId, dTitle);
	dfunc;
}