// 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;
}

// 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);
}

// JavaScript Fade Transition Slideshow 940x320
function ss_changeSlide() {
	fgDiv = document.getElementById("slideshow_fgimage");
	bgDiv = document.getElementById("slideshow_bgimage");
	if(ss_imageOn < ss_images.length-1)
		ss_imageOn ++;
	else
		ss_imageOn = 0;
	fgDiv.innerHTML = bgDiv.innerHTML.replace("ss_fadeSlide(100)","");
	fgDiv.style.opacity = 1;
	fgDiv.style.filter = "alpha(opacity=100)";
	fgDiv.style.display = "block";
	bgDiv.innerHTML = "<img src=\"cm/images/" + ss_images[ss_imageOn] + "\" width=\"940\" height=\"320\" border=\"0\" alt=\"\" onload=\"ss_fadeSlide(100)\">";
}

function ss_fadeSlide(opac) {
	fgDiv = document.getElementById("slideshow_fgimage");
	if(opac > 0) {
		newOpac = opac - 10;
		fgDiv.style.opacity = newOpac/100;
		fgDiv.style.filter = "alpha(opacity=" + newOpac + ")";
		setTimeout("ss_fadeSlide(newOpac)",100);
	}
	else {
		snumDiv = document.getElementById("slideshow_snum");
		stitleDiv = document.getElementById("slideshow_stitle");
		slinkDiv = document.getElementById("slideshow_linkarea");
		fgDiv.style.display = "none";
		snumDiv.innerHTML = ss_imageOn+1 + " of " + ss_images.length;
		stitleDiv.innerHTML = ss_titles[ss_imageOn];
		snumDiv.style.display = "block";
		stitleDiv.style.display = "block";
		// Start Linking Code
		if(ss_links[ss_imageOn] != "") {
			slinkDiv.style.cursor = "pointer";
			slinkDiv.onclick = function() {
				if(ss_linktargets[ss_imageOn] != "")
					var x = window.open(ss_links[ss_imageOn],ss_linktargets[ss_imageOn]);
				else
					var x = window.open(ss_links[ss_imageOn],"_self");
			};
		}
		else {
			slinkDiv.style.cursor = "";
			slinkDiv.onclick = function() {return false};
		}
		// End Linking Code
		setTimeout("ss_changeSlide()",5000);
	}
}


// JavaScript Fade Transition Portfolio 940x185
function pf_changeSlide(idx) {
	fgDiv = document.getElementById("portfolio_fgimage");
	bgDiv = document.getElementById("portfolio_bgimage");
	fgDiv.innerHTML = bgDiv.innerHTML.replace("pf_fadeSlide(100)","");
	fgDiv.style.opacity = 1;
	fgDiv.style.filter = "alpha(opacity=100)";
	fgDiv.style.display = "block";
	bgDiv.innerHTML = "<img src=\"cm/images/" + pf_items[idx][0] + "\" width=\"940\" height=\"185\" border=\"0\" alt=\"\" onload=\"pf_fadeSlide(100)\">";
		contentDiv = document.getElementById("portfolio_infocontainer");
		contentDiv.innerHTML = pf_items[idx][2];
}

function pf_fadeSlide(opac) {
	fgDiv = document.getElementById("portfolio_fgimage");
	if(opac > 0) {
		newOpac = opac - 5;
		fgDiv.style.opacity = newOpac/100;
		fgDiv.style.filter = "alpha(opacity=" + newOpac + ")";
		setTimeout("pf_fadeSlide(newOpac)",50);
	}
}

/*
function buildPortfolioItem(img,thumb,info) {
	var pf_idx = pf_items.length;
	pf_items[pf_idx] = new Array();
	pf_items[pf_idx][0] = img;
	pf_items[pf_idx][1] = thumb;
	pf_items[pf_idx][2] = info;
}

function activatePortfolioItem(idx) {
	for(i=0; i < pf_items.length; i++) {
		var ithumb = document.getElementById("pf_icon" + i);
		if(i == idx) {
			ithumb.className = "portfolio_activethumbholder";
			pf_changeSlide(i);
		}
		else {
			ithumb.className = "portfolio_thumbholder";
		}
	}
}

function initPortfolio() {
	var ic_code = "";
	for(i=0; i < pf_items.length; i++) {
		ic_code += "<div id=\"pf_icon" + i + "\" class=\"portfolio_thumbholder\"><a href=\"#\" onclick=\"activatePortfolioItem(" + i + "); return false\"><img src=\"cm/images/" + pf_items[i][1] + "\" width=\"52\" height=\"35\" border=\"0\" alt=\"\" class=\"portfolio_thumb\" /></a></div>\n";
	}
	document.getElementById("portfolio_iconcontainer").innerHTML = ic_code;
	activatePortfolioItem(0);
}
*/

function buildPortfolioItem(img,thumb,info) {
	var pf_idx = pf_items.length;
	pf_items[pf_idx] = new Array();
	pf_items[pf_idx][0] = img;
	pf_items[pf_idx][1] = thumb;
	pf_items[pf_idx][2] = info;
}

function activatePortfolioItem(idx) {
	for(i=0; i < pf_items.length; i++) {
		var ithumb = document.getElementById("pf_icon" + i);
		if(i == idx) {
			ithumb.className = "portfolio_activethumbholder";
			pf_changeSlide(i);
		}
		else {
			ithumb.className = "portfolio_thumbholder";
		}
	}
}

function initPortfolio() {
	var ic_code = "";
	for(i=0; i < pf_items.length; i++) {
		ic_code += "<div id=\"pf_icon" + i + "\" class=\"portfolio_thumbholder\"><a href=\"#\" onclick=\"activatePortfolioItem(" + i + "); return false\"><img src=\"cm/images/" + pf_items[i][1] + "\" width=\"52\" height=\"35\" border=\"0\" alt=\"\" class=\"portfolio_thumb\" /></a></div>\n";
	}
	document.getElementById("portfolio_iconcontainer").innerHTML = ic_code;
	activatePortfolioItem(0);
}