var images = new Array();
var starttime = 1000;
var steptime = 2000;
var scale = 1;
var maxcycle = 100;

var loadlist = [
    // initial set
    {
        file: "frontpage/img_1384.jpg",
	where: "Kauai, HI, US",
        popup: "Polihale Beach",
	linkto: "Scenery/img_1384.jpg",
        fromx: 0,
	fromy: 0
    },
    {
        file: "frontpage/waterfall-dusk.jpg",
	where: "Quebec, Canada",
        popup: "Waterfall At Dusk",
	linkto: "Scenery/waterfall-dusk.jpg",
        fromx: 0,
	fromy: 0
    },
    {
        file: "frontpage/img_8270.jpg",
	where: "Prague, Czech Republic",
        popup: "Prague at Night",
	linkto: "Places/CzechRepublic/Prague-at-night/img_8270.jpg",
        fromx: 0,
	fromy: 0
    },
    {
        file: "frontpage/img_3413.jpg",
	where: "Santo Domingo, Dominican Republic",
        popup: "Blue Music",
	linkto: "People/img_3413.jpg",
        fromx: 0,
	fromy: 0
    },
    {
        file: "frontpage/img_1517-fixed.jpg",
	where: "Hiroshima, Japan",
        popup: "Hiroshima Castle",
	linkto: "Places/Japan/Hiroshima/img_1517-fixed.jpg",
        fromx: 0,
	fromy: 0
    },
    {
        file: "frontpage/img_0687.jpg",
	where: "El Dorado County, CA, US",
        popup: "Winter Wonderland",
	linkto: "Scenery/img_0687.jpg",
        fromx: 0,
	fromy: 0
    },
    {
        file: "frontpage/img_1170.jpg",
	where: "Honolulu, HI, US",
        popup: "Reflections",
	linkto: "Animals/Insets/img_1170.jpg",
        fromx: 0,
	fromy: 0
    },
    {
        file: "frontpage/faces.jpg",
	where: "Davis, CA, US",
        popup: "True Patriots",
	linkto: "People/dscn9486-fixed2.jpg",
        fromx: 0,
	fromy: 0
    },

    // others
    {
        file: "frontpage/img_3176.jpg",
	where: "Kyoto, Japan",
        popup: "In the Belly of the Sun",
	linkto: "Objects/img_3176.jpg",
        fromx: 0,
	fromy: 0
    },
    {
        file: "frontpage/EfficientWindow.jpeg",
	where: "Stockholm, Sweden",
        popup: "Efficient Use of Space",
	linkto: "Objects/EfficientWindow.jpg",
        fromx: 0,
	fromy: 0
    },
    {
        file: "frontpage/BeeingPink.jpg",
	where: "Davis, CA, US",
        popup: "Beeing Pink",
        fromx: 0,
	fromy: 0
    },
    {
        file: "frontpage/img_1393-fixed.jpg",
	where: "Miyajima, Japan",
        popup: "Endless Lights",
	linkto: "Objects/img_1393-fixed.jpg",
        fromx: 0,
	fromy: 0
    },
    {
        file: "frontpage/img_8668.jpg",
	where: "London, UK",
        popup: "Charge!!!",
	linkto: "Places/UnitedKingdom/img_8668.jpg",
        fromx: 0,
	fromy: 0
    },
    {
        file: "frontpage/th890.jpg",
	where: "Beijing, China",
        popup: "Standing!!!",
	linkto: "Places/China/Beijing-Temple-Heaven/th890.jpg",
        fromx: 0,
	fromy: 0
    },
    {
        file: "frontpage/IMG_9353.jpg",
	where: "Quebec, Canada",
        popup: "Fireworks over a Waterfall",
	linkto: "Objects/IMG_9353.jpg",
        fromx: 0,
	fromy: 0
    },
    {
        file: "frontpage/feet-you-will-meet.jpg",
	where: "San Francisco, CA, US",
        popup: "The Feet You Will Meet",
	linkto: "Objects/feet-you-will-meet.jpg",
        fromx: 0,
	fromy: 0
    },
    {
        file: "frontpage/img_8060_001.jpg",
	where: "Echo Lake, CA, US",
        popup: "Pollen Burst",
	linkto: "Flora/Pollen+Burst.jpg",
        fromx: 0,
	fromy: 0
    },
    {
        file: "frontpage/blacksmith.jpg",
	where: "Prague, Czech Republic",
        popup: "Blacksmith",
	linkto: "People/blacksmith.jpg",
        fromx: 0,
	fromy: 0
    },
    {
        file: "frontpage/FlowingGreen.jpg",
	where: "Columbia, MD, US",
        popup: "Flowing Green",
	linkto: "Flora/FlowingGreen.jpg",
        fromx: 0,
	fromy: 0
    },
    {
        file: "frontpage/img_5252.jpg",
	where: "Maastricht, Netherlands",
        popup: "Slow Falls",
	linkto: "Places/Netherlands/Maastricht/img_5252.jpg",
        fromx: 0,
	fromy: 0
    },
    {
        file: "frontpage/dscp2291-cropped.jpg",
	where: "Seattle, WA, US",
        popup: "Bending the Bars Lightly",
	linkto: "Objects/dscp2291-cropped.jpg",
        fromx: 0,
	fromy: 0
    },

    {
        file: "frontpage/img_0670.jpg",
	where: "El Dorado County, CA, US",
        popup: "Coyote In Winter",
	linkto: "Animals/img_0670.jpg",
        fromx: 0,
	fromy: 0
    },
    {
        file: "frontpage/img_1032-fixed.jpg",
	where: "Minneapolis, MN, US",
        popup: "Guilty",
	linkto: "Animals/img_1032-fixed.jpg",
        fromx: 0,
	fromy: 0
    },
    {
        file: "frontpage/img_1754-fixed.jpg",
	where: "El Dorado County, CA, US",
        popup: "Fast and Slow",
	linkto: "Seasons/Winter/img_1754-fixed.jpg",
        fromx: 0,
	fromy: 0
    },
    {
        file: "frontpage/pg7371.jpg",
	where: "Beijing, China",
        popup: "Reflections of Willows",
	linkto: "Places/China/PurpleBamboo/pg7371.jpg",
        fromx: 0,
	fromy: 0
    },
    {
        file: "frontpage/img_4125.jpg",
	where: "Denver, CO, US",
        popup: "The Commute",
	linkto: "People/img_4125.jpg",
        fromx: 0,
	fromy: 0
    },
    {
        file: "frontpage/img_9580.jpg",
	where: "Stockholm, Sweden",
        popup: "Goat",
	linkto: "Animals/Goat.jpg",
        fromx: 0,
	fromy: 0
    },

    {
        file: "frontpage/EchosOfIce.jpeg",
	where: "Echo Lake, CA, US",
        popup: "Echos of Ice",
	linkto: "Scenery/EchosOfIce.jpg",
        fromx: 0,
	fromy: 0
    },
    {
        file: "frontpage/img_6687.jpg",
	where: "Beijing, China",
        popup: "Forbidden City",
	linkto: "Places/China/Beijing-Forbidden-City/img_6687.jpg",
        fromx: 0,
	fromy: 0
    },
    {
        file: "frontpage/img_1202.jpg",
	where: "Hiroshima, Japan",
        popup: "Orange and Green",
	linkto: "Places/Japan/Hiroshima/img_1202.jpg",
        fromx: 0,
	fromy: 0
    },
    {
        file: "frontpage/img_1822.jpg",
	where: "Davis, CA, US",
        popup: "Fog on Fire",
	linkto: "Scenery/img_1822.jpg",
        fromx: 0,
	fromy: 0
    },
    {
        file: "frontpage/dscn2144.jpg",
	where: "Coolfont, WV, US",
        popup: "Shaded Road",
	linkto: "Scenery/SunnyRoad.jpg",
        fromx: 0,
	fromy: 0
    },

    ];    

//
// Picture
//
function Picture_startat(thetime) {
    var obj = this;
    setTimeout(function() { obj.popup() }, thetime);
}

function Picture_nextNum() {
    if (this.filenum+5 < loadlist.length) {
        return this.filenum + 5;
    } else {
        return this.initnum;
    }
}

function Picture_popup() {
    document.getElementById(this.element + "div").style.zIndex = "5";
    this.filenum = this.nextNum();
    var obj = this;
    setTimeout(function() { obj.nextimage() } , 5 * steptime * scale);
//    alert ("here: " + this.filenum + " / " + loadlist.length);
}

function Picture_nextimage() {
    maxcycle -= 1;
    if (maxcycle > 0) {
        this.setimage(loadlist[this.filenum]);
        this.popup();
    }
}

function Picture_setimage(pic) {
    document.getElementById(this.element).src = pic.file;
    document.getElementById(this.element).title = pic.popup;
    document.getElementById(this.element + "text").innerHTML = pic.where;
    document.getElementById(this.element + "load").src = this.nextNum();
    if (pic.linkto) {
	document.getElementById(this.element + "link").href = 
	    "http://capturedonearth.com/v/" + 
	    pic.linkto +
	    ".html?g2_imageViewsIndex=1";
    } else {
	document.getElementById(this.element + "link").href =
	    "http://capturedonearth.com/main.php";
    }
}

function Picture(filenum, element, starttime) {
    this.filenum = filenum;
    this.initnum = filenum;
    this.file = loadlist[filenum].file;
    this.picture = loadlist[filenum];
    this.element = element;
    this.starttime = starttime;

    this.popup = Picture_popup;
    this.nextNum = Picture_nextNum;
    this.startat = Picture_startat;
    this.setimage = Picture_setimage;
    this.nextimage = Picture_nextimage;

    var obj = this;
    this.setimage(loadlist[this.filenum]);
    obj.startat(starttime);
}

Object.prototype.getElementWidth = function() {
	if (typeof this.clip !== "undefined") {
		return this.clip.width;
	} else {
		if (this.style.pixelWidth) {
			return this.style.pixelWidth;
		} else {
			return this.offsetWidth;
		}
	}
}

// adjusts the position of the middle image
function positionLeft() {
    document.getElementById("box5div").style.left = (document.getElementById("full").getElementWidth() - document.getElementById("box5div").getElementWidth())/2;
}

function bootstrap_timers() {

    setTimeout('document.getElementById("enter").style.zIndex="5"', 1500);

    images[0] = new Picture(0, "box2", scale * 1000);
    images[1] = new Picture(1, "box3", scale * 3000);
    images[2] = new Picture(2, "box1", scale * 5000);
    images[3] = new Picture(3, "box4", scale * 7000);
    images[4] = new Picture(4, "box5", scale * 9000);
}

