﻿var imgPath = "";

// Must register all possible subdirectories for image swapping and 
// loading to work correctly. This enables the code to work under
// any directory structure.
var regSubDirectories = new Array (

    "About",
    "Properties",
    "News",
    "SubAbout",
    "AboutUs"
)


function setImagePath ( path ) {
// set the image path from the root of the website. 
// the javascript will determine whether or not we are in a deeper directory
// and compensate.

    var url= document.URL;
    var urlList = document.URL.split("/");
    
    // start at 3, which is the earlier possible subdirectory
    // counts the number of subdirectories in the URL
    var directoriesFound = 0;
    for ( var x = 3; x < urlList.length; x ++ ) {
        for ( var y = 0; y < regSubDirectories.length; y ++ ) {
            if ( regSubDirectories[y] == urlList[x] ) {
                directoriesFound ++;
            }
        }    

    }
    
    for ( var x = 0; x < directoriesFound; x ++ ){
        imgPath += "../";
    }
    
    imgPath += path;

}

function preloadImage ( imgFile ) {
    
    var tmpImg = new Image();
    tmpImg.src = imgPath + imgFile;
    
}

function imageSwap ( id, img ) {

    document.getElementById( id ).src = imgPath + "/" + img;
    
}

