﻿var req;
var images;
var enabledImages = [];
var j = 0;

function loadImages() {

    req = false;
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest && !(window.ActiveXObject)) {
        try {
            req = new XMLHttpRequest();
        }
        catch (e) {
            req = false;
        }
    }
    // branch for IE/Windows ActiveX version
    else if (window.ActiveXObject) {
        try {
            req = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                req = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                req = false;
            }
        }
    }
    if (req) {
        //		req.onreadystatechange = processReqChange;
        req.open("GET", "../images/frontpage/Images.xml", false);
        req.send("");
        processReqChange();
    }
}

function processReqChange() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            xmlDoc = req.responseXML;
            images = xmlDoc.getElementsByTagName("image");
            for (var i = 0; i < images.length; i++) {
                if ((images[i].getElementsByTagName("enable")[0].childNodes[0].nodeValue) == "true")
                { enabledImages.push(images[i]); }
            }
        }
        else {
            alert("There was a problem retrieving the XML data:\n" +
                req.statusText);
        }
    }
}

var url;
var src;
var alt;
var text;

function display() {
    target = "";
    if (j >= enabledImages.length)
    { j = 0; }
    url = (enabledImages[j].getElementsByTagName("url")[0].childNodes[0].nodeValue);
    src = (enabledImages[j].getElementsByTagName("src")[0].childNodes[0].nodeValue);
    alt = (enabledImages[j].getElementsByTagName("alt")[0].childNodes[0].nodeValue);
    newwindow = (enabledImages[j].getElementsByTagName("newwindow")[0].childNodes[0].nodeValue);
    if (newwindow == 'true')
    { target = " target=\"_blank\" "; }

    text = "<a href=\"" + url + "\"" + target + "><img src=\"" + src + "\" alt=\"" + alt + "\" class=\"frontpageimages\" /></a>";
    document.getElementById("mainfeature").innerHTML = text;
    time = 6000;
    newtime = (enabledImages[j].getElementsByTagName("time")[0].childNodes[0].nodeValue);
    if (newtime > 0)
    { time = newtime; }
    //    alert(time);
    j++;
    if (time != 10001)
        setTimeout("display()", time);
}

function preloadfirstimage() {
    text = "<a href=\"../ContactUs.aspx\"><img src=\"../images/frontpage/mosquitofrontpage.jpg\" width=\"740px\" height=\"300px\" border=\"0\" /></a>";
    document.getElementById("mainfeature").innerHTML = text;
}

function $(id) {
    return document.getElementById(id);
}

var number_of_property_image = 0;
var html_image_list = new Array();
var a_link_list = new Array();
var featuredtitle;
var html_index = 0;
var property_image_list = new Array();
var property_image_alt_list = new Array();
var property_link_list = new Array();
var property_index = 0;
var scrolling_index = 0;

function GetImagesAndLinks() {
    html_image_list[0] = $('oneImage');
    html_image_list[1] = $('twoImage');
    html_image_list[2] = $('threeImage');
    html_image_list[3] = $('fourImage');
    html_image_list[4] = $('fiveImage');
    a_link_list[0] = $('oneLink');
    a_link_list[1] = $('twoLink');
    a_link_list[2] = $('threeLink');
    a_link_list[3] = $('fourLink');
    a_link_list[4] = $('fiveLink');
    featuredtitle = $('featuredheader');
}

function ScrollingPropertiesImages2() {
    if (scrolling_index >= number_of_property_image) { scrolling_index = 0; }
    property_index = scrolling_index;
    for (html_index = 0; html_index < 5; html_index++) {
        if (property_index >= number_of_property_image) { property_index = 0; }
        html_image_list[html_index].src = property_image_list[property_index];
        a_link_list[html_index].href = property_link_list[property_index];
        property_index++;
    }
    scrolling_index++;
    setTimeout('ScrollingPropertiesImages()', 5000);
}

function ScrollingPropertiesImages() {

    var timer = 500;
    if (scrolling_index >= number_of_property_image) { scrolling_index = 0; }
    if (property_index >= number_of_property_image) { property_index = 0; }
    html_image_list[html_index].src = property_image_list[property_index];
    a_link_list[html_index].href = property_link_list[property_index];
    property_index++;
    html_index++;
    if (html_index >= 5) {
        html_index = 0;
        scrolling_index++;
        property_index = scrolling_index;
        timer = 5000;
    }
    setTimeout('ScrollingPropertiesImages()', timer);
}