﻿var timer1;
var timer2;
var timer3;
var timer4;
var timer5;
var timer6;
var timer7;
var timer8;

var rotate_delay = 3000;
var rotate_delay2 = 100;

var halt = "no";

var images = new Array(2);
var links = new Array(2);

images[0] = "skins/Skin_1/img/site/ad/breastcancerawareness-3.jpg";
images[1] = "skins/Skin_1/img/site/ad/giftofenc.jpg";

links[0] = "http://www.encouragementstore.com/e-breast-cancer-awareness.aspx";
links[1] = "";

current = 0;

function start_rotate() {
    rotate();
}

function setOpacity(obj, opacity) {
    opacity = (opacity == 100) ? 99.999 : opacity;

    // IE/Win
    obj.style.filter = "alpha(opacity:" + opacity + ")";

    // Safari<1.2, Konqueror
    obj.style.KHTMLOpacity = opacity / 100;

    // Older Mozilla and Firefox
    obj.style.MozOpacity = opacity / 100;

    // Safari 1.2, newer Firefox and Mozilla, CSS3
    obj.style.opacity = opacity / 100;
}

function fadeIn(objId, opacity) {
    if (document.getElementById) {
        obj = document.getElementById(objId);
        setOpacity(obj, opacity);
    }
}

function fadeOut(objId, opacity) {
    if (document.getElementById) {
        obj = document.getElementById(objId);

        if (opacity == 90) {
            if (current == 1)
                document.getElementById("rotatediv").style.backgroundImage = "url(skins/Skin_1/img/site/ad/giftofenc.jpg)";
            else if (current == 2)
                document.getElementById("rotatediv").style.backgroundImage = "url(skins/Skin_1/img/site/ad/breastcancerawareness.jpg)";
        }

        if (opacity >= 0) {
            setOpacity(obj, opacity);
            opacity -= 10;
            timer4 = window.setTimeout("fadeOut('" + objId + "'," + opacity + ")", 50);
        }
    }
}

function fadeOut2(objId, opacity) {
    if (document.getElementById) {
        obj = document.getElementById(objId);

        if (current == 1)
            document.getElementById("rotatediv").style.backgroundImage = "url(skins/Skin_1/img/site/ad/giftofenc.jpg)";
        else if (current == 2)
            document.getElementById("rotatediv").style.backgroundImage = "url(skins/Skin_1/img/site/ad/breastcancerawareness.jpg)";

        if (opacity >= 0) {
            setOpacity(obj, opacity);
            opacity -= 10;
            window.setTimeout("fadeOut2('" + objId + "'," + opacity + ")", 50);
        }
        else {
            halt = "no";
            rotate();
        }
    }
}

function findnext(curr) {
    clearTimeout(timer1);
    clearTimeout(timer2);
    clearTimeout(timer3);
    clearTimeout(timer4);
    clearTimeout(timer5);
    clearTimeout(timer6);
    clearTimeout(timer7);
    clearTimeout(timer8);

    current = curr;

    if (current == 4)
        current = 0;

    halt = "yes";

    image = document.getElementById("thephoto");
    setOpacity(image, 100);
    image.style.visibility = 'visible';

    document.images.show.src = images[current];

    addlink(current);
    apply_styles(current);

    timer5 = window.setTimeout("fadeOut2('thephoto', 100);", 5000);
    current = current + 1;
}

function findprevious(curr) {
    clearTimeout(timer1);
    clearTimeout(timer2);
    clearTimeout(timer3);
    clearTimeout(timer4);
    clearTimeout(timer5);
    clearTimeout(timer6);
    clearTimeout(timer7);
    clearTimeout(timer8);

    halt = "yes";

    if (current == 1)
        current = 3;
    else
        current = curr - 2;

    image = document.getElementById("thephoto");
    setOpacity(image, 100);
    image.style.visibility = 'visible';

    document.images.show.src = images[current];

    addlink(current);
    apply_styles(current);

    timer5 = window.setTimeout("fadeOut2('thephoto', 100);", 5000);
    current = current + 1;
}

function find(imagenum) {
    clearTimeout(timer1);
    clearTimeout(timer2);
    clearTimeout(timer3);
    clearTimeout(timer4);
    clearTimeout(timer5);

    halt = "yes";

    image = document.getElementById("thephoto");
    setOpacity(image, 100);
    image.style.visibility = 'visible';

    document.images.show.src = images[imagenum];
    current = imagenum;

    addlink(current);
    apply_styles(current);

    timer5 = window.setTimeout("fadeOut2('thephoto', 100);", 5000);
    current = current + 1;
}

function toggleStart() {

}

function rotate() {
    if (halt = "no") {
        if (current < images.length) {
            //document.getElementById("rotatediv").style.backgroundImage = "url(images/rotate/rotate_bga.jpg)";
            //document.images.show.style.visibility = "hidden";
            document.images.show.src = images[current];
            image = document.getElementById("thephoto");
            addlink(current);

            //setOpacity(image, 0);
            //image.style.visibility = 'visible';
            //fadeIn("thephoto", 100);

            apply_styles(current);

            timer1 = window.setTimeout("fadeOut('thephoto', 100);", 9000);

            current = current + 1;

            if (current == 4)
                timer7 = window.setTimeout("apply_styles(0);", 9200);
            else
                timer8 = window.setTimeout("apply_styles(current);", 9200);

            timer2 = window.setTimeout("rotate()", 10000);
            //needs to be 1000 more than the fadeOut function timeout
        }
        else {
            current = 0;
            rotate();
        }
    }
}

function apply_styles(curr) {
    if (halt = "no") {
        
    }
}

function addlink(curr) {
    document.getElementById('link').href = links[curr];
}
