// version 0.1 BETA!
// Copyright (c) 2008, KARLOS
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
// --------------------------------------------------------------------
//
// 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          iGoogle rewrite URL
// @namespace     http://www.karlosp.net/
// @description   iGoogle rewrite URL
// @include       http://www.google.com/ig*
// ==/UserScript==

window.setTimeout(function() {

	var script = document.createElement('script');
	script.type = 'text/javascript';
	script.text = 'function rewriteUrl()' +
'{	var divList = document.getElementsByTagName("a");' +
	'for (var i = 0; i < divList.length; ++i) ' +
	'{ var module = divList[i];		'+
	'	var newUrl = module.toString();'+		
	'	if(newUrl.search(/slo-tech/) > 0){'+
	'		if(newUrl.search(/www/) > 0){'+
	'			newUrl = newUrl.replace(/www/, "star");}'+
	'		else{'+
	'			newUrl = newUrl.replace(/http...slo-tech/,"http://star.slo-tech");'+
	'}'+
	'	}	module.href = newUrl;'+
	'}'+
	'window.setTimeout(function() {rewriteUrl()}, 1500)'+
	'}';
	//document.body.appendChild(script);

	document.getElementsByTagName("head")[0].appendChild(script);
	
	var ref = document.getElementById('refresh-85');
	ref.setAttribute('onMouseover', 'javascript:rewriteUrl()'); 
	
	var container = document.getElementById('list-85');
	container.setAttribute('onMouseover', "rewriteUrl()");
	
	var divList = document.getElementsByTagName("a");
	for (var i = 0; i < divList.length; ++i)
	{
		var module = divList[i];
		module.addEventListener("onMouseover", function(event){rewriteUrl();}, false);
	}
	
}, 300);
