/**
 * Include script for VVD Leiden website.
 * 
 * @author R.J.T. de Vries <rdevries@thirdwave.nl>
 * @version 1.00, 07/25/2007
 * @access public
 */
      
	//------------------------------------------------------------------------------
	// PHASE I: INCLUDE ALL NECESSARY JAVASCRIPT FILES.
	//------------------------------------------------------------------------------
	document.write("<script src='/inc/jscripts/newwin.js'></script>");
	document.write("<script src='/inc/jscripts/checkFields.js'></script>");
	document.write("<script src='/cms/jscripts/cms.cookie.js'></script>");
	document.write("<script src='/cms/jscripts/cms.functions.js'></script>");
	document.write("<script src='/cms/jscripts/cms.event.js'></script>");
	document.write("<script src='/inc/jscripts/ddMenus.js'></script>");
	document.write("<script src='/cms/jscripts/cms.reactionarea.js'></script>");
	document.write("<script src='/cms/jscripts/cms.dateinput.js'></script>");
	document.write("<script src='/inc/jscripts/FormDependencies.js'></script>");
  
	//------------------------------------------------------------------------------
	// PHASE II: INITIALIZATION FUNCTION, CALLED ON WINDOW LOAD EVENT
	//------------------------------------------------------------------------------

	/**
	 * Instance of the FormDependencies object.
	 * @var object formDependencies
	 * @access global
	 */
	var formDependencies = null;

	/**
	 * Date input management object, that takes care of automatically continuing to
	 * next field input.
	 * @var object dateInput
	 * @access global
	 */
	var dateinput = null;
		
	/**
	 * Instance of the ddMenus object.
	 * @var object ddmeus
	 * @access global
	 */
	var ddmenus = null;
	
	/**
	 * Initialize website. Called from window.onload event.
	 *
	 * Starts with calling the ddinit() function which initializes the dropdown
	 * menus in the website. After that, the current document is checked for forms
	 * in which special events need to be attached to form elements. (such as a
	 * select element that needs an onchange event.) Finally, I.E. is instructed 
	 * not to keep a background-image cache, as that keeps I.E. from flickering on
	 * mouseover.
	 * 
	 * @return 	void
	 * @access	public
	 */
	function init() {
		reactionArea.init();

		// set formdependencies.
		formDependencies = new FormDependencies;
		formDependencies.init();

		// initialize dateinput.
		dateinput = new Dateinput;
		dateinput.init();
	
		ddmenus = new ddMenus;
		ddmenus.init();

		if ( isIE() ) {
			try {
				document.execCommand("BackgroundImageCache", false, true);
			} catch(err) {}
		}
	} // init()

	/**
	 * Toggles the visibility of the Reaction form by resizing is to 1px (hidden)
	 * or full height (visible).
	 * 
	 * @return	void
	 */
	function toggleReactionform() {
		var reactformdiv = document.getElementById('reactformdiv');
		if ( typeof(reactformdiv) == 'undefined' || reactformdiv == 'null' ) return;
		if ( reactformdiv.style.visibility == 'visible' ) {
			reactformdiv.style.visibility = 'hidden';
			reactformdiv.style.height = '1px';
		} else {
			reactformdiv.style.visibility = 'visible';
			reactformdiv.style.height = '270px';
		}
	} // toggleReactionform()
	
	/**
	 * Load in the image in the fotoalbum to the 'big' version on the
	 * righthand-side.
	 * 
	 * @param		object		link		link element.
	 * @return	boolean						false.
	 */
	function loadImage(link) {
		var loc = link.getAttribute('loc');
		var comments = link.getAttribute('comments');
		var imgtag = document.getElementById('photo');
		var commentstag = document.getElementById('comments');
		
		if ( !imgtag || !commentstag ) return false;

		imgtag.src = '/uploads/' + loc;
		commentstag.innerHTML = comments;
		if ( !comments.length ) commentstag.style.display = 'none';
		else										commentstag.style.display = 'block';
		
		return false;
	} // loadImage()
	
	/**
	 * Insert a smiley into the textarea.
	 * 
	 * @param 	string		sCode		code for the smiley (e.g. :-))
	 * @return 	void
	 */
	function insertSmiley(sCode) {
		reactionArea.putStr(sCode);
	} // insertSmiley()
	
	/**
	 * Submit the find form.
	 * 
	 * @return boolean false
	 */
	function submit_find() {
		document.getElementById('searchform').submit();
		return false;
	} // submit_find()
	

	window.onload = init;
