// cookie functions
//
function setCookie(name, value, expires, path, domain, secure)
{
    var curCookie = name + "=" + escape(value) +
      (expires ? "; expires=" + expires.toGMTString() : "") +
      (path ? "; path=" + path : "") +
      (domain ? "; domain=" + domain : "") +
      (secure ? "; secure" : "");

    return document.cookie = curCookie;
}
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);

    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

//*****
//
if (!getCookie('currentImageIndex'))
{
    var now = new Date();
    now.setMinutes(now.getMinutes() + 1);

    setCookie('currentImageIndex', -1, now, null, null, null);
}

// JSON Object
// (http://www.json.org/js.html)
//
// This is where you add more images
//
var slideShow = { "bindings":
                    [
                        { "imageUrl": "images/img-1.jpg" },
                        { "imageUrl": "images/img-2.jpg" },
                        { "imageUrl": "images/img-3.jpg" },
                        { "imageUrl": "images/img-4.jpg" },
                        { "imageUrl": "images/img-5.jpg" },
                        { "imageUrl": "images/img-6.jpg" },
                        { "imageUrl": "images/img-7.jpg" }
                    ]
                };

//*****
//
function ChangeImage() {

    var now = new Date();
    now.setMinutes(now.getMinutes() + 1);

    var currentImageIndex = parseInt(getCookie('currentImageIndex'), 10);
    currentImageIndex++;
    
    if (currentImageIndex >= slideShow.bindings.length) {
        currentImageIndex = 0;
    }
    setCookie('currentImageIndex', currentImageIndex, now, null, null, null);

    var currentSlide = slideShow.bindings[currentImageIndex];

return document.write('<img src="' + currentSlide.imageUrl + '" alt="" width="643px" height="364px" />');
}


// Force IE 7 to refresh
//
// This is only for IE7 browser. FF & Opera don't need this.


function refresh() {
    var sURL = unescape(window.location.pathname);
    window.location.href = sURL; 
}

function forceIE7_Refresh() {
    var longTime = 80000*1000
    setTimeout( "refresh()", longTime );
}


window.onload = forceIE7_Refresh;
