/* 1array image navigation function */
function showimg(id, filename, title, description, item, height, loggedin, pdet)
{
    img = document.getElementById('image');
    img.src = '/img/gallery/images/gamma1/thumbnails/'+filename+'.jpg';
    img.height = height;
    imglnk = document.getElementById("imagelink");
    // imglnk.href = "/gallery/"+id+"/show";
    imglnk.href = '/img/gallery/images/gamma1/fullsize/'+filename+'.jpg';
    imglnk.id = "imagelink";
    imglnk.title = title;
    a = document.getElementById('titleref');
    a.href = "/gallery/"+id+"/show/";
    a.innerHTML = title;
    a.target = "new";
    if (loggedin) {
        b = document.getElementById('editlink');
        b.href = "/gallery/"+id+"/edit";
    }
    d = document.getElementById('description');
    d.innerHTML = description + pdet;
    if (item != 0) {
        //alert("Item is not zero: "+item);
        o = document.getElementById('onsale');
        if (o) {
            o.href = "/prints/"+item+"/";
            o.innerHTML = '<img src="/img/assets/sales/prints_available.png"/>';
            o.alt="Prints available";
            }
        if (loggedin) {
            u = document.getElementById('unpimp');
            if (u) {
                u.href = "/gallery/"+id+"/unpimp/";
                u.innerHTML = '<img src="/img/assets/sales/discard.png"/>'
                }
            p = document.getElementById('pimp');
            if (p) {
                p.href = "";
                p.innerHTML = '';
                }
        } else {
            u = document.getElementById('unpimp');
            if (u) {
                u.href = "";
                u.innerHTML = '';
            }
        }
    } else {
        // alert("Item is zero: "+item);
        o = document.getElementById('onsale');
        if (o) {
            o.href = "";
            o.innerHTML = '';
            }
        if (loggedin) {
            u = document.getElementById('unpimp');
            if (u) {
                u.href = "";
                u.innerHTML = '';
                }
            p = document.getElementById('pimp');
            if (p) {
                p.href = "/gallery/"+id+"/pimp";
                p.innerHTML = '<img src="/img/assets/sales/add.png"/>';
            }
        }
    }
    // x = document.getElementById('imgid');
    // x.innerHTML = '<span>'+id+'</span> <span>'+item+'</span>';
    return true;
}

/* 6array image navigation function */
function gopage(x) {
    page = x.document.getElementById('chooseid').value;
    x.document.location = "/gallery/"+page+"/section/"
    return true;
}

/* Gallery navigation function */
function gosection(x) {
    page = x.document.getElementById('sectionid').value;
    x.document.location = "/gallery/"+page+"/section/";
    return true;
}

/* Unused Javascript purple numbers function (resolution too coarse)
var tagsRE=/\bp|pre\b/i; 
var nid = 0;
var purpleStyle = "font-family:sans-serif;font-weight:bold;font-size:x-small;text-decoration:none;color:#C8A8FF"
function purp(node){
  if (node.hasChildNodes) {
    var hi_cn;
    for(hi_cn=0; hi_cn<node.childNodes.length; hi_cn++) {
        purp(node.childNodes[hi_cn]);
    }
  }
  if(node.nodeType == 1) {
    if (tagsRE.test(node.nodeName)) {
        var nidValue = "nid" + nid;
        node.setAttribute('id', nidValue);
        newNode = document.createElement('a');
        newNode.setAttribute('href', "#" + nidValue);
        newNode.setAttribute('style', purpleStyle);
        newNode.innerHTML = " " + nid;
        node.appendChild(newNode);
        nid = nid + 1;
    }
  }
}
*/

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}

function addUnloadEvent(func) {
    var oldunload = window.unload;
    if (typeof window.unload != 'function') {
        window.unload = func;
    } else {
        window.unload = function() {
            oldunload();
            func();
        }
    }
}

/* 
    Simon Willison's unobtrusive purple numbers version.
    See http://simon.incutio.com/archive/2004/05/30/plinks
    Numbered paragraphs are of id 'p-<count>' which have
    correspondingly-numbered anchors programmatically added.
*/
function addpLinks() {
    if (!/notes/.test(document.location.href)) {
        return; /* Only show plinks on notes pages */
    }
    var paras = document.getElementsByTagName('p');
    for (var i = 0; i < paras.length; i++) {
        var current = paras[i];
        if (/^p-/.test(current.id)) {
            // It's a purple link paragraph
            var plink = document.createElement('a');
            plink.href = document.location.href.split('#')[0] + '#' + current.id;
            plink.className = 'plink';
            plink.appendChild(document.createTextNode(' #'));
            current.appendChild(plink);
        }
    }
}

/*
    At the cost of one extra function, detect if the 
    request is a for purple-numbered paragraph. If so,
    add 'plinkHighlight' to the class attribute, then
    the landing point can be conveniently highlighted 
    via a CSS class selector.
*/ 

function plinkHighlight() {
    if (/#p-/.test(document.location)) {
        // The user arrived via a plink
        var plink_id = document.location.href.split('#')[1];
        var para = document.getElementById(plink_id);
        para.className = para.className + ' plinkHighlight';
    }
}

addLoadEvent(addpLinks);
addLoadEvent(plinkHighlight);

/* 
var ckUtil = new CJL_CookieUtil("tg_visit");
*/

var map = null;
function newPin(id, lat, lon, txt, tt) {
    var latlon = new VELatLong(lat, lon);
    var pin = new VEPushpin(id, latlon, '/img/assets/pushpin.png', txt, tt,'pushPin','titleStyle','previewStyle');
    return pin;
}
function GetMap() {
    if (!/virtualearthmap/.test(document.location.href)) {
        return;
    }
    map = new VEMap('myMap');
    map.LoadMap(new VELatLong(51.3, -3.27), 9 ,'h' , false);
    showAll();
}


addLoadEvent(GetMap);

function confirmDelete(what, id) {
    return confirm('Delete "'+what+'" (#'+id+')?');
}

/*
function showFlashStatusMessage() {
    var flashData = document.getElementById('flashTransport');
    if (flashData.value != "") {
        statusmessage = flashData.value
        if (statusmessage[0] == 'S') {
            $.flash.success('Success', '...... '+statusmessage);
        } else {
            $.flash.error('Failure', '...... '+statusmessage);
        }
    }
}
*/


