/**
 * Include script for ThirdWave Website.
 * 
 * @author R.J.T. de Vries <rdevries@thirdwave.nl>
 * @version 1.00, 05/03/2007
 * @access public
 * @package BOSCHENDUIN
 */

//------------------------------------------------------------------------------
// PHASE I: INCLUDE ALL NECESSARY JAVASCRIPT FILES.
//------------------------------------------------------------------------------
document.write("<script src='/cms/jscripts/cms.event.js'></script>");
document.write("<script src='/cms/jscripts/cms.functions.js'></script>");
if ( document.all &&
	(	navigator.appVersion.indexOf("MSIE 5.") != -1 
		|| navigator.appVersion.indexOf("MSIE 6.") != -1
	)
) {
	document.write("<script src='/cms/jscripts/sarissa/sarissa.js''></script>");
} 
document.write("<script src='/inc/jscripts/jquery.js'></script>");
 //------------------------------------------------------------------------------
// PHASE II: INITIALIZATION FUNCTION, CALLED ON DOCUMENT LOAD EVENT
//------------------------------------------------------------------------------
/**
 * Initialize website.
 *
 * Initializes the dropdown menu on the website (ddmenus.init()).
 *
 * After that, the current document is checked for forms in which special
 * events need to be attached to form elements.
 * 
 * @return 	void
 * @access	global
 */
function init() {
	// add events to the username and password input elements.
	var inps = document.getElementsByTagName('input'),
			addedTo = [];
			
	if ( isIE() ) {
		try {
			document.execCommand('BackgroundImageCache', false, true);
		} catch(err) {}
	}
			
	for ( var i = 0; i < inps.length; i++ ) {
		// if ( inps.getAttribute('defaulttext') ) {
		if ( inps[i].className.indexOf('deftxt') != -1 ) {
			inps[i].setAttribute('defaultText', inps[i].value);
			addEvent(inps[i], 'focus', removeDefTxt);
			addEvent(inps[i], 'blur', restoreDefTxt);
			if ( !in_array(inps[i].form, addedTo) ) {
				addEvent(inps[i].form, 'submit', removeDefaultTexts);
				addedTo.push(inps[i].form);
			}
			if ( inps[i].getAttribute('defaultText') !== inps[i].value ) {
				inps[i].className = inps[i].className.replace(/ ?deftxt/, '');
			}
			if ( inps[i].getAttribute('value') !== inps[i].value ) {
				inps[i].className = inps[i].className.replace(/ ?deftxt/, '');
			}
		}
	}
	
	// if map div exists than call load function to show map
	if ( document.getElementById('map') ) {
		var gmap = new GoogleMaps();
		gmap.load('map');
		gmap.getInstaMapperPoints(1);
		gmap.setZoom(17);
	}
	if ( document.getElementById('map-large') ) {
		var gmapLarge = new GoogleMaps();
		gmapLarge.load('map-large');
		gmapLarge.getInstaMapperPoints();
		gmapLarge.getGoogleMapsRoute();
		gmapLarge.enableControl(new GMapTypeControl());
		gmapLarge.setZoom(14);
	}
	
	try { loadTweet();} catch ( e ) {}
	
	
} // init()

/**
 * Remove the default text from inputs to which this event was attached.
 * 
 * @param		object	[e]	event object for Mozilla based browsers.
 * @return	void
 */
function removeDefTxt(e) {
	if ( !e ) e = window.event;
	var eventSrc = getEventSrc(e);
	if ( eventSrc.getAttribute('defaultText') == eventSrc.value 
			&& eventSrc.className.match(/deftxt/)) {
		eventSrc.value = '';
		eventSrc.className = eventSrc.className.replace(/ ?deftxt/, '');
	}
	setTimeout( function() { eventSrc.focus(); }, 100);
} // removeDefTxt()

/**
 * A function to remove all default texts from the defaultText fields when the
 * form is submitted.
 * 
 * @param e
 * @return
 */
function removeDefaultTexts(e) {
	var it, eventSrc, inps;
	
	e = e || window.event;
	eventSrc = getEventSrc(e);
	inps = document.getElementsByAttribute('defaultText', false, 'input', eventSrc);
	for ( it in inps ) {
		if ( inps[it].className.match(/ ?deftxt/) ) {
			inps[it].value = '';
		}
	}
} // removeDefaultTexts()

/**
 * Restore the default value for inputs to which this event was attached.
 * 
 * @param		object	[e]					event object for Mozilla based browsers.
 * @param		object	[eventSrc]	use as eventSrc if given.
 * @return	void
 */
function restoreDefTxt(e, eventSrc) {
	if ( !eventSrc ) {
		if ( !e ) e = window.event;
		eventSrc = getEventSrc(e);
	}
	if ( eventSrc.value == '' ) {
		if ( eventSrc.getAttribute('defaultText') !== undefined ) { 
			eventSrc.value = eventSrc.getAttribute('defaultText');
		} else {
			eventSrc.value = '';
		}
		if ( !/( |^)deftxt($| )/.test(eventSrc.className) ) {
			eventSrc.className = trim(eventSrc.className + ' deftxt');
		}
	}
} // restoreDefTxt()

sfHover = function() {
	if ( document.getElementById('ddmenu') ) {
		var sfEls = document.getElementById('ddmenu').getElementsByTagName('LI');
		for ( var i = 0; i < sfEls.length; i++ ) {
			sfEls[i].onmouseover=function() {
				this.className+=" hover";
			};
			sfEls[i].onmouseout=function() {
				this.className = this.className.replace(new RegExp(" hover\\b"), "");
			};
		}
	}
};
if (window.attachEvent) window.attachEvent('onload', sfHover);

window.onload = init;

/* end of include script */

