/*
 *
 *	IWE getnews
 *	You must use it together with AJAX object included in iwe_calendar.js package
 *	(so you must include this after that script)
 *	To allow also news ticker to work remember to include jquery-1.2.6.pack.js
 *	and jquery.accessible-news-slider.js (for automatic slide use the Alessandro Perrone
 *	customized version)
 *
 *	Remember to change the line in startSlider() to maintain JQuery compatibility if you are using also the prototype.js library
 *	If this is the case, remember to add the following line in a <script> tag before including the prototype.js library:
 *	JQ = jQuery.noConflict();
 *	Obviously, JQ is the same global variable you will use in startSlider() to initialize the slider
 *
 */
 
 //create onDomReady Event
window.onDomReady = DomReady;

//Setup the event
function DomReady(fn)
{
	//W3C
	if(document.addEventListener)
	{
		document.addEventListener("DOMContentLoaded", fn, false);
	}
	//IE
	else
	{
		document.onreadystatechange = function(){readyState(fn)}
	}
}

//IE execute function
function readyState(fn)
{
	//dom is ready for interaction
	if(document.readyState == "interactive")
	{
		fn();
	}
}

 
function startSlider(){
	// don't need a function here if using a timer to start the slider
	//$(function(){
		//$("#news_ticker").accessNews({ // use this line if using this JQuery based getNews component together with prototype.js library
		JQ("#news_ticker").accessNews({
			headline : "News",
			speed : "normal",
			slideBy : 1
		});
	//});
}

//window.onDomReady(startSlider);

function getNews(file){
	var xmlObj = AJAX();
	// calendar data are html data, so we don't need to use the XMLParse object, but we use innerHTML instead
	if(xmlObj != null){
		xmlObj.onreadystatechange = function(){
		if(xmlObj.readyState == 4){
			if(xmlObj.status == 200 || xmlObj.status == 304){

				var newCont = xmlObj.responseText;
				// IE 6 null element replacer
				if(document.getElementById('news_list') == null){
					var el = document.getElementById('news_ticker');
					var ul = document.createElement('ul');
					ul.setAttribute('id', 'news_list');
					el.appendChild(ul);
				}
				// use innerHTML property as formatted HTML code is returned instead of XML or text data
				document.getElementById('news_list').innerHTML = newCont;

				// this function has been replaced with 'startSlider()' to allow a delayed start using a timeout
				/*
				$(function(){
					$("#news_ticker").accessNews({
						headline : "News",
						speed : "normal",
						slideBy : 1
					});

				});
				*/

				var t = setTimeout("startSlider()", 500);

			}else
				alert('Could not generate News.');
		    }
		};
		xmlObj.open('GET', file, true);
		xmlObj.send(null);
	}else
		alert('AJAX requests cannot be generated on your browser');
}

function getNewsDetail(file){
	var xmlObj = AJAX();
	// calendar data are html data, so we don't need to use the XMLParse object, but we use innerHTML instead
	if(xmlObj != null){
		xmlObj.onreadystatechange = function(){
		if(xmlObj.readyState == 4){
			if(xmlObj.status == 200 || xmlObj.status == 304){

				var newCont = xmlObj.responseText;
				// IE 6 null element replacer
				if(document.getElementById('content_index') == null){
					var el = document.getElementById('wrapper_index');
					var div = document.createElement('div');
					div.setAttribute('id', 'content_index');
					el.appendChild(div);
				}
				// use innerHTML property as formatted HTML code is returned instead of XML or text data
				document.getElementById('content_index').innerHTML = newCont;

			}else
				alert('Could not generate news detail.');
		    }
		};
		xmlObj.open('GET', file, true);
		xmlObj.send(null);
	}else
		alert('AJAX requests cannot be generated on your browser');
}