(function($){
	$.fn.hoverImg = function(options){
        // Setup options
        options = jQuery.extend({
            main: 'false'
        }, options);
		
		// Current hover status
        var thistable = this;
		
		// Current URL
        var thisurl = window.location.href;
		
		function doHover(obj){
			var img = $(this).children('img')[0];
			var newsrc = img.src;
			newsrc = newsrc.substring(0, newsrc.length-4) + '_hover.png';
			img.src = newsrc;
		}
		
		$(this).children().each(function() { 
		 	//table trs
		 	$(this).children().each(function() {
				//table tds
				$(this).children().each(function() {
					var thistd = $(this);
					var thislink = thistd.children('a');

					if(thislink.length > 0) {
						// Hover effect for all links
						thislink.hover(function(){
							var img = $(this).children('img')[0];
							if(options.main == 'true') {
								img.src = img.src.replace(/.png/, '_hover.png');								
							} else {
								img.src = img.src.replace(/_off/, '_hover');
							}
						}, function(){
							var img = $(this).children('img')[0];
							if(options.main == 'true') {
								img.src = img.src.replace(/_hover/, '');
							} else if($(img).attr('class') != 'selected') {
								img.src = img.src.replace(/_hover/, '_off');						
							}
								
						});
						
						var thishref = thislink.attr('href');
						
						if (thishref == '#') {
							// Add a click event if the header does not contain a link
							thislink.click(function(){
								doHover(this);
								this.blur();
								return false;
							});
						}
					}
				});
			});
		 	//alert(index + ': ' + value);
		 	//alert($(this).children()[1].nodeName); 
		 });
		
		return this;
    };
})(jQuery);
