// Header Links
// version 0.0.0.0.0
// 2006-03-27
// Copyright (c) 2006, Justin Kikiy
// released nder the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
// ---------------------------------------------------------------------
//
// I have no intent of maintaining this or making it look pretty.
// Feel free to submit patches via the comments on 
// http://blogs.openaether.org/?p=160
//
//
// ---------------------------------------------------------------------
//
// This is a Greasemonkey user script.
//
// To install, you need Greasemonkey: http://greasemonkey.mozdev.org/
// Then restart Firefox and revisit this script.
// Under Tools, there will be a new menu item to "Install User Script".
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select "Hello World", and click Uninstall
//
// ---------------------------------------------------------------------
//
// ==UserScript==
// @name  Header Links
// @namespade http://blogs.openaether.org/data
// @description grabs all links in the header and inserts them in a popup list
// @include *
// ==/UserScript==


window.oaHeadCss=function(){
  /* generate the css */
  var head = document.getElementsByTagName('head')[0];
  if(!head){return;}

  var style = document.createElement('style');
  style.type = 'text/css';

  styleHtml="ul#oamenu {position:absolute;text-align:left;z-index:10;background-color: white;color: black;list-style-type:none;padding:10px;}";
  styleHtml+="ul#oamenu li ul {display: none;}";
  styleHtml+="ul#oamenu li:hover > ul {display: block;background-color: white;color: black;}";
  styleHtml+="ul#oamenu li ul li {border-style: solid;border-width: 1px;padding: 0px 10px 0px 10px;}";
  style.innerHTML = styleHtml;
  head.appendChild(style);
}

window.oaHeadGenList=function(){
  var links = document.getElementsByTagName('link')
    if(!links){return;}
  if(links.length<=0){return;}


  var menu=document.createElement("div");
  var htmlstr="<ul id=\"oamenu\"><li>Head<ul>";
  for(var li=0; li<links.length; ++li){
    var title,type,link=links[li];
    if(link.title){
      title=link.title;
    }else if(link.type){
      title=link.type;
    }else if(link.href){
      title=link.href;
    }
    htmlstr+="<li><a href=\""+link.href+"\">"+title+"</a></li>";

  }
  htmlstr += "</ul></li></ul>";
  menu.innerHTML=htmlstr;

  document.body.insertBefore(menu,document.body.firstChild);
}


window.addEventListener('load',window.oaHeadCss,true);
window.addEventListener('load',window.oaHeadGenList,true);

