
function attachOverlays() {
     // this function identifies the links on the page with the class 'aOverlay.
     // it then overlays the showOverlay at load time and calls the showOverlay function
     // at run time 

     //grab all links
     var arrLinks = document.getElementsByTagName('a'); 

     //itterate over the links     
     for (var x = 0; x < arrLinks.length; x++  ) {
     
          var link = arrLinks[x]; 
     
          //we are only concerned links with the class 'aOverlay'
          if ( link.getAttribute( 'class' ) == 'aOverlay' ) {
               link.onclick= function() {


                    //isolate the query string and break up the params
                    var queryString  = this.getAttribute('href').split('?');  

                    var arrParams = queryString[1].split('&'); 
                    var arrArgs = new Array(); 
     
                    //loop over the params, split them up and build an associative array
                    for (var y = 0; y < arrParams.length; y++ ) {
                         
                         var param = arrParams[ y ]; 

                         var arrElements = param.split('='); 
                         arrArgs[ arrElements[0] ] = arrElements[1]; 

                    }
                    //call the overlay function
                    showOverlay( arrArgs['series'], arrArgs['overlay'] );return false;
               }
          }
     }
}

//---------------------------

function showOverlay( argSeries, argOverlay ) {
     //Show the overlay and call the appropropriate dialog
      
     var queryString = 'series='+argSeries+'&overlay='+argOverlay;  
     
     var nextFunction = function() { 
          document.getElementById('imgLoading').style.display = ""; 

          var dBox = document.getElementById('divDialogBox'); 


          var dBoxLeft = dBox.style.left = (screen.width / 2) - (512 ) ; //this should center ish the dialog box

          dBox.style.left = dBoxLeft+"px"; 

          dialogFadeIn(); 
          document.getElementById('dialogXOut').onclick = function() { dialogFadeOut();  }; 

     }; 
     
     document.getElementById('divOverlay').style.display = 'block';
     document.getElementById('imgLoading').style.display = "block"; 

     var aHandler=   ajaxConfig ( 'getOverlay', 'divDialogBoxContainer', queryString, nextFunction, true, true  ); 
     runQuery( aHandler ); 
}

//---------------------------

function dialogFadeIn( ) {
     // manage the fade in of the overlay
     var diaBox = document.getElementById('divDialogBoxContainer'); 

     var theValue = diaBox.style.opacity;         
     theValue = theValue * 1;  
     if ( theValue < 1 ) {
          theValue = theValue + 0.08; 
          diaBox.style.opacity = theValue; 
          diaBox.style.filter = "progid:DXImageTransform.Microsoft.Alpha(Opacity="+theValue * 10+"01)";
          setTimeout('dialogFadeIn()', 1); 
     }
}

//---------------------------


function dialogFadeOut() {

     var diaBox = document.getElementById('divDialogBoxContainer'); 

     var theValue = diaBox.style.opacity;         
     theValue = theValue * 1;  
     if ( theValue > 0 ) {
          theValue = theValue - 0.08
          diaBox.style.opacity = theValue;  
          diaBox.style.filter=  "progid:DXImageTransform.Microsoft.Alpha(Opacity="+theValue * 10+"01)";
          setTimeout('dialogFadeOut()', 1); 
     }else {
          //this function clear the dialog container contents, remove the display override
          document.getElementById('divDialogBoxContainer').innerHTML = ''; 
          document.getElementById('divOverlay').style.display = 'none'; 
     }
}

