/* =Photo Gallery Viewer
-----------------------------------------------------------------------------*/
/* Fixes issue where scrolling right-side of gallery-viewer wouldn't expand to
   the full height of the photo next to it. Also positions the scroller at the
   marked photo, which could actually be done in CSS too.
 */

pictureSelector = new function() {

    //public methods
    this.gallerySetup = gallerySetup;

    // size scrollbar to height of image
    function gallerySetup() {
        if (document.getElementById("picture-selector") == null) {
            return;
        }			
        var t = setInterval(function(){
            clearInterval(t);
            thumbScroll(); // position div scroll
        }, 300);
    }

    // position scroller at the "marked" photo
    function thumbScroll() {
        var b = document.getElementById("picture-selector");
        objAgent = navigator.userAgent.toUpperCase();
        ieWin = (objAgent.indexOf("WIN") >= 0)? true : false;
        ieWin = (objAgent.indexOf("IE") >= 0 && objAgent.indexOf("OPERA") < 0)? true : false;
        for (var i = 0; i < b.childNodes.length; i++) {
            if (b.childNodes[i].id == "selected"){
                var c =  b.childNodes[i];
                break;
            }
        }
        if (ieWin) {
            b.scrollTop += Math.floor(i / 10) * (72 + 4);
        } else {
            b.scrollTop = c.offsetTop - (72 - 8 - 8);
        }
    }

}
