//////////////////////////////////////////////////////////////////////////////////
// Xara clientside album functions Version 0.84 Copyright 2003 Xara Ltd
var pics = 0;
var picn = new Array();
var cap = new Array();
var thmb = new Array();
var ti = new Array();
var base = 0;
var path = '';
var album = '';
var themename = '';
var numCols = 0;
var debug = false;
var myids = new Array();
var cp;
var cs;
var pw = null;
var d = document;
var xaf_NS7 = (!d.all && d.getElementById);
var xaf_NS4 = (!d.getElementById);
var xaf_IE5 = (!xaf_NS4 && !xaf_NS7 && (navigator.userAgent.indexOf('MSIE 5.0') != -1 || navigator.userAgent.indexOf('MSIE	5.2') != -1));
var xaf_IE5p5 = (!xaf_NS4 && !xaf_NS7 && navigator.userAgent.indexOf('MSIE 5.5') != -1);
var xaf_NS6 = (xaf_NS7 && navigator.userAgent.indexOf('Netscape6') != -1);
var xaf_SAF = (navigator.userAgent.indexOf('Safari') != -1);
function xara_templatesetup(tcp, tcs){
    if (typeof tcp != 'undefined') {
        cp = tcp;
    }
    if (typeof tcs != 'undefined') {
        cs = tcs;
    }
}

function xara_albumsetup(p, a, t){
    var node;
    path = p;
    album = a;
    themename = t;
    xara_scanCollection("xara_albumtitle", 0, function(node, i, a){
        node.innerHTML += a;
    }, a);
}

function xara_pic(n, tti, tcap){
    var leaf, ext;
    leaf = n.substring(0, n.lastIndexOf('.'));
    ext = n.substring(n.lastIndexOf('.'), n.length);
    picn[pics] = path + n;
    ti[pics] = tti;
    cap[pics] = tcap;
    thmb[pics] = path + leaf + '_thumb' + ext;
    pics++;
}

function xara_show(pc){
    var w, h;
    var cb = pc + base;
    var bigimg;
    var strsrc = "";
    if (cb >= picn.length) 
        return true;
    strsrc += '<html><head><title>' + ti[cb] + '</title>';
    strsrc += '<style type="text/css"><!--';
    strsrc += 'td {';
    strsrc += '	font-family: Arial,Helvetica,Swiss,Sans Serif;';
    strsrc += '	font-size: smaller;';
    strsrc += '}';
    strsrc += '--></style>';
    strsrc += '<scr' + 'ipt>';
    strsrc += 'var pics=' + pics + '; var c=' + cb + '; var e;';
    strsrc += '</scr' + 'ipt>';
    strsrc += '</head>';
    strsrc += '<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 bgcolor="#FFFFFF" scroll="auto">';
    strsrc += '<table width="100%"><tr><td><a href="javascript:window.opener.xara_nextpic(-1, window)"><img src="' + themename + 'prev.gif" border=0 alt="Previous photo" /></a><a href="javascript:window.opener.xara_nextpic(1, window)"><img src="' + themename + 'next.gif" border=0 alt="Next photo" /></a></td><td><b ID="title"></b></td><td height=15 ID="posn" >Photo i of n</td><td align="right"><a href="javascript:close()">close</a></td></tr></table>';
    strsrc += '<table align="center"><tr><td align="center"><a href="javascript:window.opener.xara_nextpic(1, window)"><img src ="' + picn[cb] + '" border=0 ID="pic" onLoad="window.opener.xara_sizetofit(window);" /></a></td></tr>';
    strsrc += '<tr><td align="center" ID="caption"></td></tr></table>';
    strsrc += '</body></html>';
    bigimg = new Image();
    bigimg.src = picn[cb];
    w = bigimg.width + 10;
    h = bigimg.height + 30;
    s = 0;
    if (w > screen.availWidth - 50) {
        w = screen.availWidth - 50;
        s = 1;
    }
    if (h > screen.availHeight - 50) {
        h = screen.availHeight - 50;
        s = 1;
    }
    o = "toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=1,scrollbars=" + s + ",left=40;top=20;screenX=40,screenY=20,width=" + w + ",height=" + h;
    if (pw) {
        wd = window.open("", "xaraslideshow", o, true);
        pw = wd;
    }
    else {
        wd = window.open("", "", o, true);
        wd.name = "xaraslideshow";
        pw = wd;
    }
    wd.document.open();
    wd.document.writeln(strsrc);
    wd.document.close();
    xara_nextpic(0, wd);
    wd.focus();
}

function xara_albumfill(base){
    var i;
    var timg;
    var tel;
    var trow;
    myids = new Array();
    xara_scanIndexedCollection("xara_thumb", xara_img, 0);
    xara_scanIndexedCollection("xara_title", xara_text, ti);
    xara_scanIndexedCollection("xara_caption", xara_text, cap);
    xara_scanCollection("xara_positionpages", 0, function(tel, i, a){
        if (base > 0 || picn.length > base + xara_countslots()) 
            tel.style.visibility = "visible";
        else 
            tel.style.visibility = "hidden";
    }, 0);
    xara_scanCollection("xara_prevpage", 0, function(tel, i, a){
        if (base > 0) 
            tel.style.visibility = "visible";
        else 
            tel.style.visibility = "hidden";
    }, 0);
    xara_scanCollection("xara_nextpage", 0, function(tel, i, a){
        if (picn.length > base + xara_countslots()) 
            tel.style.visibility = "visible";
        else 
            tel.style.visibility = "hidden";
    }, 0);
    xara_scanCollection("xara_position", 0, xara_postext, 0);
    xara_scanIndexedCollection("xara_cell", xara_vis, 0);
}

function xara_img(timg, i, a){
    if ((base + i) < thmb.length && (base + i) >= 0) 
        if (thmb[base + i] != '') {
            timg.src = thmb[base + i];
            timg.removeAttribute("width");
            timg.removeAttribute("height");
        }
        else 
            timg.src = themename + "nothumb.gif";
    else 
        timg.src = themename + "missingthumb.gif";
}

function xara_text(tel, i, a){
    if ((base + i) < a.length && (base + i) >= 0) 
        tel.innerHTML = a[base + i];
    else 
        tel.innerHTML = '';
}

function xara_postext(tel, i, a){
    var top = base + xara_countslots();
    if (top > picn.length) 
        top = picn.length;
    tel.innerHTML = "Showing pictures " + (base + 1) + " to " + top + " of " + picn.length;
}

function xara_vis(tel, i, a){
    if ((base + i) < thmb.length && (base + i) >= 0) 
        tel.style.visibility = "visible";
    else 
        tel.style.visibility = "hidden";
}

function xara_countslots(){
    var i;
    i = 0;
    timg = document.getElementById("xara_thumb" + i);
    while (timg) {
        i++;
        timg = document.getElementById("xara_thumb" + i);
    }
    return i;
}

function xara_prevpage(){
    if (base > 0) {
        base = base - xara_countslots();
        xara_albumfill(base);
    }
}

function xara_nextpage(){
    if (picn.length > base + xara_countslots()) {
        base = base + xara_countslots();
        xara_albumfill(base);
    }
}

function xara_albumcreate(ncols, nrows, startslot){
    var posn = document.getElementById("xara_albumdisplay");
    var x, y;
    var slotnum;
    var row_startslot;
    if (posn) {
        var oTable = document.createElement("TABLE");
        var oTBody0 = document.createElement("TBODY");
        var oRow, oCell;
        var i, j, k;
        var tcell_collect;
        var tcell;
        var tcellInnerHTML;
        if (startslot != -1) 
            slotnum = startslot;
        else 
            slotnum = xara_countslots();
        oTable.appendChild(oTBody0);
        oTable.border = 0;
        oTable.width = '100%';
        if (typeof cp != 'undefined') 
            oTable.cellPadding = cp;
        if (typeof cs != 'undefined') 
            oTable.cellSpacing = cs;
        oTable.className = "xara_albumtable";
        for (i = 0; i < nrows; i++) {
            tcell_collect = document.getElementsByName("xara_albumcelltemplate");
            row_startslot = slotnum;
            for (k = 0; k < tcell_collect.length; k++) {
                slotnum = row_startslot;
                tcell = tcell_collect[k];
                if (tcell) 
                    tcellInnerHTML = tcell.innerHTML;
                oRow = document.createElement("TR");
                oRow.id = "xara_row" + i;
                oRow.className = "xara_albumrow";
                oTBody0.appendChild(oRow);
                for (j = 0; j < ncols; j++) {
                    oCell = document.createElement("TD");
                    if (tcell) {
                        var slothtml = tcellInnerHTML;
                        slothtml = slothtml.replace(/slotnum/gi, slotnum);
                        slothtml = slothtml.replace(/%28/gi, "(");
                        slothtml = slothtml.replace(/%29/gi, ")");
                        oCell.innerHTML = slothtml;
                    }
                    else {
                        oCell.innerHTML = '<a href="javascript:xara_show(' + slotnum + ');"><img src="gradient_photothumb.gif" border=0 hspace=2 vspace=2 ID="xara_thumb' + slotnum + '"></a>';
                    }
                    oCell.align = 'center';
                    oCell.vAlign = 'top';
                    oCell.width = 100 / ncols + '%';
                    oCell.id = "xara_cell" + slotnum;
                    oCell.className = "xara_albumcell" + k;
                    oRow.appendChild(oCell);
                    slotnum++;
                }
            }
        }
        tcell_collect = document.getElementsByName("xara_albumcelltemplate");
        for (k = tcell_collect.length - 1; k >= 0; k--) {
            tcell = tcell_collect[k];
            if (tcell && xara_ChildOf(posn, tcell)) {
                var p = tcell.parentNode;
                p.removeChild(tcell);
            }
        }
        posn.appendChild(oTable);
        numCols = ncols;
    }
}

function xara_nextpic(d, wnd){
    wnd.c += d;
    if (wnd.c >= pics) 
        wnd.c = 0;
    if (wnd.c < 0) 
        wnd.c = pics - 1;
    if (wnd.document.images != null) {
        var e = wnd.document.getElementById("pic");
        if (e) {
            e.src = picn[wnd.c];
            e.align = "center";
        }
        e = wnd.document.getElementById("posn");
        if (e) 
            e.innerHTML = "Photo&nbsp;" + (wnd.c + 1) + "&nbsp;of&nbsp;" + pics;
        e = wnd.document.getElementById("title");
        if (e) 
            e.innerHTML = ti[wnd.c];
        e = wnd.document.getElementById("caption");
        if (e) 
            e.innerHTML = cap[wnd.c];
        if (wnd.navigator.userAgent.indexOf('MSIE') != -1) 
            wnd.document.title = ti[wnd.c];
    }
}

function xara_sizetofit(wnd){
    if (wnd.document.images != null) {
        e = wnd.document.getElementById("pic");
        if (e) {
            if (e.width != 0 || e.height != 0) {
                var w, h, s;
                w = e.width + 18 + 32;
                h = e.height + 56 + 32;
                s = false;
                if (cap[wnd.c] != '') 
                    h = h + 40;
                if (w > screen.availWidth) {
                    w = screen.availWidth;
                    s = true;
                }
                if (h > screen.availHeight) {
                    h = screen.availHeight;
                    s = true;
                }
                wnd.resizeTo(w, h);
                if (s) 
                    wnd.moveTo(0, 0);
            }
            else {
                wnd.setTimeout("xara_sizetofit(window)", 50);
            }
        }
    }
}

function xara_ChildOf(a, n){
    var p;
    p = n.parentNode;
    while (p) {
        if (p == a) 
            return true;
        p = p.parentNode;
    }
    return false;
}

function xara_scanIndexedCollection(name, func, args){
    var i;
    var count;
    i = 0;
    do {
        count = xara_scanCollection(name + i, i, func, args);
        i++;
    }
    while (count > 0)
}

function xara_scanCollection(name, base, func, args){
    var tcell_collect;
    var tcell;
    var i;
    var count;
    count = 0;
    tcell_collect = document.getElementsByName(name);
    if (tcell_collect.length > 0) {
        for (k = 0; k < tcell_collect.length; k++) {
            tcell = tcell_collect[k];
            if (tcell) 
                func(tcell, base, args);
        }
        return tcell_collect.length;
    }
    else {
        if (myids.length == 0) 
            xara_scanTree3A();
        return xara_scanTree3B(name, base, func, args);
    }
    return 0;
}

function xara_scanTree3A(){
    var i;
    var c = 0;
    var node = document;
    while (node) {
        if (node.id != "" && typeof node.id != "undefined") {
            myids[c] = node;
            c++;
        }
        node = xara_getnextnode(node);
        if (node && !(xaf_NS7 || xaf_NS6 || xaf_NS4)) 
            if ((typeof node.tagName) != "undefined") 
                if (node.tagName.toUpperCase() == "HTML") 
                    node = null;
    }
    return c;
}

function xara_scanTree3B(name, base, func, args){
    var i;
    var c = 0;
    var node;
    if (document.getElementById(name) == null) 
        return 0;
    for (i = 0; i < myids.length; i++) {
        node = myids[i];
        if (node.id == name) {
            func(node, base, args);
            c++;
        }
    }
    return c;
}

function xara_getnextnode(node){
    if (node == null) 
        return null;
    if (node.firstChild) 
        return node.firstChild;
    while (node.nextSibling == null) {
        if (node.parentNode == null) 
            return null;
        node = node.parentNode;
    }
    return node.nextSibling;
}
