﻿// For Accuweather 
var k = 0
var speed = 1500
var Pic = new Array()
Pic[0] = 'http://www.caycompass.com/weather/accuweather/iscar1.jpg'
Pic[1] = 'http://www.caycompass.com/weather/accuweather/iscar2.jpg'
Pic[2] = 'http://www.caycompass.com/weather/accuweather/iscar3.jpg'
Pic[3] = 'http://www.caycompass.com/weather/accuweather/iscar4.jpg'
Pic[4] = 'http://www.caycompass.com/weather/accuweather/iscar5.jpg'
Pic[5] = 'http://www.caycompass.com/weather/accuweather/iscar6.jpg'
var t
var j = 0
var p = Pic.length
var preLoad = new Array()
for (i = 0; i < p; i++) {
    preLoad[i] = new Image();
    preLoad[i].src = Pic[i];
}

function runSlideShow() {
    if (preLoad[j].complete) {
        document.images.SlideShow.src = preLoad[j].src;
        j = j + 1;
        if (j > (p - 1)) { j = 0 };


    }
    t = setTimeout('runSlideShow()', speed)
}
function runloop() { runSlideShow() }

function toggleWeatherBoxes(elemId, imgHeight) {
    if (elemId == "") {
        return;
    } else {
        var control = document.getElementById(elemId);
        if (control.style.display == "none") {
            grayOut(true);
            setTimeout(function() {
                var windowHeight = getWindowHeight();
                var controlDivHeight = imgHeight;  // Get height of Image from parameter (TODO: make this automatic?)
                var ScrollY = getScrollYPos();
                if (windowHeight - controlDivHeight > 0) {
                    control.style.top = (((windowHeight / 2) - (controlDivHeight / 2)) + ScrollY) + 'px';
                }
                control.style.display = "block";
            }, 400);
        } else {
            control.style.display = "none";
            setTimeout("grayOut(false);", 200);
        }
    }
}

function toggleStormBoxes(imgUrl) {
    if (imgUrl == "") {
        return;
    } else {
        var stormDiv = document.getElementById("activeStorm");
        var stormImg = document.getElementById("activeStormImg");
        if (stormDiv.style.display == "none") {
            stormImg.src = imgUrl;
            grayOut(true);
            setTimeout(function() {
                var windowHeight = getWindowHeight();
                var stormDivHeight = 400;   // Div is always 400px in height (TODO: automatic?)
                var ScrollY = getScrollYPos();
                if (windowHeight - stormDivHeight > 0) {
                    stormDiv.style.top = (((windowHeight / 2) - (stormDivHeight / 2)) + ScrollY) + 'px';
                }
                stormDiv.style.display = "block";
            }, 400);
        } else {
            stormImg.src = "";
            stormDiv.style.display = "none";
            setTimeout("grayOut(false);", 200);
        }
    }
}

function getWindowHeight() {
    var windowHeight = 0;
    if (typeof (window.innerHeight) == 'number') {
        windowHeight = window.innerHeight;
    }
    else {
        if (document.documentElement && document.documentElement.clientHeight) {
            windowHeight = document.documentElement.clientHeight;
        }
        else {
            if (document.body && document.body.clientHeight) {
                windowHeight = document.body.clientHeight;
            }
        }
    }
    return windowHeight;
}

function getWindowWidth() {
    var windowWidth = 0;
    if (typeof (window.innerWidth) == 'number') {
        windowHeight = window.innerWidht;
    }
    else {
        if (document.documentElement && document.documentElement.clientWidth) {
            windowHeight = document.documentElement.clientWidth;
        }
        else {
            if (document.body && document.body.clientWidth) {
                windowWidth = document.body.clientWidth;
            }
        }
    }
    return windowWidth;
}

function getScrollYPos() {
    var ScrollY = document.body.scrollTop;

    if (ScrollY == 0) {
        if (window.pageYOffset)
            ScrollY = window.pageYOffset;
        else
            ScrollY = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
    }

    return ScrollY;
}