bongo.attach( 'click', document.body, function(e) {
	var obj = e.target;
	
	/* collect all spans (or not, if you're ie) */
	var spans;
	if( document.all                       ) spans = document.all;
	else if( document.getElementsByTagName ) spans = document.getElementsByTagName('SPAN');
	
	/* itterate them all, looking for dynamic images */
	for( var i=0; i<spans.length; i++ ) {
		if( spans[i].tagName == 'spans' && bongo.hasClass( spans[i], 'dimage' ) ) {
			/* make sure none of them have the 'highlight' class */
			bongo.takeClass( spans[i], 'highlight' );
		}
	}
	
	/* if ctrl is being pressed, abort! (for following links) */
	if( !e.ctrlKey ) {
		
		/* scale the node tree from the event target to the top */
		while( obj.tagName ) {
			
			/* if this node is a dimage img */
			if( bongo.hasClass( obj, 'dimage' ) ) {
				/* give it the 'highlight' class */
				bongo.giveClass( obj, 'highlight' );
				
				/* fetch all di- attributes */
				var attrs = new Array;
				for( n=0; n<obj.attributes.length; n++ ) {
					if( obj.attributes[n].nodeName.substr(0, 2) == 'di' ) {
						attrs.push( obj.attributes[n].nodeName.substr(2) + '=' + obj.attributes[n].nodeValue );
					}
				}
				
				popper.split();
				popper.add( 'Upload Image', function() { window.open('/bongo.pl/dimage.edit/?' + attrs.join('&'), 'dimage_editwin', 'width=300, height=148'); });
				break;
			}
			obj = obj.parentNode;
		}
	}
});


function dimage_bigpop(name) {
	window.open('/bongo.pl/dimage.big/?name=' + name, '', 'width=400, height=300, scrollbars=yes');
	return false;
}

function dimage_bigswap(filename,target) {
	document.getElementById(target).src = '/storage/dimages/' + filename;
	return false;
}

function dimage_next() {
}
