/*
	script:	Content Scroller
	author: Krzysztof Debinski [www.boleslawiec.org]
	source:	(c) 2008
*/

//	tablica obiektow
var	DBLmarqueeList = new Array();

/*
	konstruktor

	id:		id main container (outter)
	idin:	id moved container (inner)
	lr:		true=left/right, false=up/down
	time:	miliseconds
	speed:	pixels
*/
function	DBLmarquee(id, idin, lr, time, speed) {
	this.idContainer = id;
	this.idContent= idin;
	this.elContainer = document.getElementById(id);
	this.elContent = document.getElementById(idin);
	//	prawo/lewo czy gora/dol
	this.lrMode = lr ? true : false;
	this.speed = speed;
	this.paused = false;
	if(!this.elContainer || !this.elContent)
		return false;
	//	zapisujemy do tablicy obiektow
	DBLmarqueeList.push(this);
	this.idList = DBLmarqueeList.length -1;
	//	dodajemy do kontenera atrybut zapisujac id listy
	this.elContainer.setAttribute('DBLmarquee', this.idList);
	//	dodajemy zdarzenia
	this.addEvent(this.elContainer, 'mouseover', this.onMouseOver);
	this.addEvent(this.elContainer, 'mouseout', this.onMouseOut);
	//	uruchamiamy czas
	this.timerContent = window.setInterval('DBLmarquee.prototype.onTimerContent('+this.idList+')', time);
};

DBLmarquee.prototype = {
	//	dodanie zdarzenia
	addEvent : function(el, event, func) {
		if (el.attachEvent)
			el.attachEvent("on" + event, func);
		else
			el.addEventListener(event, func, false);
	},

	//	usuniecie zdarzenia
	removeEvent : function(el, event, func) {
		if (el.detachEvent)
			el.detachEvent("on" + event, func);
		else
			el.removeEventListener(n, func, false);
	},

	//	pauza
	onMouseOver : function(e) {
		var o = this;
		if(window.event && window.event.srcElement && !this.nodeName)
			o = window.event.srcElement;
		var	idList = o.getAttribute('DBLmarquee');
		if(!idList)
			return;
		var obj = DBLmarqueeList[idList];
		obj.paused = true;
	},

	//	kontynuacja
	onMouseOut : function(e) {
		var o = this;
		if(window.event && window.event.srcElement && !this.nodeName)
			o = window.event.srcElement;
		var	idList = o.getAttribute('DBLmarquee');
		if(!idList)
			return;
		var obj = DBLmarqueeList[idList];
		obj.paused = false;
	},

	//	interval
	onTimerContent : function(idList) {
		//	obiekt z tablicy
		obj = DBLmarqueeList[idList];
		if(obj.paused)
			return;
		var	val = obj.lrMode ? obj.elContent.style.left : obj.elContent.style.top;
		//	tylko liczba
		if(!(val = parseInt(val)))
			val = 0;
		//	przesuwamy
		val += obj.speed;
		//	spr limity
		var	cr = parseInt(obj.lrMode ? obj.elContainer.clientWidth : obj.elContainer.clientHeight);
		var	ct = parseInt(obj.lrMode ? obj.elContent.clientWidth : obj.elContent.clientHeight);
		if(obj.speed<0) {
			if(val < -ct)
				val = cr;
		} else {
			if(val >= cr)
				val = -ct;
		}
		if(obj.lrMode)
			obj.elContent.style.left = val + 'px';
		else
			obj.elContent.style.top = val + 'px';
	}
};