// ==UserScript==
// @name           Insel Monarchie Markers
// @namespace      http://example.org/a1x/gmscripts/immarkers
// @description    Insel Monarchie - Inselmarkierungen fuer IM
// @include        http://*.insel-monarchie.de/sid/*
// ==/UserScript==
/*
Copyright (C) 2007 a1x

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
*/
function imcmt_rotate_color(event) {
  colors = new Array("white", "lime", "yellow", "magenta", "red", "green", "gray");
  var cell = event.currentTarget.parentNode;
  name = cell.parentNode.parentNode.firstChild.firstChild.firstChild.innerHTML;
  erg = name.match(/sicht:\s*(.*)\s+-\s+\d+\s+Insel/);
	name = erg[1];
  cur = cell.style.backgroundColor;
  found="white";
  for(i=0;i<colors.length-1;i++) {
	  if (cur==colors[i]) found=colors[i+1];
		}
	inr = cell.parentNode.firstChild.firstChild.innerHTML;
	GM_setValue("im_cmt_" +name + "_" + inr, found);
  cell.style.backgroundColor = found;
	event.preventDefault();
}	

var _page = document.location.href;
var tables = document.getElementsByTagName("table");

  if (_page.indexOf("home.php")>0) {
     cell = tables[16].getElementsByTagName("td");
     i = 11;
     name = cell[0].firstChild.innerHTML;
     erg = name.match(/sicht:\s*(.*)\s+-\s+\d+\s+Insel/);
	   name = erg[1];
     
     while (cell[i]) {
        nr = cell[i].getElementsByTagName("A")[0].innerHTML;
        color = GM_getValue("im_cmt_"+ name + "_" + nr, "white");
        cell[i+1].style.backgroundColor = color;
				l = document.createElement("A");
				l.style.width="10px";
				l.style.height="10px";
				l.style.textDecoration="none";
				l.addEventListener('click', imcmt_rotate_color, true);
				l.innerHTML = " * ";
				cell[i+1].appendChild(l);
				i += 12;
				}
      
  };


