function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);


/* Utility Javascript functions common across pages
 *  $Author:  Rick Critchett
 *  $Date: 11-Sep-03
 */
 
// Initialization
// Browser determination
var bName = navigator.appName;
var agt = navigator.userAgent.toLowerCase();
var NS = (bName == "Netscape");
var IE = (bName == "Microsoft Internet Explorer");
var IE5x = (agt.indexOf("msie 5") != -1);
var bVer = parseInt(navigator.appVersion);
var NS4 = (NS && bVer < 5);
var NS6 = (NS && bVer >= 5);
// rwc: 15-Sep-03. the above works!  Use these vars.
var IESP2 = (agt.indexOf("sv1") != -1); // IE with Service Pack 2
var isMac = (agt.indexOf('mac') != -1);
var isMacIE5x = (isMac && IE5x);

var winVar = null;
var actionVar;

// Global reference variables
var docRef = "document.";
if(NS4)  docRef = "document.";
if(NS6)  docRef = "document.";
if(IE)  docRef = "document.all.";

//Netscape seems to need these document array initialized here and not lazily
document.preloadArray = new Array();
document.chosenPhotos = new Array();
chosenCaptions = new Array();
var chosenPhotoIMGobjectName = "chosenPhotoIMG";
var chosenPhotoDIVobjectName = "chosenPhotoCaption";
// Vehicle information
var currMake = null;
var currModel = null;

// global var to track currently enlarged photo when choosePhoto(n) is called
// this var is passed to the multi photo popup which autoscrolls to the corresponding pic
var lastChosenPhotoIndex = 0;

/*
 * swapImage FUNCTION
 * @param refName name of the IMG object
 * @param imgName name of the image-not a complete filename
 * @param imgState desired state of the image-used to complete filename
 */
function swapImage(refName,imgName,imgState)
{
    var imgRef = eval(docRef + refName);
    imgRef.src = "images/" + imgName + imgState + ".gif";
}

/*
 * preloadImages FUNCTION
 * General functions for preloading a set of images
 *
 */
function preloadImages()
{
    if (document.images)
    {
        var imgFiles = preloadImages.arguments;
        if (document.preloadArray==null)
            document.preloadArray = new Array();
        var i = document.preloadArray.length;
        with (document) for (var j=0; j<imgFiles.length; j++)
            if (imgFiles[j].charAt(0)!="#")
            {
                preloadArray[i] = new Image;
                preloadArray[i++].src = imgFiles[j];
            }
    }
}


/*
 * preloadChosenPhoto FUNCTION
 * @param imageFile an image filename to put into the chosenPhotos array of Image objects
   example: preloadChosenPhoto('/stock/386x258/225885.jpg');
*/
function preloadChosenPhoto(imageFile, caption)
{
  if (document.images)
  {
    if (document.chosenPhotos==null)
    {
        document.chosenPhotos = new Array();
    }
    var p = document.chosenPhotos.length;

    if (imageFile.charAt(0)!="#")
    {
        document.chosenPhotos[p] = new Image;
        document.chosenPhotos[p].src = imageFile;
        chosenCaptions[p] = caption;
    }
  }
}

/*
 * getPhotoCaption(index)
 * @param index which photo of the list 
 *
 */
var shownRegExp = new RegExp(" shown", "i");
var appendShown = true;
function getPhotoCaption(index)
{
    if (index < chosenCaptions.length && null != chosenCaptions[index])
    {
        var caption = chosenCaptions[index];
        caption = caption.replace(shownRegExp, '');
        if (null == caption || "" == caption.replace(/ /g, ""))
        {
            caption = chosenPhotoDIVobjectText;  // reset to default
        }
        else if (appendShown)
        {
            /* only append shown if caption not empty */
            caption += " shown&nbsp;";
        }
        return caption;
    }
}

/*
 * choosePhoto FUNCTION
 * Put the cached image at index 'n' as Chosen Image
 * Uses chosenPhotos variable of large vehicle Image objects and
 * "chosenPhotoIMG" IMG object
 * With highlighting of thumbnail as chosen, use convention that the
 * thumbnail images are named tnImgX where X is passed "n".
 * @param n index into chosenPhotos array of Image objects
*/
function choosePhoto(n)
{
    var imgRef = eval(docRef + chosenPhotoIMGobjectName);
    if (null != imgRef && n < document.chosenPhotos.length)
    {
        imgRef.src = document.chosenPhotos[n].src;
        updateChosenPhotoCaption(n);
        //imgRef.className = "photo";
        //imgRef.border = 2;
        highlightPhoto('tnImg' + n);
    }
    
    lastChosenPhotoIndex = n;
}

/*
 * highlightPhoto FUNCTION
 * Reference the given image object and change its class so it is highlighted.
 * Must keep a state of currently highlighted image to reset the previous.
 * @param imgName name of image object to highlight
*/
var highlightedPhoto = null;
function highlightPhoto(imgName)
{
    var imgRef = eval(docRef + imgName);
    if (null != imgRef)
    {
        if (null != highlightedPhoto){
            highlightedPhoto.className = "photo";
            //highlightedPhoto.width=66;
            //highlightedPhoto.height=44;
        }
        imgRef.className = "photoHighlight";
        //imgRef.width=59;
        //imgRef.height=38;
        highlightedPhoto = imgRef;
    }
}

/* updateChosenPhotoCaption
 * Attempt to update the caption for the Chosen Photo
 * using the rules shown, assets shown below.
 * @param n index into all the photos and their assets
 */
var chosenPhotoDIVobjectText = null;
function updateChosenPhotoCaption(n)
{
    var divRef = null;
    // Find DIV reference first
    if (IE || NS4)
    {
        divRef = eval(docRef + chosenPhotoDIVobjectName);
    }
    else
    {
        divRef = document.getElementById(chosenPhotoDIVobjectName);
    }

    // Then set its text 
    if (null != divRef)
    {
        // Set the default caption from first time thru
        if (null == chosenPhotoDIVobjectText)
        {
            chosenPhotoDIVobjectText = divRef.innerHTML;
        }

        var caption = getPhotoCaption(n, chosenPhotoDIVobjectText);
        if (null == caption || "" == caption.replace(/ /g, ""))
        {
            divRef.innerHTML = chosenPhotoDIVobjectText;  // reset to default
        }
        else
        {
            divRef.innerHTML = caption;
        }
            
    }
}





/*Ensure that the window resizes the same in netscape and IE*/
function resizeOuterTo(w,h) {
 if (parseInt(navigator.appVersion)>3) {
   if (navigator.appName=="Netscape") {
    top.outerWidth=w;
    top.outerHeight=h;
   }
   else top.resizeTo(w,h);
 }
}

