/*
	domNews 2.0
	released: 2006-10-03

	What's new?

    - Object oriented programmation
    - Multiple istance allowed
    - Vertically and horizontally scrolling

*/

//class domNews {
//}

function domNews (id, direction, speed, jsObjName) {

	/* ID of the scroller */
	this.id = ( id==undefined || id=='' || id==0 ? 'foto_gallery' : id )
	/* name of the javascript object, only for IE */
	this.jsObjName = ( jsObjName==undefined || jsObjName=='' || jsObjName==0 ? 'dn' : jsObjName )

	/* Direction and Speed of the scroller */
	this.direction = ( direction==undefined || direction=='' || direction==0 ? 'stop' : direction )
//	this.speed = ( speed==undefined || speed=='' || speed<1 ? 30 : speed )
	this.speed = 10 

	/* Scrolling variables */
	this.startPos
	this.endPos
	this.scrollPos

	/* intervalID */
	this.interval

	/* the DOM element */
	var domNewsElement = document.getElementById(this.id)
	if ( !domNewsElement ) return

	/* change the CSS properties of the scroller... */
	if ( domNewsElement.style.position!='relative' || domNewsElement.style.position!='absolute' )
		domNewsElement.style.position = 'relative'
	domNewsElement.style.overflow = 'hidden'
	/* ...and its container */
	domNewsElement.parentNode.style.overflow = 'hidden'

	/* initial positions by direction */
	switch ( this.direction ) {
 		case 'left':
 		case 'right':
			this.startPos = domNewsElement.parentNode.offsetWidth
//			this.scrollPos = this.startPos
			this.scrollPos = 0	// se lo scroller deve partire dalla posizione attuale
			this.endPos = -1 * domNewsElement.offsetWidth
			break
// 		case 'down':
//		case 'up':
		default:
			this.startPos = domNewsElement.parentNode.offsetHeight
			this.scrollPos = this.startPos
// 			this.scrollPos = 0	// se lo scroller deve partire dalla posizione attuale
			this.endPos = -1 * domNewsElement.offsetHeight
	}
}



/* Start the scrolling */
domNews.prototype.start = function () {
	if ( this.interval == undefined )
		if ( navigator.appName == 'Microsoft Internet Explorer' )
			this.interval = setInterval( this.jsObjName + '.scrolling()', this.speed)
			// ok x tutti (ie e firefox), perņ richiede la conoscenza dell'oggetto creato con "new domNews()"
		else
			this.interval = setInterval(this.scrolling, this.speed, this)
			// ok x firefox, raggiungo l'oggetto orginario passandolo come paramentro
	return
}



/* Stop the scrolling */
domNews.prototype.stop = function () {
	if ( this.interval != undefined )
		this.interval = clearInterval(this.interval)
	return
}



/* Change the scrolling direction/speed */
domNews.prototype.update = function (direction, speed) {
	this.stop()
	this.direction = ( direction==undefined || direction=='' || direction==0 ? 'stop' : direction )
	this.speed     = ( speed==undefined     || speed==''     || speed<1      ? this.speed   : speed )
	this.start()
}



/* Scrolling function */
domNews.prototype.scrolling = function (jsNewsElement) {

	/* jsNewsElement is defined if the browser isn't IE */
	if ( jsNewsElement == undefined )
		if ( this.direction == undefined )
			return
		else
			jsNewsElement = this

	var domNewsElement = document.getElementById(jsNewsElement.id)

	switch ( jsNewsElement.direction ) {

		case 'stop':
			jsNewsElement.stop()
			break

		case 'left':
			domNewsElement.style.left = jsNewsElement.scrollPos + 'px'
			if ( jsNewsElement.scrollPos == jsNewsElement.endPos ) jsNewsElement.scrollPos = jsNewsElement.startPos
			jsNewsElement.scrollPos--
			break

		case 'right':
			domNewsElement.style.left = jsNewsElement.scrollPos + 'px'
			if ( jsNewsElement.scrollPos == jsNewsElement.startPos ) jsNewsElement.scrollPos = jsNewsElement.endPos
			jsNewsElement.scrollPos++
			break

		case 'down':
			domNewsElement.style.top = jsNewsElement.scrollPos + 'px'
			if ( jsNewsElement.scrollPos == jsNewsElement.startPos ) jsNewsElement.scrollPos = jsNewsElement.endPos
			jsNewsElement.scrollPos++
			break

//		case 'up':
		default:
			domNewsElement.style.top = jsNewsElement.scrollPos + 'px'
			if ( jsNewsElement.scrollPos == jsNewsElement.endPos ) jsNewsElement.scrollPos = jsNewsElement.startPos
			jsNewsElement.scrollPos--
	}
}


