﻿var lb_items = new Array();

var lb_active = 0;

function LightBoxItem(imgSrc, subject, headline, cutline, byline, url) {
    this.imgSrc = imgSrc;
    this.image = new Image();
    this.image.src = imgSrc;
    this.subject = subject;
    this.headline = headline;
    this.cutline = cutline;
    this.byline = byline;
    this.url = url;
}

function addLightBoxItem(obj) {
    lb_items.push(obj);
}

function initLightBox() {
    // build switcher
    buildSwitcher();
    
    // create 1
    switchLightBox(0);
}

function switchLightBox(itemNo) {
    // get object
    var obj = lb_items[itemNo];
    
    // set switcher
    lb_active = itemNo;
    document.getElementById('theRootLightbox_SwitchText1').className = 'theRootLightbox_SwitchText';
    document.getElementById('theRootLightbox_SwitchText2').className = 'theRootLightbox_SwitchText';
    document.getElementById('theRootLightbox_SwitchText3').className = 'theRootLightbox_SwitchText';
    document.getElementById('theRootLightbox_SwitchText4').className = 'theRootLightbox_SwitchText';
    document.getElementById('theRootLightbox_SwitchText5').className = 'theRootLightbox_SwitchText';
    var elementNo = itemNo + 1;
    var id = 'theRootLightbox_SwitchText' + elementNo;
    document.getElementById(id).className = 'theRootLightbox_SwitchTextSelected';
    // change image
    document.getElementById('theRootLightbox_Image').src = obj.image.src;
    
    // change subject
    document.getElementById('theRootLightbox_ImageDetailSubject').innerHTML = obj.subject;
    
    // change headline
    document.getElementById('theRootLightbox_ImageDetailHeadline').innerHTML = obj.headline;
    
    // change cutline
    document.getElementById('theRootLightbox_ImageDetailCutline').innerHTML = obj.cutline;
    
    // change byline
    document.getElementById('theRootLightbox_ImageDetailByline').innerHTML = obj.byline;
}

function buildSwitcher() {
    for (var x = 0; x < 5; x = x + 1) {
        var p = x + 1;
        var id = 'theRootLightbox_Switch' + p;
        var obj = document.getElementById(id);
        if (x >= lb_items.length) {
            obj.style.display = 'none';
        }
    }
    document.getElementById('theRootLightbox_SwitcherContainer').style.visibility = 'visible';
}

function lightboxGoto() {
    var obj = lb_items[lb_active];
    window.location = obj.url;
    return false;
}