/**********************************************************************************
 * 
 * LastChangedDate:		$Date: 2007-02-13 13:54:48 +0100 (Tue, 13 Feb 2007) $
 * LastChangedRevision	$Rev: 63 $
 * LastChangedBy:		$Author: $
 * HeadURL:				$URL: http://linux/cd/balance/trunk/httpdocs/js/nl/balance/balance.js $
 * ID:					$Id: balance.js 63 2007-02-13 12:54:48Z  $
 * 
/**********************************************************************************/

// Create namespace
if ( ! window.nl.schaapskooi ) {
	window.nl.schaapskooi = {} ;
} ;

/**
 * Schaapskooi Class
 */
nl.schaapskooi.Schaapskooi = function() {
	nl.xd.util.Event.addListener( window , 'load' , function() { nl.schaapskooi.Schaapskooi.DOC.show() ; } ) ;
} ;

/**
 * DOC Class
 */
nl.schaapskooi.Schaapskooi.DOC = function() {
	var flash ;
	
	return {
		show: function() {
			window.flashPlayer = deconcept.SWFObjectUtil.getPlayerVersion() ;
			
			if ( window.flashPlayer.major >= 6 ) {
				this.showMenu() ;
				
				var headertypes = new Array( {tag:'h1',size:'16'} ) ;
				
				for ( var i = 0; i < headertypes.length; i++ ) {
					this.replaceHeaders( headertypes[ i ] ) ;
				} ;
			} ;
		} ,
		replaceHeaders: function( headertype ) {
			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 = this.getColor( headers[ i ] ) ;
						size  = headertype.size ;
						title = headers[ i ].innerHTML ;
						
						var a = headers[ i ].getElementsByTagName( 'a' ) ;
						
						if ( a.length ) {
							title = a[ 0 ].innerHTML ;
							hover = '#ffffff' ;
							link  = a[ 0 ].href ;
						} else {
							title = headers[ i ].innerHTML ;
						} ;
						break ;
				} ;
				
				var width 	   = headers[ i ].offsetWidth ;
				var timestamp  = 2000 * Math.random() ;
				var height 	   = headers[ i ].offsetHeight ;
				var lineheight = parseInt( headertype.size ) ;
				var lines 	   = Math.floor( height / lineheight ) ;
				height         = lines * lineheight ; // fix IE bug
				
				title = title.replace( '&amp;' , '%26' ) ;
				
				newtitle = encodeURI( title ) ;
				newtitle = newtitle.toUpperCase() ;
				
				var flashvars  = '_xml=<header><height>' + height + '</height><lineheight>' + lineheight + '</lineheight><size>' + size + '</size><color>' + color + '</color><title><![CDATA[' + newtitle + ']]></title></header>&id=' + timestamp ;
				headers[ i ].innerHTML = window.nl.xd.flash.Simple.Standard( 'swf/h.swf' , width , height , flashvars , timestamp ) + '<span>' + title + '</span>' ;
			} ;
		} ,
		getColor: function( element ) {
			color = '#000000' ;
			
			switch ( element.className ) {
				case 'blue' :
					color = '#0099FF' ;
					break ;
					
				case 'green' :
					color = '#C1DD00' ;
					break ;
			} ;
			
			return color ;
		} ,
		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 ;
		} ,
		resetHeight: function( id , height ) {
			var flash = nl.xd.util.DOM.get( id ) ;
			
			flash.height = height ;
		} ,
		showMenu: function() {
			var path = location.href ;
			path = path.split( '?' ) ;
			path = path[ 0 ] ;
			
			var container = nl.xd.util.DOM.get( 'mainmenu' ) ;
			container.innerHTML = nl.xd.flash.Simple.Standard( 'swf/top.swf' , 900 , 245 , window.flashvars + '&path=' + path , 'mm' ) ;
		}
	} ;
} () ;

new nl.schaapskooi.Schaapskooi() ;