/**
 * JavaScript für die Navigation
 */
 
 function DiscoSurf()
 {
 	this.toggleWithImage = function( image_id, container_id )
 	{
 		var images = [
 			'/sites/discosurf/gfx/list-add.png',
 			'/sites/discosurf/gfx/list-remove.png',
 		];
 		
 		var container 	= js.e( container_id );
 		var image 		= js.e( image_id );
 		
 		js.toggle( container_id );
 		
 		(container.style.display != 'none')
 		? image.src = images[1]
 		: image.src = images[0];
 	}

	/**
	 * Fügt Popup-Events für entsprechend eingestellte Elemente hinzu
	 */
	this.addPopupEvents = function()
	{
		$('*[target^=_popup]').each( function( index )
		{
			if ( this.tagName != 'A' && this.tagName != 'INPUT' )
				return true;

			var elem = $(this);

			if ( elem.attr('href').match(/^\/popup/) )
				return true;

			elem.attr( 'href', '/popup' + elem.attr( 'href' ) );

			if ( window.location.toString().match(/\/popup\//) )
			{
				elem.attr( 'target', '_self' );
				return true;
			}

			var infos	= elem.attr( 'target' ).replace( '_popup_', '' ).split( '_' );
			var width	= infos[0];
			var height	= infos[1];

			// Event hinzufügen
			elem.bind( 'click', function()
			{
				var object = $(this);
				js.popup( object.attr( 'href' ), '', width, height, true, true, true );
				return false;
			} );

		} );
	};

	this.addPopupEvents();
 }
 
 // Instanz erstellen
 var discosurf = null;

 $( function() {
	 discosurf = new DiscoSurf();
 } );
