﻿// JScript File

function initPopup(){
    var allDivs = document.getElementsByTagName("div");
    
    for (var i=0; i<allDivs.length; i++){
        var currentDiv = allDivs[i];
        if (currentDiv.className.indexOf("capImgThumb") != -1){
            
            // set width
            var getImg = currentDiv.getElementsByTagName("img");
            var currentImg = getImg[0];
            //var divWidth = currentImg.getAttribute("width");
            var divWidth = currentImg.clientWidth;
            var newWidth = eval(divWidth);
            currentDiv.style.width = (newWidth + 6) + "px";
            
            // go to rollover
            currentDiv.onmouseover = function(){
                rollover(this);
            }
            currentDiv.onmouseout = function(){
                rollout(this);
            }
            
            
            // init links
            var aLinks = currentDiv.getElementsByTagName("*");
            var currentHref = aLinks[0].href;
            var splitHref = currentHref.split("#");
            aLinks[0].title = splitHref[1];
            aLinks[0].href = "javascript:void(0)";
            aLinks[0].onclick = function(){
                     showPopup(this.title);   
            }
            var currentDiv = aLinks[2];
            currentDiv.id = splitHref[1] + "Arrow";
            aLinks[2].style.cursor = "pointer";
            aLinks[2].onclick = function(){
                     showPopup(this.id);   
                     //alert(this.id);
            }
            
       }
    }
}

function showPopup(popupId){
    
    
if (browser.isIE) {
    
    y = document.documentElement.scrollTop
  }
  
if (browser.isNS) {
   
    y = window.scrollY;
    
  }

  
    var whichPopup = popupId;
    
    if (popupId.indexOf("Arrow") != -1){
        var splitId = popupId.split("Arrow");
        whichPopup = splitId[0];
    }
    
    var showDiv = document.getElementById(whichPopup);
   
    if (y > 19){
    showDiv.style.top = parseInt(y)-150 + "px";
    }else{showDiv.style.top = "18px";}
    showDiv.style.display = "block";    
    showDiv.style.cursor = "pointer";
    showDiv.onclick = function(){
        this.style.display = "none";
    }
    var allAs = showDiv.getElementsByTagName("a");
    for (var i=0; i<allAs.length; i++){
       if(allAs[i].className.indexOf("close") != -1){
            allAs[i].href = "javascript:void(0)";
            allAs[i].onclick = function(){
                 showDiv.style.display = "none";
            }
       }
    }
}

function rollover(thisDiv){
   var allDiv = thisDiv.getElementsByTagName("div");
   var currentDiv= allDiv[0];
   currentDiv.className = "capImgArrowOn";
   

}

function rollout(thisDiv){
   var allDiv = thisDiv.getElementsByTagName("div");
   var currentDiv = allDiv [0];
   currentDiv.className = "capImgArrow";

}

addLoadEvent(initPopup);