/**********************************************************************************
 * 
 * LastChangedDate:		$Date: 2007-05-16 10:52:44 +0200 (Wed, 16 May 2007) $
 * LastChangedRevision	$Rev: 126 $
 * LastChangedBy:		$Author: $
 * HeadURL:				$URL: http://linux/cd/balance/trunk/httpdocs/js/nl/balance/balance.js $
 * ID:					$Id: balance.js 126 2007-05-16 08:52:44Z  $
 * 
/**********************************************************************************/

// Create namespace
if ( ! window.nl.balance ) {
	window.nl.balance = {} ;
} ;

/**
 * Balance Class
 */
nl.balance.Balance = function() {
	nl.xd.util.Event.addListener( window , 'load' , function() { nl.balance.Balance.DOC.show() ; } ) ;
} ;

/**
 * DOC Class
 */
nl.balance.Balance.DOC = function() {
	var flash ;
	
	return {
		show: function() {
			var holder = nl.xd.util.DOM.get( 'holder' ) ;
			holder.style.display = 'block' ;
			
			try {
				document.execCommand( 'BackgroundImageCache' , false , true ) ;
			} catch( e ) {} ;
			
			window.flashPlayer = deconcept.SWFObjectUtil.getPlayerVersion() ;
			
			if ( window.flashPlayer.major >= 6 ) {
				var headertypes = new Array( {tag:'h1',size:'52'} , {tag:'h2',size:'18'} , {tag:'h3',size:'24'} , {tag:'h4',size:'18'} , {tag:'h5',size:'18'} , {tag:'h6',size:'18'} ) ;
				var color		= this.getColor() ;
				
				for ( var i = 0; i < headertypes.length; i++ ) {
					this.replaceHeaders( headertypes[ i ] , color ) ;
				} ;
			} ;
		} ,
		replaceHeaders: function( headertype , bodycolor ) {
			return;
			var headers = this.getHeaders( headertype.tag ) ;
			
			for ( var i = 0; i < headers.length; i++ ) {
				if ( headers[ i ].innerHTML == '' ) {
					continue ;
				} ;
				
				var size = '' ;
				var color = '' ;
				var hover = '' ;
				var title = '' ;
				var link = '' ;
				
				switch ( headertype.tag ) {
					case 'h1' :
						color = bodycolor ;
						size  = headertype.size ;
						title = headers[ i ].innerHTML ;
						break ;
					case 'h2' :
					case 'h3' :
						color = '000000' ;
						size  = headertype.size ;
						title = headers[ i ].innerHTML ;
						break ;
					case 'h4' :
					case 'h5' :
						var a = headers[ i ].getElementsByTagName( 'a' ) ;
						
						if ( nl.xd.util.DOM.hasClass( headers[ i ] , 'inactive' ) ) {
							color = '000000' ;
						} else {
							color = bodycolor ;
						} ;
						
						size  = headertype.size ;
						title = a[ 0 ].innerHTML ;
						hover = bodycolor ;
						link  = a[ 0 ].href ;
						break ;
					case 'h6' :
						color = 'ffffff' ;
						size  = headertype.size ;
						title = headers[ i ].innerHTML ;
						break ;
				} ;
				
				var width 	   = '100%' ;
				var timestamp  = 2000 * Math.random() ;
				var height 	   = headers[ i ].offsetHeight ;
				var lineheight = parseInt( headertype.size ) + 4 ;
				var lines 	   = Math.ceil( height / lineheight ) ;
				
//				height += ( ( lines - 1 ) * 8 ) ;

				newtitle = encodeURI( title.replace( /&amp;/g , '%26' ) ) ;
				var flashvars  = '_xml=<header><size>' + size + '</size><color>' + color + '</color><hover>' + hover + '</hover><title><![CDATA[' + newtitle + ']]></title><link>' + link + '</link></header>' ;
				headers[ i ].innerHTML = window.nl.xd.flash.Simple.Standard( window._root + 'swf/h.swf' , width , height , flashvars , timestamp ) + '<span>' + title + '</span>' ;
			} ;
		} ,
		getColor: function() {
			var colors = new Array( {name:'purple',code:'7A1E99'} , {name:'green',code:'7fba00'} , {name:'orange',code:'ef6b00'} , {name:'blue',code:'0091c9'} ) ;
			var color  = document.body.id ;
			
			for ( var i = 0; i < colors.length; i++ ) {
				if ( color == colors[ i ].name ) {
					return colors[ i ].code ;
				} ;
			} ;
			
			return colors[ 0 ].code ;
		} ,
		getHeaders: function( tag ) {
			var elements = document.getElementsByTagName( tag ) ;
			var targets = new Array() ;
			
			for ( var i = 0; i < elements.length; i++ ) {
				targets[ targets.length ]= elements[ i ] ;
			} ;
			
			return targets ;
		} ,
		createCases: function() {
			var root  = nl.xd.util.DOM.get( 'cases' ) ;
			
			if ( root ) {
				var items = nl.xd.util.DOM.get( 'caseitems' ) ;
				var cases = items.getElementsByTagName( 'a' ) ;
				var color = this.getColor() ;
				
				var timestamp = 2000 * Math.random() ;
				var flashvars = '&c=' + color + '&ca=<ca>' ;
				
				for ( var i = 0; i < cases.length; i++ ) {
					flashvars += this.createCase( cases[ i ] ) ;
				} ;
				
				flashvars += '</ca>' ;
				
				items.innerHTML = window.nl.xd.flash.Simple.Standard( window._root + 'swf/case.swf' , '142' , '486' , flashvars , timestamp ) ;
			} ;
		} ,
		createCase: function( element ) {
			var text = escape( element.innerHTML ) ;
			var link  = escape( element.href ) ;
			
			return '<itm><i><![CDATA[' + link + ']]></i><q><![CDATA[' + text + ']]></q></itm>';
		}
	} ;
} () ;

/**
 * Search Class
 */
nl.balance.Balance.Search = function() {
	var defaultValue = 'zoekterm' ;
	
	return {
		_over: function( id ) {
			var item = nl.xd.util.DOM.get( id ) ;
			
			nl.xd.util.DOM.addClass( item , 'over' ) ;
		} ,
		_out: function( id ) {
			var item = nl.xd.util.DOM.get( id ) ;
			
			nl.xd.util.DOM.removeClass( item , 'over' ) ;
		} ,
		_submit: function() {
			var form = document.forms ['zoeken' ] ;
			
			form.submit() ;
		} ,
		_click: function( id ) {
			document.location = '?id=' + id ;
		} ,
		_focus: function() {
			var input = nl.xd.util.DOM.get( 'query' ) ;
			
			nl.xd.util.DOM.removeClass( input , 'default' ) ;
			
			if ( input.value == defaultValue ) {
				input.value = '' ;
			} ;
		} ,
		_blur: function() {
			var input = nl.xd.util.DOM.get( 'query' ) ;
			
			if ( input.value == '' ) {
				input.value = defaultValue ;
				nl.xd.util.DOM.addClass( input , 'default' ) ;
			} ;
		}
	} ;
} () ;

/**
 * CV Class
 */
nl.balance.Balance.CV = function() {
	return {
		browse: function() {
			var field = nl.xd.util.DOM.get( 'browse' ) ;
			nl.xd.util.DOM.removeClass( field , 'hidden' ) ;
		} ,
		send: function() {
			var form  = nl.xd.util.DOM.get( 'cvform' ) ;
			var check = nl.xd.form.Form.check( form ) ;
			
			if ( check ) {
				form.submit() ;
			} ;
		} ,
		reset: function() {
			var form = nl.xd.util.DOM.get( 'cvform' ) ;
			form.reset() ;
		} ,
		print: function() {
			window.print() ;
		}
	} ;
} () ;

/**
 * Info Class
 */
nl.balance.Balance.Info = function() {
	return {
		send: function() {
			var form  = nl.xd.util.DOM.get( 'informatieaanvragenform' ) ;
			var check = nl.xd.form.Form.check( form ) ;
			
			if ( check ) {
				form.submit() ;
			} ;
		} ,
		reset: function() {
			var form = nl.xd.util.DOM.get( 'informatieaanvragenform' ) ;
			form.reset() ;
		} ,
		print: function() {
			window.print() ;
		}
	} ;
} () ;

/**
 * SearchResult Class
 */
nl.balance.Balance.SearchResult = function() {
	return {
		over: function( item ) {
			nl.xd.util.DOM.addClass( item , 'hover' ) ;
		} ,
		out: function( item ) {
			nl.xd.util.DOM.removeClass( item , 'hover' ) ;
		}
	} ;
} () ;

/**
 * Kandidaten Class
 */
nl.balance.Balance.Kandidaten = function( color , items ) {
	this.items     = items ;
	this.color     = color ;
	this.container = nl.xd.util.DOM.get( 'kandidaten' ) ;
	
	this.interval = null ;
	this.duration = 9 ;
	this.speed    = 45 ;
	this.time     = 0 ;
	
	this.flash() ;
} ;
nl.balance.Balance.Kandidaten.prototype.expand = function() {
	clearInterval( this.interval ) ;
	
	var self = this ;
	
	this.container.style.height = nl.xd.visual.animation.Ease.outQuadratic( this.time , this.duration , 165 , 135 ) + 'px' ;
	
	if ( this.time < this.duration ) {
		this.time++ ;
		this.interval = setInterval( function() { self.expand(); } , this.speed ) ;
	} else {
		this.time = 0 ;
		self = undefined ;
	} ;
} ;
nl.balance.Balance.Kandidaten.prototype.collapse = function( time ) {
	clearInterval( this.interval ) ;
	
	var self = this ;
	
	this.container.style.height = nl.xd.visual.animation.Ease.outQuadratic( this.time , this.duration , 300 , -135 ) + 'px' ;
	
	if ( this.time < this.duration ) {
		this.time++ ;
		this.interval = setInterval( function() { self.collapse(); } , this.speed ) ;
	} else {
		this.time = 0 ;
		self = undefined ;
	} ;
} ;
nl.balance.Balance.Kandidaten.prototype.flash = function() {
	var timestamp = 2000 * Math.random() ;
	var flashvars = 'ca=<xml>' ;
	
	for ( var i = 0; i < this.items.length; i++ ) {
		flashvars += this.createItem( this.items[ i ] ) ;
	} ;
	
	flashvars += '</xml>&co=' + this.color ;
	
	this.container.innerHTML = window.nl.xd.flash.Simple.Standard( window._root + 'swf/kandidaten.swf' , 680 , '300' , flashvars , timestamp ) ;
} ;
nl.balance.Balance.Kandidaten.prototype.createItem = function( item ) {
	var xml = '' ;
	
	xml += '<e>' ;
	xml += '<i><![CDATA[' + item._ID + ']]></i>' ;
	xml += '<q><![CDATA[' + item._quote + ']]></q>' ;
	xml += '<t><![CDATA[' + item._text + ']]></t>' ;
	xml += '<s><![CDATA[' + window._root + item._small_image + ']]></s>' ;
	xml += '<l><![CDATA[' + window._root + item._large_image + ']]></l>' ;
	xml += '</e>' ;
	
	return xml ;
} ;

/**
 * Trefwoord Class
 */
nl.balance.Balance.Trefwoord = function() {
	var defaultValue = 'Zoek op trefwoord' ;
	
	return {
		_focus: function() {
			var input = nl.xd.util.DOM.get( 'trefwoord' ) ;
			
			nl.xd.util.DOM.removeClass( input , 'default' ) ;
			
			if ( input.value == defaultValue ) {
				input.value = '' ;
			} ;
		} ,
		_blur: function() {
			var input = nl.xd.util.DOM.get( 'trefwoord' ) ;
			
			if ( input.value == '' ) {
				nl.xd.util.DOM.addClass( input , 'default' ) ;
				input.value = defaultValue ;
			} ;
		}
	} ;
} () ;

/**
 * Filter Class
 * 
 * @param string
 * @param string
 * @param string
 * @param string
 * @param Array
 * @param Array
 * @param boolean
 * @param integer
 * @param boolean
 */
nl.balance.Balance.Filter = function( baseurl , target , name , title , active , items , multiple , height , onchange ) {
	this.baseurl  = baseurl ;
	this.target   = nl.xd.util.DOM.get( target ) ;
	this.name     = name ;
	this.onchange = onchange ;
	 
	this.active   = new Array() ;
	this.multiple = multiple ;
	this.height   = height ;
	this.header   = null ;
	this.items    = null ;
	this.input    = null ;
	this.interval = null ;
	
	this.initialize( title , items , active , height ) ;
	this.attachEvents() ;
} ;

/**
 * Methods
 */
nl.balance.Balance.Filter.prototype = {
	/**
	 * @param string
	 * @param Array
	 * @param Array
	 * @param integer
	 * @return void
	 */
	initialize: function( title , items , active , height ) {
		var root = document.createElement( 'div' ) ;
		
		this.input = document.createElement( 'input' ) ;
		this.input.setAttribute( 'type' , 'hidden' ) ;
		this.input.setAttribute( 'name' , this.name ) ;
		
		nl.xd.util.DOM.addClass( root , 'filter' ) ;
		
		this.items  = new nl.balance.Balance.FilterItems( this , root , title , items , active , height ) ;
		this.header = new nl.balance.Balance.FilterHeader( this , root ) ;
		
		this.target.appendChild( root ) ;
		this.target.appendChild( this.input ) ;
		
		if ( ! this.active.length ) {
			var def = this.items.getDefault() ;
			def.active() ;
			this.active.push( def ) ;
		} ;
		
		this.setInput() ;
		this.setHeaderText() ;
	} ,
		
	/**
	 * @return void
	 */
	attachEvents: function() {
		var self = this ;
		
		nl.xd.util.Event.addListener( this.target , 'mouseover' , function() { self.over() ; } ) ;
		nl.xd.util.Event.addListener( this.target , 'mouseout' , function( e ) { self.out( e ) ; } ) ;
	} ,
	
	/**
	 * @param FilterItem
	 * @return void
	 */
	click: function( filterItem ) {
		if ( filterItem.item._id == 0 ) {
			if ( this.isActive( filterItem ) ) {
				filterItem.inactive() ;
			} else {
				for ( var i = 0; i < this.active.length; i++ ) {
					this.active[ i ].inactive() ;
				} ;
				
				this.active = [ filterItem ] ;
				
				filterItem.active() ;
			} ;
		} else {
			if ( this.isActive( filterItem ) ) {
				var index = -1 ;
				
				for ( var i = 0; i < this.active.length; i++ ) {
					if ( this.active[ i ] == filterItem ) {
						index = i ;
						break ;
					} ;
				} ;
				
				if ( index > -1 ) {
					this.active.splice( index ,1 ) ;
					filterItem.inactive() ;
				} ;
			} else {
				if ( this.multiple ) {
					for ( var i = 0; i < this.active.length; i++ ) {
						if ( this.active[ i ].item._id == 0 ) {
							this.active[ i ].inactive() ;
							this.active = [] ;
							
							break ;
						} ;
					} ;
					
					this.active.push( filterItem ) ;
					filterItem.active() ;
				} else {
					this.active[ 0 ].inactive()
					this.active[ 0 ] = filterItem ;
					filterItem.active() ;
				} ;
			} ;
		} ;
		
		this.setInput() ;
		this.setHeaderText() ;
		
		if ( this.onchange && filterItem.item._id != 0 ) {
			window.location = this.baseurl + '&' + this.name + '=' + filterItem.item._id ;
		} else if ( ! this.multiple ) {
			this.hide() ;
		} ;
	} ,
	
	/**
	 * @return void
	 */
	setInput: function() {
		var value = '' ;
		
		for ( var i = 0; i < this.active.length; i++ ) {
			if ( value != '' ) {
				value += '|' ;
			} ;
			
			value += this.active[ i ].item._id ;
		} ;
		
		this.input.value = value ;
	} ,
	
	/**
	 * @return void
	 */
	setHeaderText: function() {
		var headerText = '' ;
		var maxChars   = 31 ;
		
		for ( var i = 0; i < this.active.length; i++ ) {
			if ( headerText != '' ) {
				headerText += '/' ;
			} ;
			
			headerText += unescape( this.active[ i ].item._title ) ;
		} ;
		
		if ( headerText.length > maxChars ) {
			headerText = headerText.substr( 0, maxChars ) ;
		} ;
		
		this.header.setText( headerText ) ;
	} ,
	
	/**
	 * @param FilterItem
	 * @return boolean
	 */
	isActive: function( filterItem ) {
		for ( var i = 0; i < this.active.length; i++ ) {
			if ( this.active[ i ] == filterItem ) {
				return true ;
			} ;
		} ;
		
		return false ;
	} ,
	
	/**
	 * @return void
	 */
	over: function() {
		clearInterval( this.interval ) ;
	} ,
	
	/**
	 * @param Event
	 * @return void
	 */
	out: function( e ) {
		var target = nl.xd.util.Event.relatedTarget( e ) ;
		
		if ( target ) {
			while ( target.parentNode ) {
				target = target.parentNode ;
				
				if ( target == this.target ) {
					return ;
				} ;
			} ;
		} ;
		
		clearInterval( this.interval ) ;
		
		var self = this ;
		this.interval = setInterval( function() { self.hide() ; } , 300 ) ;
	} ,
	
	/**
	 * @return void
	 */
	hide: function() {
		this.items.hide() ;
	} ,
	
	/**
	 * @return void
	 */
	show: function() {
		clearInterval( this.interval ) ;
		
		this.items.show() ;
	}
} ;

/**
 * FilterHeader Class
 * 
 * @param Filter
 * @param HTMLElement
 */
nl.balance.Balance.FilterHeader = function( filter , root ) {
	this.filter = filter ;
	
	this.container = null ;
	this.hyperlink = null ;
	
	this.initialize( root ) ;
	this.attachEvents() ;
} ;

/**
 * Methods
 */
nl.balance.Balance.FilterHeader.prototype = {
	/**
	 * @param HTMLElement
	 * @return void
	 */
	initialize: function( root ) {
		this.container = document.createElement( 'div' ) ;
		this.hyperlink = document.createElement( 'a' ) ;
		
		nl.xd.util.DOM.addClass( this.container , 'header' ) ;
		
		this.hyperlink[ 'href' ] = 'javascript:void(null);' ;
		this.hyperlink.innerHTML = 'header' ;
		
		this.container.appendChild( this.hyperlink ) ;
		root.appendChild( this.container ) ;
	} ,
	
	/**
	 * @return void
	 */
	attachEvents: function() {
		var filter = this.filter ;
		
		nl.xd.util.Event.addListener( this.hyperlink , 'click' , function() { filter.show() ; } ) ;
	} ,
	
	/**
	 * @param string
	 * @return void
	 */
	setText: function( text ) {
		this.hyperlink.innerHTML = unescape( text ) ;
	}
} ;

/**
 * FilterItems Class
 * 
 * @param Filter
 * @param HTMLElement
 * @param string
 * @param Array
 * @param Array
 * @param integer
 */
nl.balance.Balance.FilterItems = function( filter , root , title , items , active , height ) {
	this.filter = filter ;
	
	this.items       = new Array() ;
	this.container   = null ;
	this.itemsholder = null ;
	
	this.initialize( root , title , items , height ) ;
	this.createItems( items , active ) ;
} ;

/**
 * Methods
 */
nl.balance.Balance.FilterItems.prototype = {
	/**
	 * @param HTMLElement
	 * @param string
	 * @param Array
	 * @param integer
	 * @return void
	 */
	initialize: function( root , title , items , height ) {
		this.container = document.createElement( 'div' ) ;
		
		nl.xd.util.DOM.addClass( this.container , 'none' ) ;
		nl.xd.util.DOM.addClass( this.container , 'items' ) ;
		
		var shadow = document.createElement( 'div' ) ;
		
		nl.xd.util.DOM.addClass( shadow , 'shadow' ) ;
		
		this.container.appendChild( shadow ) ;
		
		if ( title != null ) {
			var titleHolder = document.createElement( 'div' ) ;
			titleHolder.innerHTML = title ;
			
			nl.xd.util.DOM.addClass( titleHolder , 'subtitle' ) ;
			
			shadow.appendChild( titleHolder ) ;
		} ;
		
		this.itemsholder = document.createElement( 'div' ) ;
		
		if ( items.length > height ) {
			nl.xd.util.DOM.addClass( this.itemsholder , 'itemsscroller' ) ;
			
			this.itemsholder.style.height = ( height * 21 ) + 'px' ;
		} else {
			nl.xd.util.DOM.addClass( this.itemsholder , 'itemswrapper' ) ;
		} ;
		
		shadow.appendChild( this.itemsholder ) ;
		
		root.appendChild( this.container ) ;
	} ,
	
	/**
	 * @param Array
	 * @param Array
	 * @return void
	 */
	createItems: function( items , active ) {
		for ( var i = 0; i < items.length; i++ ) {
			var filterItem = new nl.balance.Balance.FilterItem( this.filter , this.itemsholder , i , items[ i ] ) ;
			
			this.items[ this.items.length ] = filterItem ;
			
			for ( var p = 0; p < active.length; p++ ) {
				if ( items[ i ]._id == active[ p ] ) {
					this.filter.active.push( filterItem ) ;
					filterItem.active() ;
					
					break ;
				} ;
			} ;
		} ;
	} ,
	
	/**
	 * @return FilterItem
	 */
	getDefault: function() {
		return this.items[ 0 ] ;
	} ,
	
	/**
	 * @return void
	 */
	hide: function() {
		nl.xd.util.DOM.addClass( this.container , 'none' ) ;
	} ,
	
	/**
	 * @return void
	 */
	show: function() {
		nl.xd.util.DOM.removeClass( this.container , 'none' ) ;
	}
} ;

/**
 * FilterItem Class
 * 
 * @param Filter
 * @param HTMLElement
 * @param integer
 * @param Object
 */
nl.balance.Balance.FilterItem = function( filter , root , index , item ) {
	this.filter = filter ;
	this.item   = item ;
	
	this.container = null ;
	this.link      = null ;
	
	this.initialize( root , index ) ;
	this.attachEvents() ;
} ;

/**
 * Methods
 */
nl.balance.Balance.FilterItem.prototype = {
	/**
	 * @param HTMLElement
	 * @param integer
	 * @return void
	 */
	initialize: function( root , index ) {
		if ( this.item._id != -1 ) {
			this.container = document.createElement( 'div' ) ;
			this.link      = document.createElement( 'a' ) ;
			
			nl.xd.util.DOM.addClass( this.container , 'item' ) ;
			
			if ( index == 0 ) {
				nl.xd.util.DOM.addClass( this.link , 'first' ) ;
			} ;
			
			this.link[ 'href' ] = '#' ;
			this.link.innerHTML = '<div>' + unescape( this.item._title ) + '</div>' ;
			
			this.container.appendChild( this.link ) ;
			root.appendChild( this.container ) ;
		} ;
	} ,
	
	/**
	 * @return void
	 */
	attachEvents: function() {
		if ( this.item._id != -1 ) {
			var self   = this ;
			var filter = this.filter ;
			
			nl.xd.util.Event.addListener( this.link , 'mousedown' , function( e ) { nl.xd.util.Event.preventDefault( e ) ; } ) ;
			nl.xd.util.Event.addListener( this.link , 'click' , function( e ) { filter.click( self ) ; } ) ;
		} ;
	} ,
	
	/**
	 * @return void
	 */
	active: function() {
		if ( this.item._id != -1 ) {
			nl.xd.util.DOM.addClass( this.container , 'active' ) ;
		} ;
	} ,
	
	/**
	 * @return void
	 */
	inactive: function() {
		if ( this.item._id != -1 ) {
			nl.xd.util.DOM.removeClass( this.container , 'active' ) ;
		} ;
	}
} ;






/**
 * Selector Class
 */
nl.balance.Balance.Selector = function( baseurl , name , active , items ) {
	this.baseurl = baseurl ;
	this.name    = name ;
	this.active  = active ;
	this.items   = items ;
	
	this.interval   = null ;
	this.itemHolder = null ;
	this.activeItem = this.getItem( this.active ) ;
	
	this.build() ;
} ;
nl.balance.Balance.Selector.prototype.build = function() {
	var root   = document.createElement( 'div' ) ;
	var parent = nl.xd.util.DOM.get( 'selectors' ) ;
	
	nl.xd.util.DOM.addClass( root , 'selector' ) ;
	
	this.createHeader( root ) ;
	this.createItems( root ) ;
	
	parent.appendChild( root ) ;
} ;
nl.balance.Balance.Selector.prototype.createHeader = function( root ) {
	var div = document.createElement( 'div' ) ;
	var a   = document.createElement( 'a' ) ;
	
	nl.xd.util.DOM.addClass( div , 'header' ) ;
	
	a[ 'href' ] = 'javascript:void(null);' ;
	
	if ( this.activeItem != null ) {
		a.innerHTML = unescape( decodeURI( this.activeItem._title ) ) ;
	} else {
		a.innerHTML = 'Kies ' + this.name ;
	} ;
	
	var selector = this ;
	
	nl.xd.util.Event.addListener( a , 'mouseover' , function() { selector.over() ; } ) ;
	nl.xd.util.Event.addListener( a , 'mouseout' , function() { selector.out() ; } ) ;
	
	div.appendChild( a ) ;
	root.appendChild( div ) ;
} ;
nl.balance.Balance.Selector.prototype.createItems = function( root ) {
	this.itemHolder = document.createElement( 'div' ) ;
	
	nl.xd.util.DOM.addClass( this.itemHolder , 'items' ) ;
	nl.xd.util.DOM.addClass( this.itemHolder , 'none' ) ;
	
	for ( var i = 0; i < this.items.length; i++ ) {
		if ( this.activeItem != null && this.activeItem._id == this.items[ i ]._id ) {
			continue ;
		} ;
		
		this.createItem( this.items[ i ] , this.itemHolder ) ;
	} ;
	
	root.appendChild( this.itemHolder ) ;
} ;
nl.balance.Balance.Selector.prototype.getItem = function( id ) {
	var item = null ;
	
	for ( var i = 0; i < this.items.length; i++ ) {
		if ( this.items[ i ]._id == id ) {
			item = this.items[ i ] ;
			break ;
		} ;
	} ;
	
	return item ;
} ;
nl.balance.Balance.Selector.prototype.createItem = function( item , holder ) {
	var div = document.createElement( 'div' ) ;
	var a   = document.createElement( 'a' ) ;
	
	nl.xd.util.DOM.addClass( div , 'item' ) ;
	
	a[ 'href' ] = this.baseurl + '&' + this.name.toLowerCase() + '=' + item._id ;
	a.innerHTML = unescape( decodeURI( item._title ) ) ;
	
	var selector = this ;
	
	nl.xd.util.Event.addListener( a , 'mouseover' , function() { selector.over() ; } ) ;
	nl.xd.util.Event.addListener( a , 'mouseout' , function() { selector.out() ; } ) ;
	
	div.appendChild( a ) ;
	holder.appendChild( div ) ;
} ;
nl.balance.Balance.Selector.prototype.over = function() {
	clearInterval( this.interval ) ;
	
	nl.xd.util.DOM.removeClass( this.itemHolder , 'none' ) ;
} ;
nl.balance.Balance.Selector.prototype.out = function() {
	clearInterval( this.interval ) ;
	
	var self = this ;
	
	this.interval = setInterval( function() { self.hide() ; } , 300 ) ;
} ;
nl.balance.Balance.Selector.prototype.hide = function() {
	clearInterval( this.interval ) ;
	
	nl.xd.util.DOM.addClass( this.itemHolder , 'none' ) ;
} ;

/**
 * NewsMenu Class
 */
nl.balance.Balance.NewsMenu = function( id , active , items ) {
	this.id = id ;
	this.active = active ;
	this.items = items ;
	
	this.flash() ;
} ;
nl.balance.Balance.NewsMenu.prototype.flash = function() {
	var timestamp = 2000 * Math.random() ;
	var flashvars = '_xml=<xml>' ;
	
	var url = document.URL ;
	var qmp = url.indexOf( '?' ) ;
	
	if ( qmp != - 1 ) {
		url = url.substring( 0 , qmp ) ;
	} ;
	
	flashvars += '<id>' + url + '?id=' + this.id + '</id>' ;
	flashvars += '<active>' + this.createItem( this.active ) + '</active>' ;
	flashvars += '<items>' ;
	
	for ( var i = 0; i < this.items.length; i++ ) {
		flashvars += this.createItem( this.items[ i ] ) ;
	} ;
	
	flashvars += '</items>' ;
	flashvars += '</xml>' ;
	
	var container = nl.xd.util.DOM.get( 'newsmenu' ) ;
	container.innerHTML = window.nl.xd.flash.Simple.Standard( window._root + 'swf/newsmenu.swf' , 680 , 80 , flashvars , timestamp ) ;
} ;
nl.balance.Balance.NewsMenu.prototype.createItem = function( item ) {
	var xml = '' ;
	
	xml += '<e>' ;
	xml += '<i><![CDATA[' + item._ID + ']]></i>' ;
	xml += '<d><![CDATA[' + item._date + ']]></d>' ;
	xml += '<t><![CDATA[' + item._title + ']]></t>' ;
	xml += '</e>' ;
	
	return xml ;
} ;

/**
 * Campaign Class
 */
nl.balance.Balance.Campaign = function( mainmenu , quickmenu , content , campaigns ) {
	this.mainmenu  = 'mm=<mm>' + this.createMenu( mainmenu ) + '</mm>';
	this.quickmenu = 'qm=<qm>' + this.createMenu( quickmenu ) + '</qm>' ;
	this.content   = 'co=<co>' + this.createContent( content ) + '</co>' ;
	this.campaigns = 'ca=<ca>' + this.createCampaigns( campaigns ) + '</ca>' ;
	this.news = 'nws=' + window.newsitems;
	
	window.flashPlayer = deconcept.SWFObjectUtil.getPlayerVersion() ;
	
	if ( window.flashPlayer.major >= 6 ) {
		this.flash() ;
	} else {
		this.noflash() ;
	} ;
} ;
nl.balance.Balance.Campaign.prototype.noflash = function() {
	document.write( 'Om deze site goed te kunnen bekijken moet u in het bezit zijn van <a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&promoid=BIOW" target="_blank">Flash player</a> 6 of hoger.' )
}
nl.balance.Balance.Campaign.prototype.flash = function() {
	var middle    = nl.xd.util.DOM.get( 'middle' ) ;
	var timestamp = 2000 * Math.random() ;
	var flashvars = this.mainmenu + '&' + this.quickmenu + '&' + this.content + '&' + this.campaigns + '&' + this.news ;
	
	middle.innerHTML = window.nl.xd.flash.Simple.Standard( window._root + 'swf/campaign.swf' , 990 , 530 , flashvars , timestamp ) ;
} ;
nl.balance.Balance.Campaign.prototype.createCampaigns = function( campaigns ) {
	var xml = '' ;
	
	for ( var i =0; i < campaigns.length; i++ ) {
		xml += '<itm>' ;
		xml += '<i>' + campaigns[ i ]._id + '</i>' ;
		xml += '<q><![CDATA[' + campaigns[ i ]._quote + ']]></q>' ;
		xml += '<t><![CDATA[' + campaigns[ i ]._text + ']]></t>' ;
		xml += '<s><![CDATA[' + window._root + campaigns[ i ]._small_image + ']]></s>' ;
		xml += '<l><![CDATA[' + window._root + campaigns[ i ]._large_image + ']]></l>' ;
		xml += '</itm>' ;
	} ;
	
	return xml ;
} ;
nl.balance.Balance.Campaign.prototype.createMenu = function( menu ) {
	var xml = '' ;
	var url = document.URL ;
	var qmp = url.indexOf( '?' ) ;
	
	if ( qmp != - 1 ) {
		url = url.substring( 0 , qmp ) ;
		url = url.split( 'Home.html' ).join( '' ) ;
	} ;
	
	for ( var i =0; i < menu.length; i++ ) {
		xml += '<itm>' ;
		xml += '<i>' + url + menu[ i ]._title.split('%20').join('') + '.html?id=' + menu[ i ]._pagelinkid + '</i>' ;
		xml += '<t><![CDATA[' + menu[ i ]._title + ']]></t>' ;
		xml += '</itm>' ;
	} ;
	
	return xml ;
} ;
nl.balance.Balance.Campaign.prototype.createContent = function( content ) {
	var xml = '' ;
	
	xml += '<itm>' ;
	xml += '<pt><![CDATA[' + content._pagetitle + ']]></pt>' ;
	xml += '<t><![CDATA[' + content._title1 + ']]></t>' ;
	xml += '<tt><![CDATA[' + content._text1 + ']]></tt>' ;
	xml += '</itm>' ;
	
	return xml ;
} ;

new nl.balance.Balance() ;
