//
//
var originalFeatureImage;
var originalFeatureImageW;
var originalFeatureImageH;
var ActiveReplacement;

function xGetElementById(e)
{
  if(typeof(e)!='string') return e;
  if(document.getElementById) e=document.getElementById(e);
  else if(document.all) e=document.all[e];
  else e=null;
  return e;
}



function my_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

var imagenew;
var imageW;
var imageH;

function previewFeatureImage( imagenew_c, imageW_c, imageH_c ) {

imagenew =imagenew_c;
imageW =imageW_c;
imageH =imageH_c;

var W3CDOM = (document.createElement && document.getElementsByTagName);
	if (!W3CDOM) { 
		alert("Your Browser does not support Javascript!");
		return;
	}
	/////
	
	var aImg = [imagenew];
	var ip = null;
	ip = new ImagePreloader(aImg, onPreload);
}

function doRestoreFeatureImage(imagenew ) {
	srcImage = xGetElementById("feature_image");
	srcImage.src = imagenew;
	srcImage.width = originalFeatureImageW;
	srcImage.height = originalFeatureImageH;
}

function MM_clearTimeout() {
	if (mmHideMenuTimer) clearTimeout(mmHideMenuTimer);
	mmHideMenuTimer = null;
	mmDHFlag = false;
}

function My_startTimeout() {
	if( ActiveReplacement ) {
		mmStart = new Date();
		mmDHFlag = true;
		mmHideMenuTimer = setTimeout("mmDoHide()", 5500);
	}
}

function mmDoHide() {
	if (!mmDHFlag || !ActiveReplacement) return;
	var elapsed = new Date() - mmStart;
	var timeout = 5500;
	if (elapsed < timeout) {
		mmHideMenuTimer = setTimeout("mmDoHide()", timeout+100-elapsed);
		return;
	}
	mmDHFlag = false;
	doRestoreFeatureImage(originalFeatureImage);
	ActiveReplacement = 0;
}


//=============================================================================
// Image Preloader
function ImagePreloader(images,callback)
{
	// store the callback
	this.callback = callback;

	// initialize internal state.
	this.nLoaded = 0;
	this.nProcessed = 0;
	this.aImages = new Array;

	// record the number of images.
	this.nImages = images.length;

	// for each image, call preload()
	for ( var i = 0; i < images.length; i++ ) 
		this.preload(images[i]);
}
ImagePreloader.prototype.preload = function(image)
{
	// create new Image object and add to array
	var oImage = new Image;
	this.aImages.push(oImage);
	
	// set up event handlers for the Image object
	oImage.onload = ImagePreloader.prototype.onload;
	oImage.onerror = ImagePreloader.prototype.onerror;
	oImage.onabort = ImagePreloader.prototype.onabort;
	
	// assign pointer back to this.
	oImage.oImagePreloader = this;
	oImage.bLoaded = false;
	oImage.source = image;
	
	// assign the .src property of the Image object
	oImage.src = image;
}
ImagePreloader.prototype.onComplete = function()
{
	this.nProcessed++;
	if ( this.nProcessed == this.nImages )
		this.callback(this.aImages);
}
ImagePreloader.prototype.onload = function()
{
	this.bLoaded = true;
	this.oImagePreloader.nLoaded++;
	this.oImagePreloader.onComplete();
}
ImagePreloader.prototype.onerror = function()
{
	this.bError = true;
	this.oImagePreloader.onComplete();
}
ImagePreloader.prototype.onabort = function()
{
	this.bAbort = true;
	this.oImagePreloader.onComplete();
}




////


function onPreload(aImages, nImages)

{
	srcImage = xGetElementById('feature_image');
//	BackUp 
	if (!originalFeatureImage) {
		originalFeatureImageW=srcImage.width;
		originalFeatureImageH=srcImage.height;
		originalFeatureImage = srcImage.src;
	}

	srcImage.width=imageW;
	srcImage.height=imageH;
	srcImage.src = imagenew;
	srcImage.alt = " ";	

	ActiveReplacement = 1;
}





startList = function()
{
     if (document.all&&document.getElementById)
     {
          navRoot = document.getElementById("nav");
          for (i=0; i<navRoot.childNodes.length; i++)
          {
               node = navRoot.childNodes[i];
               if (node.nodeName=="LI")
               {
                    node.onmouseover=function()
                    {
                         this.className+=" over";
                    }
                    node.onmouseout=function()
                    {
                         this.className=this.className.replace(" over", "");
                    }
               }
          }
     }
}

window.onload=startList;
