/*******************************************************************************
 * Ajax dynamic articles Copyright (C) 2006 DTHMLGoodies.com, Alf Magne
 * Kalleland
 * 
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 * 
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 * 
 * Dhtmlgoodies.com., hereby disclaims all copyright interest in this script
 * written by Alf Magne Kalleland.
 * 
 * Alf Magne Kalleland, 2006 Owner of DHTMLgoodies.com
 * 
 * 
 ******************************************************************************/
var ajax = new sack();
var articleListObj;
var activeArticle = false;
var clickedArticle = false;
var contentObj
// Reference to article content <div>

function mouseoverArticle() // Highlight article
{
	if (this == clickedArticle)
		return;
	if (activeArticle && activeArticle != this) {
		if (activeArticle == clickedArticle)
			activeArticle.className = 'articleClick';
		else
			activeArticle.className = '';

	}
	this.className = 'articleMouseOver';
	activeArticle = this; // Storing reference to this article
}

function showContent() // Displaying content in the content <div>
{
	contentObj.innerHTML = '<br>' + ajax.response; // ajax.response is a
													// variable that contains
													// the content of the
													// external file
}

function showWaitMessage() {
	contentObj.innerHTML = '<div class="normalbold" style="margin:2px;padding:5px;"><img src="images/site/loading.gif" style="background-color:white;border-width:1px;border-style:solid;border-color:black;"><br>Seite wird aufgerufen.....<br>Bitte warten</div>';
}
function getAjaxFile(fileName) {
	ajax.requestFile = fileName; // Specifying which file to get
	ajax.onCompletion = showContent; // Specify function that will be
										// executed after file has been found
	ajax.onLoading = showWaitMessage(); // Action when AJAX is loading the file
	ajax.runAJAX(); // Execute AJAX function
}

function selectArticle() // User have clicked on an article
{
	getAjaxFile(this.id); // Calling the getAjasFile function. argument to the
							// function is id of this <li> + '.html', example
							// "article1.html"
	if (clickedArticle && clickedArticle != this)
		clickedArticle.className = '';
	this.className = 'articleClick';
	clickedArticle = this;
}

function initAjaxDemo() {
	var max = 3;
	for ( var maxno = 1; maxno <= max; maxno++) {
		articleListObj = document.getElementById('articleList' + maxno);
		if (articleListObj != null) {
			var articles = articleListObj.getElementsByTagName('LI');
			for ( var no = 0; no < articles.length; no++) {
				articles[no].onmouseover = mouseoverArticle;
				articles[no].onclick = selectArticle;
			}
		}
	}

	contentObj = document.getElementById('main');
}
window.onload = initAjaxDemo;