var box = {
	init: function( ParentEle ) {
		var oBoxRegExp = new RegExp("(^|\\s)box-([a-z0-9-]+)($|\\s)");
		
		var boxArray = ( typeof ParentEle != 'undefined' ? $('div,form', ParentEle) : $('div,form') );
		boxArray.filter('.box:not(.box-statisch)').filter(
			function() {
				if ( $(this).find('.i3').length > 0 ) {
					return false;
				}
				return true;
			} ).each( function(i) {
			var oHoofd, oI1, oI2;
			
			// Naam van afbeelding
			if ( regMatch = $(this).attr('class').match( oBoxRegExp ) ) {
				boxAfbeelding = regMatch[2].replace( 'box-', '' );
				$(this).removeClass( 'box '+regMatch[2] );
			} else {
				return true;
			}
			
			// Creatie van het nieuwe hoofdelement.
			oHoofd = document.createElement('div');
			$(oHoofd).attr( 'class', 'box box-'+boxAfbeelding+' '+$(this).attr('class')+' pad-geen' );
			$(oHoofd).css( { border: 'none', backgroundColor: 'transparent', margin: 0, padding: 0 } );
			
			// De nieuwe div het id van het orginele div geven indien het er is.
			if ( $(this).attr('id') ) {
				$(oHoofd).attr('id', $(this).attr('id') );
				$(this).attr('id', '');
			}
			
			// De nieuwe div de float over laten nemen van het originele div indien het er is.
			if ( $(this).css('float') ) {
				$(oHoofd).css('float', $(this).css('float') );
				$(this).css('float', 'none');
			}
			
			// Breedte automatisch maken.
			$(this).width('auto');
			
			// Originele klassenaam aanpassen en originele element laten vervangen door de nieuwe.
			$(this).attr( 'class', 'i3' );
			$(this).parent()[0].replaceChild( oHoofd, this );
			
			// Creatie van 2 div elementen en deze plaatsen in de buitenste div.
			oI1 = document.createElement('div');
			$(oI1).css( { backgroundImage: 'url(/images/box/'+boxAfbeelding+'-v.gif)' } ).attr( 'class', 'i1' );
			oI2 = $(oI1).clone()[0];
			$(oI2).attr( 'class', 'i2' );
			
			// Elementen samenvoegen
			oI2.appendChild( this );
			oI1.appendChild( oI2 );
			oHoofd.appendChild( oI1 );
			box.setZijde( oHoofd, boxAfbeelding, true );
			box.setZijde( oHoofd, boxAfbeelding, false );
			
			if ( $(this)[0].style.height ) {
				var sH = ( parseInt( $(this).css('height') ) - $(oI1).find('.bt').height() - $(oHoofd).find('.bb').height() );
				$(this).css('height', sH );
			}
		} );
	},
	setZijde: function( oHoofd, boxAfbeelding, bovenkant ) {
		var oBuiten = document.createElement("div");
		$(oBuiten).css( { backgroundImage: 'url(/images/box/'+boxAfbeelding+'-h.gif)' } );
	    $(oBuiten).append( $(oBuiten).clone() ).attr( 'class', 'b'+( bovenkant ? 't' : 'b' ) );
		
		if ( bovenkant ) {
			$(oHoofd).prepend( oBuiten );
		} else {
			$(oHoofd).append( oBuiten );
		}
	}
};
