/**
 * Include script.
 * 
 * @author R.J.T. de Vries <rdevries@thirdwave.nl>
 * @version 1.00, 01/05/2009
 * @access public
 * @package CMS
 */
 
//------------------------------------------------------------------------------
// 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>");
document.write("<script src='/inc/jscripts/ddMenus.js'></script>");
document.write("<script src='/inc/jscripts/checkFields.js'></script>");

//------------------------------------------------------------------------------
// PHASE II: INITIALIZATION FUNCTION, CALLED ON DOCUMENT LOAD EVENT
//------------------------------------------------------------------------------

	/**
	 * Instance of ddMenus object.
	 * @var object ddmenus
	 * @access global
	 */
	var ddmenus;

	/**
	 * Initialize website. Called from <body> tag.
	 *
	 * Starts with calling the ddinit() function which initializes the dropdown
	 * menus in the website. After that, initialize photoalbum: load second image
	 * in the row of images.
	 * 
	 * @return 	void
	 * @access	public
	 */
	function init() {
		var thumblist,		// container for thumbnail images.
				thumbs;				// <a> elements in the thumbnail container.

		ddmenus = new ddMenus;
		if ( !ddmenus.init() ) {
			alert('Dropdown menus kunnen niet worden geactiveerd');
		}
				
		if ( !(thumblist = document.getElementByAttribute('className', 'thumblist')) ) {
			return false;
		}
		if ( thumbs = thumblist.getElementsByTagName('a') ) {
			loadImage(thumbs[0]);
		}
		return true;
	} // init()

	/**
	 * Confirm delete action for reactions.
	 * 
	 * @param		string		requestUri		request URL to load.
	 * @param		integer		reactionID		id of reaction to remove.
	 * @return	void
	 * @access	global
	 */
	function confirmReactionDelete(requestUri, reactionID) {
		if ( !confirm("Weet u zeker dat u deze reactie wilt verwijderen?") ) {
			return false;
		}
		var url = requestUri + '&type=reaction&act=processRemove&ids=' + reactionID;
		url += '&noredirect=1';
		document.location = url;
	} // confirmReactionDelete()
	
	/**
	 * Load an image from the thumbnail-list.
	 * 
	 * @param		object		link		the link that was clicked.
	 * @return	void
	 * @access	global
	 */
	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;
		return false;
	} // loadImage()

window.onload = init;

/* end of include script */