/* $Id$ */
/* Copyright (c) 2007 RealGo Inc. All rights reserved. */

var browserOK = (navigator.userAgent.indexOf ("MSIE 3") == -1),
    pics = [];

function loadImages(name, id) {
    if (browserOK) {
        var pic = pics[name];
        if (!pic) {
            pic = pics[name] = [];
            pic.pos= 0;
        }
        pic.push(id);
    }
}

function loadPhoto(index,name) {
    if (browserOK){
        var pic = pics[name];
        document.images[name].src= pic[pic.pos = index];
        decorateText(index,name);
    }
}

function nextImg(name) {
    if (browserOK) {
        var pic = pics[name];
        pic.pos = (pic.pos + 1) % pic.length;
        document.images[name].src= pic[pic.pos];
    }
}

function nextPhoto(name) {
    if (browserOK) {
        nextImg(name);
        decorateText(pics[name].pos,name);
    }
}

function prevImg(name) {
    if (browserOK) {
        var pic = pics[name];
        pic.pos = (pic.pos + pic.length - 1) % pic.length;
        document.images[name].src= pic[pic.pos];
    }
}

function prevPhoto(name) {
    if (browserOK) {
        prevImg(name);
        decorateText(pics[name].pos,name);
    }
}

function decorateText(index,name) {
    var pic = pics[name];
    for (var i=0; i < pic.length; i++) {
        var elem = document.getElementById("photoLink_" + i);
        if (elem) {
            elem.style.color = i == index ? 'black': 'blue';
        }
    }
    var elem = document.getElementById("currPhotoIdx");
    if (elem) {
        elem.innerHTML = '' + (index + 1);
    }
}

