
var script = document.createElement('script'); script.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'; 
script.type = 'text/javascript'; document.getElementsByTagName('head')[0].appendChild(script); 


function findDivsLike(startingWith) {
    var els = document.getElementsByTagName('div');
    var i = els.length;
    var arr = [];
    var saveCnt = 0;
    while (i--) {
        if (els[i].id.indexOf(startingWith) == 0) {
            arr[saveCnt] = els[i].id;
            saveCnt++;
        }
    }
    return arr;
}


function hideDivsLike(idStart) {
    hideDivsByID(findDivsLike(idStart));
}

//function toggleDisplay(id, scroll) {
//    var vis = getDisplay(id);
//    if (vis) {
//        setDisplay(id, false);
//    }
//    else {
//        setDisplay(id, true);
//        if (scroll) document.getElementById(id).scrollIntoView(false);
//    }
//}

function toggleVis(id, scroll) {
     toggleDivVisibility(id, scroll);
}

function toggleDivVisibility(id, scroll) {
    var vis = isDivVisible(id);
    if (vis) {
        hideDiv(id);
    }
    else {
        showDiv(id);
        if (scroll) document.getElementById(id).scrollIntoView(false);
    }
}

function hideDivsByID(idArray) {
    //loop through the array and hide each element by id
    if (idArray == null) return;
    for (var i = 0; i < idArray.length; i++) {
        hideDiv(idArray[i]);
    }
}

function setVisibility(el, vis) {               // Used for POIs. As opposed to using 'display', i.e., hideDiv(
    if (el == null) return;
    if (vis)
        el.style.visibility = 'visible';
    else
        el.style.visibility = 'hidden';
}

//function setVisibility(el, vis) {
//    if (el == null) return;
//    var disp;
//    if (vis)
//        disp = 'block';
//    else
//        disp = 'none';
//    el.style.display = disp;
//}

//function getVisibility(el) {
//    if (el.style == null) return false;
//    return (el.style.display == 'block');
//    //return (el.style.visibility == 'visible');
//}

//function getDisplay(el) {
//    if (el.style == null) return false;
//    return (el.style.display == 'block');
//}

function isDivVisible(id) {
    return $("#" + id).css('display') == 'block';
}

function hideDiv(id) {
    $("#" + id).hide();
}

function showDiv(id) {
    $("#" + id).show();
}

function keyNav(event) {
    var b = 0
    switch (event.keyCode) {
        case 37:
            doPrev();
            b = 1
            break;
        case 39:
            doNext();
            b = 1
            break;
        default:
    }
    if (b == 1) event.returnValue = false;
}

function doNext() {
    if(nextpage != null && nextpage.length > 0) document.location = nextpage;  // nextpage is set by photo page gen
}
function doPrev() {
    if (prevpage != null && prevpage.length > 0) document.location = prevpage; 
}

function getSize() { return [$(window).width(), $(window).height()]; }

function resizeImage(name, w, h) {	//Need both for Chrome/IE/Firefox

    var image = document.getElementById(name)
    image.width = Math.max(w, 40);
    image.height = Math.max(h, 40);
    image.style.width = Math.max(w, 40).toString() + 'px';
    image.style.height = Math.max(h, 40).toString() + 'px';
}

