﻿// JScript File
function SwapModalImage(path, modalImage)
{
    var targetImage = document.getElementById(modalImage);
    targetImage.src = path;
}

function Cover(bottom, top, ignoreSize)
{
    var location = Sys.UI.DomElement.getLocation(bottom);
    top.style.position = 'absolute';
    top.style.top = location.y + 'px';
    top.style.left = location.x + 'px';
    if (!ignoreSize) {
        top.style.height = bottom.offsetHeight + 'px';
        top.style.width = bottom.offsetWidth + 'px';
    }
}

function CoverTop(bottom, top, ignoreSize)
{
    var location = Sys.UI.DomElement.getLocation(bottom);
    top.style.position = 'absolute';
    top.style.top = (location.y + bottom.style.height) + 'px';
    top.style.left = location.x + 'px';
    if (!ignoreSize) {
        top.style.height = bottom.offsetHeight + 'px';
        top.style.width = bottom.offsetWidth + 'px';
    }
}

function SetupImages(imageList, altImageList)
{
    for(var i = 0; i < imageList.length; i++)
    {
        AddStuff(document.getElementById(imageList[i]), altImageList[i]);
    }
}

function AddStuff(currentImage, altImage)
{
    currentImage.defaultImage = new Image();
    currentImage.defaultImage.src = currentImage.src;
    currentImage.altImage = new Image();
    currentImage.altImage.src = altImage;
    currentImage.onmouseover = SwapImageAlt;
    currentImage.onmouseout = SwapImageDefault;

}

function SwapImageAlt() { this.src = this.altImage.src; }

function SwapImageDefault() { this.src = this.defaultImage.src; }

/*

    protected class InvalidImageParametersException : Exception { };
    
    protected void Page_Load(object sender, EventArgs e)
    {
        string[] imageIDList = new string[] {   test1Img.ClientID,
                                                test2Img.ClientID };
        string[] altImageList = new string[] {  "alt1.jpg",
                                                "alt2.jpg" };
        SetupImageSwap(imageIDList, altImageList);
    }


    ////////////////////////////////////////////////////
    // Sets up a startup script which will enable image 
    // swapping on the image ids passed in
    ////////////////////////////////////////////////////
    protected void SetupImageSwap(string[] imageIDList, string[] altImageList)
    {
        if (imageIDList.Length != altImageList.Length)
        {
            throw new InvalidImageParametersException();
        }
        else
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("var testImageList = new Array(\"");
            for (int i = 0; i < imageIDList.Length - 1; i++)
            {
                sb.Append(imageIDList[i]);
                sb.Append("\", \"");
            }

            sb.Append(imageIDList[imageIDList.Length-1]);
            sb.Append("\"); ");
            sb.Append("var testAltImageList = new Array(\"");

            for (int j = 0; j < altImageList.Length - 1; j++)
            {
                sb.Append(altImageList[j]);
                sb.Append("\", \"");
            }

            sb.Append(altImageList[altImageList.Length - 1]);
            sb.Append("\"); ");
            sb.Append("SetupImages(testImageList, testAltImageList);");
            
            ClientScriptManager csm = Page.ClientScript;
            csm.RegisterStartupScript(this.GetType(), "SetupImages", sb.ToString(), true);
        }
    }
*/