bt_addEvent(window,"load",fixThumbLinks);

sImage = null;

function fixThumbLinks() {
 // Get a list of all links in the page
 var allLinks = document.getElementsByTagName('a');
 // Walk through the list
 var linksLen = allLinks.length;
 for (var i=0;i<linksLen;i++) {
   var lnk = allLinks[i];
   if (lnk.className=='thumblink'){
     bt_addEvent(lnk,'click',loadImg);
   }
 }
}

function bt_addEvent(elm, evType, fn, useCapture){
 if (elm.addEventListener){
   elm.addEventListener(evType, fn, useCapture);
   return true;
 } else if (elm.attachEvent){
   var r = elm.attachEvent("on"+evType, fn);
   return r;
 }
}

function loadImg(e) {
        var thumb;
        var link;
        if (!e) var e = window.event;
        if (e.target) thumb = e.target;
        else if (e.srcElement) thumb = e.srcElement;
        if (thumb.nodeType == 3) // defeat Safari bug
               thumb = thumb.parentNode;
        link = thumb.parentNode;
        sImage = new Image;
        sImage.src = link.href;
        bt_addEvent(sImage,'load',swap);

 // And stop the actual click happening
 if (window.event) {
   window.event.cancelBubble = true;
   window.event.returnValue = false;
 }
 if (e && e.preventDefault && e.stopPropagation) {
   e.preventDefault();
   e.stopPropagation();
 }
}

function swap(){

        var rvphoto = document.images['rv_photo'];
        rvphoto.width = sImage.width;
        rvphoto.height = sImage.height;
        rvphoto.src = sImage.src;
        sImage.src = null;
        
}

function pop_win(page,w,h)
{
        var screenwidth = window.screen.availWidth;
        var screenheight = window.screen.availHeight;
        var halfwidth = Math.floor(w/2);
        var halfheight = Math.floor(h/3);

        var leftpos = screenwidth/2 - halfwidth;
        var toppos = screenheight/3 - halfheight;

        var _width = "width="+w+",";
        var _height = "height="+h+",";
        var _scroll = "scrollbars=no,resizable=no,";
        var _posLeft= "screenX=" + leftpos + ",left=" + leftpos + ",";
        var _posTop = "screenY=" + toppos + ",top=" + toppos ;

        var w = window.open(page,"_blank", _width + _height + _scroll + _posLeft + _posTop);

        w.focus();
        return false;
}

function toggleChild(clicked){
	var ch = clicked.firstChild.nextSibling.style;
	ch.display = (ch.display == 'block') ? 'none' : 'block';
}