HW.Highlighter = {
	init:function() {
		_$$('.Highlighter').each(function(o){o.extendObject(HW.Highlighter.Element).init();});
	}
}

HW.Highlighter.Element = {
	init:function() {
		var obj = this;
		this.bind('mouseover',function(){obj.over();});
		this.bind('mouseout',function(){obj.out();});
		this.makeHighlightMethod();
	},
	reg:function(str) {
		return new RegExp("(^|\\w*)"+str+"(\\d*|([\\w* ]))");
	},
	over:function() {
		var obj = this;
		if(this.reg('HighlighterItem').exec(this.className)) {
			var cls = this.reg('HighlighterItem').exec(this.className)[0];
			_$$('.'+cls).each(function(o){if(o!=obj){o.highlight();}});
		}
	},
	out:function() {
		var obj = this;
		if(this.reg('HighlighterItem').exec(this.className)) {
			var cls = this.reg('HighlighterItem').exec(this.className)[0];
			_$$('.'+cls).each(function(o){if(o!=obj){o.unhighlight();}});
		}
	},
	makeHighlightMethod:function() {
		if(this.tagName == 'AREA') {
			this.makeHighlighter = function() {
				var map = this.parentNode.id;
				var img = null;
				_$$('img').each(function(_img){if(_img.useMap=='#'+map){img=_img;}});
				if(img && img.currentStyle) {
					var style = img.currentStyle;
				}
				else {
					var style = window.getComputedStyle(img,'');
				}
				var c = this.coords.split(',');
				var l=0,t=0,o=img;
				while(o.offsetParent) {
					l += o.offsetLeft;
					t += o.offsetTop;
					o = o.offsetParent;
				}
				this.highlighter = HW.createNode('div',img.parentNode).hide();
				this.highlighter.setStyle({
					left:l+parseInt(c[0])+parseInt(style.paddingLeft)+'px',
					top:t+parseInt(c[1])+parseInt(style.paddingTop)+'px',
					width:c[2]-c[0]+'px',
					height:c[3]-c[1]+'px'
				});
				this.bind('click',function(){},false);
			}
			this.highlight = function() {
				if(!this.highlighter) {
					this.makeHighlighter();
				}
				this.highlighter.addClass('HighlighterObject').show();
			}
			this.unhighlight = function() {
				if(!this.highlighter) {
					this.makeHighlighter();
				}
				this.highlighter.removeClass('HighlighterObject').hide();
			}
			if(!this.highlighter) {
				this.makeHighlighter();
			}
		}
		else {
			this.highlight = function() {
				this.addClass('Highlighted');
			}
			this.unhighlight = function() {
				this.removeClass('Highlighted');
			}
		}
	}
}

HW.onload(function(){HW.Highlighter.init();});
