/**
 * Prototype Klasse, die einen Toogle Link beobachtet und das Icon des Links anpasst.
 * @author Matthias Bedarff
 */
var ToggleLink = Class.create();
var	toggleLinks = new Array();

ToggleLink.prototype = {
	anchor: undefined,
	id: undefined,
	
	initialize: function(anchor, id) {
		this.anchor = anchor;
		this.id = id;
		
		document.observe('dom:loaded', (function () { this.loaded(); }).bind(this));
		Event.observe(this.anchor, 'click', (function () { this.click(); }).bind(this));
		
		toggleLinks.push(this);
	},
	
	click: function() {
		Effect.toggle(this.id, 'blind', {
			duration:0.3,
			afterFinish: (function(element) { this.toggleIcon() }).bind(this)
		});
	},
	
	loaded: function() {
		this.toggleIcon();
	},
	
	toggleIcon: function() {
		var icon = $(this.id).visible() ? 'link_minus.gif' : 'link_plus.gif';
		this.anchor.style.backgroundImage = 'url(/images/' + icon + ')';
	},
	
	toggleAllIcons: function() {
		//alert('toggleAllIcons');
		toggleLinks.each(function(toggleLink) {
			try {
				toggleLink.toggleIcon();
			} 
			catch (e) {
				// nichts tun
			}
		});
	}
}