// Preload MouseOver Images
var use_images = new Array("");
var pl_images = new Array();
for(i=0;i<use_images.length;i++)
{
   pl_images[i] = new Image();
   pl_images[i].src = "images/" + use_images[i];
}

// SubMenu Operation
var submenuin = "";
var submenutime = 100;
function showSubMenu(menuID)
{
   submenuin = menuID;
   document.getElementById(menuID).style.display = "block";
   document.getElementById(menuID).style.zIndex = 5;
}
function hideSubMenu(menuID)
{
   document.getElementById(menuID).style.zIndex = 4;
   setTimeout("doHideSubMenu('" + menuID + "')",submenutime);
   submenuin = "";
}
function doHideSubMenu(menuID)
{
   if(submenuin != menuID)
      document.getElementById(menuID).style.display = "none";
}
function getTopNode(linkElem)
{
   tn = "";
   le = linkElem;
   while (tn != "TABLE")
   {
      le = le.parentNode;
	  tn = le.tagName;
   }
   return le.id;
}

// SubMenu International Address Operation
var submenuin1 = "";
var submenutime1 = 1400;
function showSubMenuAd(menuID)
{
   submenuin1 = menuID;
   document.getElementById(menuID).style.display = "block";
   document.getElementById(menuID).style.zIndex = 5;
}
function hideSubMenuAd(menuID)
{
   document.getElementById(menuID).style.zIndex = 4;
   setTimeout("doHideSubMenu('" + menuID + "')",submenutime1);
   submenuin1 = "";
}
function doHideSubMenuAd(menuID)
{
   if(submenuin1 != menuID)
      document.getElementById(menuID).style.display = "none";
}
function getTopNode(linkElem)
{
   tn = "";
   le = linkElem;
   while (tn != "TABLE")
   {
      le = le.parentNode;
	  tn = le.tagName;
   }
   return le.id;
}
// Flash Detection
function hasFlashVersion(theVersion)
{
   if(!self["MM_FlashCanPlay_" + theVersion])
      return false;
   else
      return true;
}
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
for(i=3;i<=10;i++)
{
   if (plugin)
   {
      var words = navigator.plugins["Shockwave Flash"].description.split(" ");
      for(j=0; j<words.length; j++)
      {
         if (isNaN(parseInt(words[j])))
            continue;
         self["MM_PluginVersion_" + i] = words[j]; 
      }
      self["MM_FlashCanPlay_" + i] = self["MM_PluginVersion_" + i] >= i;
   }
   else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.appVersion.indexOf("Win") != -1))
   {
      document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
      document.write('on error resume next \n');
      document.write('MM_FlashCanPlay_' + i + ' = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & ' + i + ')))\n');
      document.write('</SCR' + 'IPT\> \n');
   }
}

// Flash Embedding
function insertFlashApp(theFile, theWidth, theHeight, theFlashVersion, theAlternateCode, theBGColor, theQuality, theID, theWindowMode)
{
   if(!theFlashVersion || !parseInt(theFlashVersion) || parseInt(theFlashVersion) == "")
      theFlashVersion = 3;
   if((!theBGColor && theBGColor != 0) || theBGColor == "")
      theBGColor = "#FFFFFF";
   if((!theQuality && theQuality != 0) || theQuality == "")
      theQuality = "high";

   if(hasFlashVersion(parseInt(theFlashVersion)) && !(!theFile && theFile != 0) && theFile != "" && !(!theWidth && theWidth != 0) && theWidth != "" && !(!theHeight && theHeight != 0) && theHeight != 0)
   {
      var theFlashEmbedCode = "<OBJECT CLASSID=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"\n"
         + "	CODEBASE=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=" + theFlashVersion + ",0,0,0\"\n";

      if(!(!theID && theID != 0) && theID != "")
         theFlashEmbedCode += "	ID=\"" + theID + "\"\n";

      theFlashEmbedCode += "	WIDTH=\"" + theWidth + "\"\n"
         + "	HEIGHT=\"" + theHeight + "\"\n";

      theFlashEmbedCode += "	>\n"
      + "	<PARAM NAME=\"movie\" VALUE=\"" + theFile + "\">\n"
      + "	<PARAM NAME=\"quality\" VALUE=\"" + theQuality + "\">\n"
      + "	<PARAM NAME=\"bgcolor\" VALUE=\"" + theBGColor + "\">\n";

      if(!(!theWindowMode && theWindowMode != 0) && theWindowMode != "")
         theFlashEmbedCode += "	<PARAM NAME=\"wmode\" VALUE=\"" + theWindowMode + "\">\n";

      theFlashEmbedCode += "	<EMBED SRC=\"" + theFile + "\"\n";

      if(!(!theID && theID != 0) && theID != "")
         theFlashEmbedCode += "		NAME=\"" + theID + "\"\n";

      theFlashEmbedCode += "		WIDTH=\"" + theWidth + "\"\n"
         + "		HEIGHT=\"" + theHeight + "\"\n"
         + "		QUALITY=\"" + theQuality + "\"\n"
         + "		BGCOLOR=\"" + theBGColor + "\"\n";

      if(!(!theWindowMode && theWindowMode != 0) && theWindowMode != "")
         theFlashEmbedCode += "		WMODE=\"" + theWindowMode + "\"\n";

      theFlashEmbedCode += "		TYPE=\"application/x-shockwave-flash\"\n"
         + "		PLUGINSPAGE=\"http://www.macromedia.com/go/getflashplayer\">\n"
         + "	</EMBED>\n"
         + "</OBJECT><BR>";

      document.write(theFlashEmbedCode);
   }
   else if(theAlternateCode)
      document.write(theAlternateCode);
}

// Menu slider variables
var theSlider, slider_width, slider_halfwidth, slider_defaultposition, slider_currentposition, slider_targetposition, slider_moveID;
var slider_speed = 6;
var slider_initialized = 0;

function generateMoveID()
{
	var newid = Math.random();
	if(newid == slider_moveID)
		return generateMoveID();
	else
	{
		slider_moveID = newid;
		return newid;
	}
}

// Move the menu slider
function sliderMoveTo(thePos,theMoveId)
{
	if(slider_initialized)
	{
		if(theMoveId == slider_moveID)
		{
			slider_currentposition = parseInt(theSlider.style.left) + slider_halfwidth;
			slider_targetposition = thePos;
			if(slider_currentposition != slider_targetposition)
			{
				var totaldistance = Math.abs(slider_targetposition - slider_currentposition);
				var traveldistance = Math.max(totaldistance/slider_speed,1);
				if(slider_currentposition > slider_targetposition)
					var slider_midposition = slider_currentposition - traveldistance;
				else
					var slider_midposition = slider_currentposition + traveldistance;
				slider_currentposition = slider_midposition;
				theSlider.style.left = slider_currentposition - slider_halfwidth + "px";
				setTimeout("sliderMoveTo(" + thePos + "," + theMoveId + ")",20);
			}
		}
	}
	else
		setTimeout("sliderMoveTo(" + thePos + "," + theMoveId + ")",20);
}

// Make sure that the menu slider's default position is actually its destination
function sliderReturnCheck(theMoveId)
{
	if(theMoveId == slider_moveID)
	{
		sliderMoveTo(slider_defaultposition,theMoveId);
	}
}

// Return the menu slider to its default position
function sliderReturn(theMoveId)
{
	setTimeout("sliderReturnCheck(" + theMoveId + ")",100);
}

// Initialize the menu slider
function sliderInit(defaultPos)
{
	theSlider = document.getElementById("menuslider");
	slider_width = parseInt(theSlider.offsetWidth);
	slider_halfwidth = Math.floor(slider_width/2);
	slider_defaultposition = defaultPos;
	slider_currentposition = defaultPos;
	slider_targetposition = defaultPos;
	theSlider.style.left = defaultPos - slider_halfwidth + "px";
	slider_initialized = 1;
}

// Determine a button's center position
function getBtnPosition(theButn,theButnName)
{
	if(theButnName == null)
		var buttonObj = theButn;
	else
		var buttonObj = document.getElementById(theButnName);
	var slider_zeroposition = parseInt(document.getElementById("headdiv").offsetLeft);
	var btn_position = parseInt(buttonObj.offsetLeft);
	var btn_relposition = btn_position - slider_zeroposition;
	var btn_width = parseInt(buttonObj.offsetWidth);
	var btn_centerposition = Math.floor(btn_width/2) + btn_relposition;
	return btn_centerposition;
}
