/*--- 
Copyright (c) Enigma Interactive 2005
Project:		SOM2 CASK
Filename:  		latest_jobs.js
Description:	Latest Jobs Javascript controller module

History
ver date  		who     	comment
-----------------------------------------------------------------------------
4	06Sep06		CT			Adjusted so that the first item in the list is displayed first
3	13Jun06		CT			Extended the pause time
2	16Mar06		AJL			Switched from setInterval to setTimeout to overcome a weird FF timing bug
2	30Jan06		AJL			updated (removed the opacity stuff, caused problems with some graphics cards)
1	17Jan06		AJL			created
---*/

var LOCAL = LOCAL || { };
LOCAL.tickPause = 10000; // milliseconds

LOCAL.cTicker = function() {
	this.inherit(OO.Timer);
}

LOCAL.cTicker.prototype = {
	initSelf: function() {
		var item,i = 1;
		var oThis = this;
		this.items = [];
		this.holder = DHTML.bind('tickerH');
		EVENT.attachEvents(document.body, 'mousemove', this.mouseMove, this);
		while (item = DHTML.bind('tickItem'+i, DHTML.Anim)) {
			this.items.push(item);
			i++;
			this.z = 1;	
		}
		this.current = -1;
		this.doScroll();
		this.restoreInterval();
		this.isOver = false;
	},
	
	doScroll: function() {
		var current = this.items[this.current];
		this.current++;
		if (this.current >= this.items.length) this.current = 0;
		if (this.current < 0) this.current = this.items.length -1;
		var next = this.items[this.current];
		next.O(100);
		next.moveTo(800, 5);
		//next.O(0);
		next.show();
		next.animate({ X: 10 }, 800);
		next.zIndex(this.z++);
		if (current) {
			current.animate({ O:  0 }, 400);
			current.setTimeout('hide', 900, current.hide);
		}
	},
	
	mouseMove: function(e) {
		if (!e.target) return;
		if (DOM.parentOf(e.target, this.holder)) {
			if (!this.isOver) {
				this.holder.className = 'ticker over';
				this.clearInterval('tick');
				this.isOver = true;
			}
		} else if (this.isOver) {
			this.holder.className = 'ticker';
			this.restoreInterval(); 
			this.isOver = false;
		}
	},

	restoreInterval: function() { this.setInterval('tick', LOCAL.tickPause, this.doScroll); }

}

PAGE.onload(function() { LOCAL.ticker = OO.create(LOCAL.cTicker); });

