// *********************************************************
// * Resize content iframe
// ********************************************************* 
/*************************************************************************
     This code is from Dynamic Web Coding at http://www.dyn-web.com/
     See Terms of Use at http://www.dyn-web.com/bus/terms.html
     regarding conditions under which you may use this code.
     This notice must be retained in the code as is!
*************************************************************************/
function getDocHeight(doc) 
{
  alert("0")
  
  var docHt = 0
  var sh
  var oh;
  
  alert("1")
  
  if (doc.height) 
  {
  	docHt = doc.height;
  	alert("2")
  }
  else if (doc.body) 
  {
  	alert("3")
    if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
    if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
    if (sh && oh) docHt = Math.max(sh, oh);
    alert("4")
  }
  alert("5")
  return docHt;
}

function setIframeHeight(iframeName) 
{
  var iframeWin = window.frames[iframeName];
  
  var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
  
  alert(iframeWin);
  
  if ( iframeEl && iframeWin ) 
  { 
  	alert("a");
    
    iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous  
    alert("b");
    
    var docHt = getDocHeight(iframeWin.document);
    alert("c");
    // need to add to height to be sure it will all show
    
    alert("!!" + docHt);
    
    if (docHt) iframeEl.style.height = docHt + 30 + "px";
  }
  
  alert("yes");
}

// *********************************************************
// * Initialise page
// *********************************************************
    function page_init() 
    {
        // preload menu images
        MM_preloadImages('images/menu_home_on.gif',
                         'images/menu_news_on.gif',
                         'images/menu_about_on.gif',
                         'images/menu_choir_on.gif',
                         'images/menu_tac_on.gif',
                         'images/menu_gallery_on.gif',
                         'images/menu_get_involved_on.gif',
                         'images/menu_links_on.gif',
						 'images/menu_musicstore_on.gif',
						 'images/menu_merchstore_on.gif',
                         'images/menu_sign_up_on.gif');

        // initialise image replacement 
        initImageReplacement();

        // resize iFrame
        parent.setIframeHeight('contentFrame');
        
        positionHeaderImage();
    }


    function positionHeaderImage()
    {
        if (document.getElementById('header_container'))
        {
            var oHeader = document.getElementById('header_container');
            
            if (oHeader.scrollHeight) docHt = sh = oHeader.scrollHeight;
            if (oHeader.offsetHeight) docHt = oh = oHeader.offsetHeight;
            if (sh && oh) docHt = Math.max(sh, oh);  
            
            var imageHeight = 271;
            var minHeaderHeight = imageHeight + 14;
            
            if (docHt > minHeaderHeight)
            {
                var oImage = document.getElementById('annie_sing_image');
                oImage.style.marginTop = (docHt - minHeaderHeight + 14)+"px"
            }
            
        }
    }

// *********************************************************
// * Popup
// *********************************************************    
    function popUp(URL)
    {
        var day = new Date();
        var id = day.getTime();
        eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=no,scrollbars=yes,location=no,statusbar=no,menubar=no,resizable=yes,width=615,height=480,left=212,top=184');");
    }    

    
// *********************************************************
// * Image replacement script, based on the quirksmode one.
// *********************************************************
    function initImageReplacement() {
        var test = new Image();
        var tmp = new Date();
        var suffix = tmp.getTime();
        test.src = 'images/fir_assumptions.gif?'+suffix;
        test.onload = imageReplacement;
    }

    function imageReplacement() {
        replaceThem(document.getElementsByTagName('tt'));
    }

    function replaceThem(x) {
        var replace = document.createElement('img');
        for (var i=0;i<x.length;i++)
        {
            if (x[i].id)
            {
                var y = replace.cloneNode(true);
                y.src = 'images/' + x[i].id + '.gif';
                y.alt = x[i].firstChild.nodeValue;
                x[i].replaceChild(y,x[i].firstChild);
            }
        }
    }
    
    
// *********************************************************
// * MM rollover scripts
// *********************************************************
    function MM_swapImgRestore() 
    { //v3.0
      var i,x,a=document.MM_sr;
      for(i=0; a&&i<a.length && (x=a[i]) && x.oSrc; i++)
      {
        x.src=x.oSrc;
      }
    }

    function MM_preloadImages() { //v3.0
      var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }

    function MM_findObj(n, d) { //v4.01
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
    }

    function MM_swapImage() { //v3.0
      var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
       if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
    }