/********************************************************************
* Copyright ©  Acsys, Inc.  All rights reserved.
* 
* This material contains the valuable properties and trade secrets of
* Acsys, Inc. embodying substantial creative efforts and confidential 
* information, ideas, and expressions, no part of which may be 
* reproduced or transmitted in any form or by any means, electronic, 
* mechanical, or otherwise, including photocopying and recording or 
* in connection with any information storage or retrieval system 
* without the permission in writing of Acsys, Inc.
*/

/********************************************************************
* This library defines classes and functions for doing image mouse 
* overs.
* 
* Dependencies: 
*	AcsysMain.js - relies on globals browser capabilities object.
*/

var IMG_RESTORE = "imgRestore_";
var IMG_HOVER = "imgHover_";

function PreloadImage(id, imgSrc, imgSrcHover)
{
	//create global image objects
	window[IMG_RESTORE + id] = new Image();
	window[IMG_RESTORE + id].src = imgSrc;
	window[IMG_HOVER + id] = new Image();
	window[IMG_HOVER + id].src = imgSrcHover;
}

function ImageSwap(id, imgToInsert)
{
	if (!window[IMG_RESTORE + id])
	{
		return;
	}
	
	var image = (browser.IsDOM)
		? document.getElementById(id)
		: document[id];
		
	var imgKey = (imgToInsert == 0)
	    ? IMG_RESTORE + id
	    : IMG_HOVER + id;

	if (image && image.src)
	{
	    image.src = window[imgKey].src
	}
}

function AttachHover(imgSrc, imgSrcHover, targetImgId, sourceElementID)
{
    PreloadImage(targetImgId, imgSrc, imgSrcHover);
    
    if (!document.getElementById  && !document.getElementById(targetImgId))
    {
        return;
    }
    
    var targetImg = document.getElementById(targetImgId);
    
    if (targetImg == null)
    {
		return;
    }

    if (sourceElementID == null)
    {
        sourceElementID = targetImgId;
    }
    
    var sourceElement = document.getElementById(sourceElementID);
    
    if (sourceElement == null)
    {
        sourceElement = targetImg;
    }
    
    targetImg.currentSrc = IMG_RESTORE + targetImgId;
    sourceElement.targetImgId = targetImgId;
    
    if (window.addEventListener)
    {
        sourceElement.addEventListener('mouseover', HoverImage, false);
        sourceElement.addEventListener('mouseout', HoverImage, false);
    }
    else
    {
        sourceElement.attachEvent('onmouseover', HoverImage);
        sourceElement.attachEvent('onmouseout', HoverImage);
    }
    
}

function HoverImage(evt)
{
    if(!document.getElementById)
    {
        return;
    }
    
    var srcElement = evt.target
        ? evt.target
        : evt.srcElement;
        
    var targetImg = srcElement.targetImgId 
        ? document.getElementById(srcElement.targetImgId)
        : srcElement;
    
    var hoverImg = (targetImg.currentSrc == (IMG_RESTORE + targetImg.id))
        ? window[IMG_HOVER + targetImg.id]
        : window[IMG_RESTORE + targetImg.id];
    
    if (hoverImg == null)
    {
        return;
    }
    
    targetImg.src = hoverImg.src;

    targetImg.currentSrc = (targetImg.currentSrc == (IMG_RESTORE + targetImg.id))
        ? IMG_HOVER + targetImg.id
        : IMG_RESTORE + targetImg.id;
    
}