window.onload=winHope;

function winHope(){
   var x=document.getElementsByTagName("a");
   for (var i=0; i<x.length;i++){
      var url = x.item(i).toString();
      var proto = url.search("hopecenter");
      if (proto < 2)  x.item(i).setAttribute("target","hopewin");
   }
}


// start jQuery
$(document).ready(function(){

  clientVer = navigator.appVersion;
  ms6 = clientVer.indexOf("MSIE 6");
  if (ms6 < 0) {
    $("li.level1").hover(
      function(){
        $(this).children("ul").css('visibility','visible');
      },
      function(){
        $(this).children("ul").css('visibility','hidden');
      }
    );
  }
  else{
    $("ul.MenuBarHorizontal > li > ul").css('display','none');
  }
 
 
});
// end jQuery

var WindowRef = null; 

function winLaunch(theURL,wid,hgt) {
  if (wid == "" || wid < 300) wid = 500;
  if (hgt == "" || hgt < 300) hgt = 500;
  var winoptions = 'width=' + wid + ',height=' + hgt + ',resizable=yes,scrollbars=yes';
  if(WindowRef == null || WindowRef.closed){
     WindowRef = window.open(theURL,'launchwin',winoptions);
  }
  else{
     WindowRef.focus();
     WindowRef = window.open(theURL,'launchwin',winoptions);
  }
}


function initializeMap() {
     if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map_canvas"));  // create new instance of a Google map
        var hcloc = new GLatLng(35.784776, -78.660877);     // set the location for an infowindow on the map
        var marker = new GMarker(hcloc);                    // new marker instance, uses previously defined location coordinates
        map.setCenter(new GLatLng(35.784776, -78.660877), 15); // center the map so infowindow shows
        map.setUIToDefault();                                  // add default behavior and UI elements to map

     /* Create DOM to insert in the infowindow  */
        var hctitle = "The Hope Center at Pullen";             // title text of the infowindow
        var hcimg = "../images/hope_center.jpg";                        // image to display in the infowindow
        var hcInfoWinDiv = document.createElement("div");      // DOM node to insert in the infowindow
        var rcInfoWinh4 = document.createElement("h4");        // element in DOM node to hold a title
        var rcInfoWinImg = document.createElement("img");      // element in DOM node to hold an image
        hcInfoWinDiv.style.width = "262px";        // set the width of the DOM node in the infowindow
        rcInfoWinh4.innerText   = hctitle;         // place text in the h3 title (IE-specific property) 
        rcInfoWinh4.textContent = hctitle;         // place text in the h3 title (standard DOM property)
     /* set image attributes, including the location of the image (src) */
        rcInfoWinImg.setAttribute("src",hcimg);   
        rcInfoWinImg.setAttribute("width","240");  
        rcInfoWinImg.setAttribute("height","180"); 
        rcInfoWinImg.style.margin = "2px";         
        rcInfoWinImg.setAttribute("alt","The Hope Center at Pullen");  
     // insert the title and image into the hcInfoWinDiv node  
        hcInfoWinDiv.appendChild(rcInfoWinh4);
        hcInfoWinDiv.appendChild(rcInfoWinImg);
   
     // listen for the click and show the node when the event occurs  
     // GEvent.addListener(map, "tilesloaded", function() {map.openInfoWindow(hcloc,hcInfoWinDiv);});      
        GEvent.addListener(map, "tilesloaded", loadWin(map,hcloc,hcInfoWinDiv,marker));      

// to-do: Add a way for user to request text directions from a particular point
     
     }

     else {
        document.write('<a href="http://maps.google.com/maps/ms?hl=en&ie=UTF8&msa=0&msid=117582645138294063538.00046f6df967bb6887740&ll=35.785441,-78.660763&spn=0.001099,0.001939&z=19"><img src="images/altmap.jpg" width="388" height="488" alt="Location on Google Maps" /></a>');
     }
}

function loadWin(map,maploc,mapwin,marker){
      map.openInfoWindow(maploc,mapwin,{onCloseFn:addMarker(map,marker,mapwin)});
}

function addMarker(map,marker,mapwin){
      GEvent.addListener(marker, "click", function() {marker.openInfoWindow(mapwin);});
      map.addOverlay(marker);

}


// start forms

function selPartner(mtr){
  mtrSelect = document.getElementById("mentor");
  ptrSelect = document.getElementById("partner");
  x = mtrSelect.selectedIndex;
  if (x == 0) ptrSelect.selectedIndex = 5;
  else if (x == 1) ptrSelect.selectedIndex = 4;
  else if (x == 2) ptrSelect.selectedIndex = 3;
  else if (x == 3) ptrSelect.selectedIndex = 2;
  else if (x == 4) ptrSelect.selectedIndex = 1;
  else ptrSelect.selectedIndex = 0;
}

