// code for new windows
function new_window(url) {
  window.open(url, 'newwindow', 'width=800,height=550,toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes'); 
  return false;
}

// code for pop ups
function popup(url) {
  win = window.open(url, 'popupwindow', 'width=470,height=500,top=0,left=0,resizable=yes,menubar=yes,scrollbars=yes'); 
  win.focus()
  return false;
}

// code for newsletterarchive
function popup_newsletter(url) {
  win = window.open(url, 'popupwindow', 'width=480,height=500,top=0,left=0,resizable=yes,menubar=yes,scrollbars=yes'); 
  win.focus()
  return false;
}

function openSmallWin(url, myWidth, myHeight){
  myWindow = window.open( url, "theWindow", "toolbar=no,menubar=no,scrollbars=yes,resizable=yes,status=yes,location=no,width=" + myWidth + ",height=" + myHeight);
  myWindow.moveTo(10,10);
  myWindow.focus();
}

function openWin(url, myWidth, myHeight){
   myWindow = window.open( url, "theWindow", "toolbar=no,menubar=yes,scrollbars=yes,resizable=yes,status=no,location=no,width=" + myWidth + ",height=" + myHeight);
   myWindow.focus();
}

function sprout_story(url) {
   popWindow = window.open(url,"feature","toolbar=yes,location=yes,directories=yes,status=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=480,height=500");
}


var imgPath = '';
function imgToggle(imgObjectName, imgObjectState) {
    imgObject = new Object();
    imgObject = imgObjectName;
    imgObject.src = imgPath + imgObjectState;
}
function Toggle (id, newsrc){
    img = document.getElementById(id);
    img.src = newsrc;
}


// highlight the nav

var Highlight = {
    init: function() {
    
         var nav = document.getElementById('nav');
         if (nav) {
             var links = nav.getElementsByTagName('a');
             var thisurl = document.location.href;
             if (thisurl.indexOf('#') > -1) {
                  thisurl = thisurl.split(/#/)[0];
             }
             if (thisurl.indexOf('list_editables') > -1 ) {
                thisurl = document.referrer;
             }
             for (x=0,total=links.length;x<total;x++) {
                 if (Highlight.sameurl(thisurl,links[x])) {
                      Highlight.swapimg(links[x]);
                      links[x].className = 'selected';
                      var li = links[x].parentNode;
                      li.className = 'selected';
                      var ul = li.parentNode;
                      if (ul.id == 'nav') {return};
                      ul.className = 'active';
                      ul = ul.parentNode;
                      if (ul.id == 'nav') {return};
                      ul.className = 'active';
                      ul = ul.parentNode;
                      if (ul.id == 'nav') {return};
                      ul.className = 'active';
                      ul = ul.parentNode;
                      if (ul.id == 'nav') {return};
                      ul.className = 'active';
                      ul = ul.parentNode;
                      if (ul.id == 'nav') {return};
                      ul.className = 'active';
                 }
             }
         }        
    },

    normalize: function(url) {
        url = url.replace(/index.html/,'')
            //console.info(url);
            return url;
    },

    sameurl: function(url,link) {
        if (!link || !link.href){return 0}
        if (Highlight.normalize(url) == Highlight.normalize(link.href)) {return 1};
        return 0;
    },


    swapimg: function(a) {
        var imgs = a.getElementsByTagName('img');
        for(var i=0;i<imgs.length;i++) {
            var img = imgs[i];
            img.src = img.src.replace('.gif','-on.gif');
            img.className = '';
        }
    },

    addEvent: function( obj, type, fn ) {
       if ( obj.attachEvent ) {
          obj['e'+type+fn] = fn;
          obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
          obj.attachEvent( 'on'+type, obj[type+fn] );
       } else {
          obj.addEventListener( type, fn, false );
       }
    }


}

sfHover = function() {
        if (!document.getElementById("resources")) {return}
	var theli = document.getElementById("resources");
	theli.onmouseover=function() {
		this.className+=" sfhover";
	}
	theli.onmouseout=function() {
		this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
	}
}

if (window.attachEvent) window.attachEvent("onload", sfHover);


// setTimeout("hoveroff('find')",150);
// delay on the first mouseover on the page
// need to delay menu close


//Highlight.addEvent(window,'load',Highlight.init)