
/* 

  semi-fixed column by Carl Camera
  
  create your dual logo like this:
  
  +------------+  +
  |            |  |
  |            |  +--- gblLilLogoHeight
  |            |  |
  +------------+  +  +
  |            |     |
  |            |     |
  |            |     +---gblBigLogoHeight
  |            |     |
  |            |     |
  |            |     |
  +------------+     +

*/

var gblBigLogoHeight = 333;
var gblLilLogoHeight =  87;
var gblScrunch = gblBigLogoHeight-gblLilLogoHeight;
var gblExtraHeight;

function init() {

 adjustBrowsers();
 fancyRules();
 googleload();
 
 // IE 6 and below get default browser interaction 
 if (/MSIE (5\.5|6\.)/.test(navigator.userAgent)) return;

  window.onscroll = scrolling;
  window.onkeyup = scrolling;
  window.onresize = scrolling;

  // firefox has a bug that, when you switch between dragging the scrollbar
  // and spinning the mousewheel, dragging the scrollbar stops working.
  // this workaround is like attaching a thumbtack with a sledgehammer, but... 
  window.onmousemove = scrolling;
  // ...the mousemove events are very consistent.  we shouldn't have to 
  // attach onmousemove
  
  if (window.addEventListener)
  {
     document.body.addEventListener('DOMMouseScroll', scrolling, false); /* For mozilla. */
  }
  else
  {
     window.onmousewheel=document.onmousewheel=scrolling; /* IE. */
  }
}


function scrolling()
{
  gblExtraHeight = getExtraHeight();
  var viewportheight = self.innerHeight;
  
  // if all the extra stuff plus the little logo (gblLilLogoHeight) won't fit
  // into the viewport, don't even fix the column.  Let it scroll off the top.

  if ( viewportheight < (gblExtraHeight + gblLilLogoHeight) )
  {
    document.getElementById("sidebar").style.position = "relative";
    return;
  }  

  var curScrollVal = getScrollVal();

  if (curScrollVal <= gblScrunch )
  {
    // shrinking the big logo to the height of the little logo
    var newhval = (gblBigLogoHeight - curScrollVal) + "px";
    document.getElementById("logo").style.height = newhval;
        
    // simulate standard scrolling off top        
    var logoYoff = "0 " + ((gblLilLogoHeight+curScrollVal)*-1) + "px";
    document.getElementById("logo").style.backgroundPosition = logoYoff;
  }
  else
  {
    // flip the logo and show the little logo
    var newhval =  gblLilLogoHeight + "px";
    document.getElementById("logo").style.height = newhval;
 
    // y offset at the fully display value of zero
    var logoYoff = "0 0";
    document.getElementById("logo").style.backgroundPosition = logoYoff;
  }

}

function getScrollVal() {

  // note: this won't work if your doctype is not in strict
  var curScrollVal;

  // hat tip to www.quirksmode.org via snook.ca  
  if (document.documentElement && document.documentElement.scrollTop)
  {
    // Firefox 1.5, IE 6+, Opera 8+
    curScrollVal = document.documentElement.scrollTop;
  }
  else if (self.pageYOffset)
  {
    // Safari, Firefox 1.5, others
    curScrollVal = self.pageYOffset;
  }

  if (curScrollVal == null)
  {
    // any other browsers as well as anomoly in IE and Firefox
    // when scrolling back to top of page, offset becomes null
    curScrollVal = 0;
  }
  
  return(curScrollVal);

}

function getExtraHeight()
{
  var navdiv = document.getElementById("nav");
  var finddiv = document.getElementById("findboxdiv");
  var etcdiv = document.getElementById("etc");
  var divtotal = navdiv.scrollHeight+finddiv.scrollHeight+navdiv.scrollHeight; 
  return (divtotal);
}

/* js solution to hr styling problem via sitepoint.com */
function fancyRules() {
  if (!document.getElementsByTagName) return; 
  var hr = document.getElementsByTagName("hr");
  for (var i=0; i<hr.length; i++) { 
    var newhr = hr[i]; 
    var wrapdiv = document.createElement('div');
    wrapdiv.className = 'hr';  
    newhr.parentNode.replaceChild(wrapdiv, newhr);  
    wrapdiv.appendChild(newhr);  
  } 
 } 


function googleload() {

  if (document.getElementById("map") == null) { return; }

  if (GBrowserIsCompatible()) {

    var map;
    map = new GMap2(document.getElementById("map"));
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
    map.setCenter(new GLatLng(36.311653, -95.607767), 14);


    // Create our "tiny" marker icon
    var icon = new GIcon();
    icon.image = "http://labs.google.com/ridefinder/images/mm_20_blue.png";
    icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
    icon.iconSize = new GSize(12, 20);
    icon.shadowSize = new GSize(22, 20);
    icon.iconAnchor = new GPoint(6, 20);
    icon.infoWindowAnchor = new GPoint(5, 1);

    map.openInfoWindow(map.getCenter(),document.createTextNode("First Christian Church of Claremore"));
    var point = new GLatLng(36.311653, -95.607767);
    map.addOverlay(new GMarker(point,icon));

    var mapstyle = document.getElementById("map");
    mapstyle.style.font = "small arial";

   }
}

function googleunload() {

    if (document.getElementById("map") == null) { return; }
    GUnload();
}

function adjustBrowsers() {

   if (navigator.userAgent)
   {
      var theAgent = navigator.userAgent.toLowerCase();
      if (theAgent.indexOf( 'safari' ) != -1 )
      {
        // safari/konqueror engine problem rendering find box
        var boxdiv = document.getElementById("findboxdiv");
        boxdiv.style.paddingTop = "60px";
        boxdiv.style.backgroundImage = "url(images/search-bak-konq.jpg)";

        var box = document.getElementById("findbox");
        box.style.border = "3px solid white";
        box.style.height = "26px";
        box.style.padding = "0";
        box.style.fontSize = "11pt";

        var butn = document.getElementById("submitfind");
        butn.style.width = "60px";
        butn.style.height = "26px";
        butn.style.padding = "0";
        butn.style.fontSize = "11pt";
      }

      if (theAgent.indexOf( 'konqueror' ) != -1 )
      {
        document.getElementById("findboxdiv").style.paddingTop = "60px";
        document.getElementById("findboxdiv").style.backgroundImage = "url(images/search-bak-konq.jpg)";
      }

      if (theAgent.indexOf( 'camino' ) != -1 )
      {
        document.getElementById("findboxdiv").style.backgroundImage = "url(images/search-bak-camino.jpg)";
        document.getElementById("submitfind").style.fontSize = "8pt";
      }

   }


}

