﻿// JScript File

//This file supports display of content inside a "popup" div using a div container and a separate, associated anchor tag
//The anchor tag that triggers the display of hte "popup" must be a named anchor where the name matches the id of the popup div
//Additionally, the "imgDetail" class must be applied to the anchor.
//
//e.g.  <a name="#popthis" class="imgDetail">Show Popup</a> <div id="popthis">Popup content goes here</div>
//
//This file contains an important YouTube API function that enables playback control of videos inside a "popup" div

function initPopup(){
    var allDivs = document.getElementsByTagName("*");
   
    for (var i=0; i<allDivs.length; i++){
        var currentDiv = allDivs[i];
        if ((currentDiv.className.indexOf("imgDetail") != -1) && (currentDiv.className.indexOf("chartImg") == -1) && (currentDiv.className.indexOf("ROSImg") == -1) && (currentDiv.className.indexOf("Popup") == -1) && (currentDiv.className.indexOf("close") == -1)){
       
            // set width
           // var getImg = currentDiv.getElementsByTagName("img");
            //var currentImg = getImg[0];
            //var divWidth = currentImg.getAttribute("width");
            //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("a");
            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);   
            }
            
           if (currentDiv.className.indexOf("survey") == -1){
            var imgThumb = currentDiv.getElementsByTagName("img");
            var currentImg = imgThumb[0];
            currentImg.id = splitHref[1] + "Img";
            currentImg.onclick = function(){
                    showPopup(this.id);   
                }     
            }
            
       }
    }
}

function showPopup(popupId){

    
if (browser.isIE) {
    
    y = document.documentElement.scrollTop
  }
  
if (browser.isNS) {
   
    y = window.scrollY;
    
  }

  
    var whichPopup = popupId;
		
    
    if (popupId.indexOf("Img") != -1){
        var splitId = popupId.split("Img");
        whichPopup = splitId[0];
    }
    
    var showDiv = document.getElementById(whichPopup);
   
    if (location.href.indexOf("2010") == -1 ) {
        if (y > 19){
        showDiv.style.top = parseInt(y)-220+ "px";
        }else{showDiv.style.top = "-220px";}
    }
    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].className.indexOf("hideVideo") == -1){
            allAs[i].href = "javascript:void(0)";
            allAs[i].onclick = function(){
                 showDiv.style.display = "none";
            }
       }
       if(allAs[i].className.indexOf("hideVideo") != -1){
            allAs[i].href = "javascript:void(0)";
            allAs[i].onclick = function(){
                 ytplayer.pauseVideo();
                 showDiv.style.display = "none";
            }
            //start playing video
            if (typeof(ytplayer) != "undefined") {
                setTimeout("ytplayer.playVideo()", 1000);
            }

       }
    }
}

function onYouTubePlayerReady(playerId) {
    ytplayer = document.getElementById("innerPlayer");
    setTimeout(ytplayer.playVideo(), 1000);
}

/*
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";

}
*/

/* added 20091207 */
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}
/* end 20091207 addition */

addLoadEvent(initPopup);