// JavaScript Document
/*
	DOMnews 1.0
	homepage: http://www.onlinetools.org/tools/domnews/
	released 11.07.05
*/

/*
	IE e Firefox

	offsetWidth
	offsetHeight

	dimensioni di un oggetto ('DIV')

*/

/* Variables, go nuts changing those! */

	var dn_interval, dn_speed;
	// initial position
	var dn_startpos = 120
	// end position
	var dn_endpos = -200
	// Speed of scroller higher number = slower scroller
	var dn_speed = 50
	// ID of the news box
	var dn_newsID = 'notizie'
	// class to add when JS is available
	var dn_classAdd = 'hasJS'
	// Message to stop scroller
	var dn_stopMessage = 'Stop scroller'
	// ID of the generated paragraph
	var dn_paraID = 'DOMnewsstopper'

	var dn_direction = 'up'
//	var dn_direction = 'down'


/// Le inizializzazioni le faccio io, quanto lo dico io!
///
///			/* Initialise scroller when window loads */
///			window.onload = function() {
///				// check for DOM
///				if ( !document.getElementById || !document.createTextNode) {
///					return
///				}
///				initDOMnews()
///				// add more functions as needed
///			}
///			/* stop scroller when window is closed */
///			window.onunload = function() {
///				clearInterval(dn_interval)
///			}



/*
	This is the functional bit, do not press any buttons or flick any switches
	without knowing what you are doing!
*/

	var dn_scrollpos = dn_startpos

	/* Initialise scroller */
	function initDOMnews(dn_newsID_init, dn_direction_init) {

		/* ID of DOMnews element */
		if ( dn_newsID_init != '' ) {
			dn_newsID = dn_newsID_init
		}

		/* Scrolling direction */
		if ( dn_direction_init != '' ) {
			dn_direction = dn_direction_init
		}

		/* The DOMnews element */
		var n = document.getElementById(dn_newsID)

		if ( !n ) return

//		n.className = dn_classAdd
		n.style.position = 'relative'
//		n.style.position = 'absolute'
		n.style.overflow = 'hidden'
//		n.style.height = '100%'

//alert(n.offsetHeight)
//alert(n.style.top)
//alert(n.parentNode.offsetHeight + ' ' + n.offsetHeight)
//		dn_startpos = n.style.top
		dn_startpos = n.parentNode.offsetHeight //- Math.round(n.parentNode.offsetHeight/100)
		dn_scrollpos = dn_startpos
		dn_endpos = -1 * n.offsetHeight



		// initial position
//		dn_startpos = n.offsetHeight

		// end position
//		dn_endpos = n.offsetHeight-200

//		alert()

		dn_interval = setInterval('scrollDOMnews(dn_direction)',dn_speed)

/*		n.onmouseover = function() {
			clearInterval(dn_interval)
		}
		n.onmouseout = function() {
			dn_interval = setInterval('scrollDOMnews(dn_direction)',dn_speed)
		}*/
	}

	function stopDOMnews() {
		clearInterval(dn_interval)
		var n = document.getElementById(dn_newsID)
		n.className = ''
//		n.parentNode.removeChild(n.nextSibling)	// errore su ie
		return false
	}

	function scrollDOMnews(direction) {

//		var n = document.getElementById(dn_newsID).getElementsByTagName('ul')[0]
		var n = document.getElementById(dn_newsID)
//		var n = document.getElementById(dn_newsID).firstChild
//		var n = document.getElementById(dn_newsID).childNodes[1]
		n.style.top = dn_scrollpos+'px'

		if ( direction == 'down' ) {
			if ( dn_scrollpos == dn_startpos ) {
				dn_scrollpos = dn_endpos
			}
			dn_scrollpos++
		}
		else {	// up
			if ( dn_scrollpos == dn_endpos ) {
				dn_scrollpos = dn_startpos
			}
			dn_scrollpos--
		}
	}
	//
	// imposta la direzione dello scolling
	//
	function setDirection(direction) {
		clearInterval(dn_interval)
		dn_direction = direction
		dn_interval = setInterval('scrollDOMnews(dn_direction)',dn_speed)
	}

