var UEL;
var ds_News_Pages;

if (!UEL) UEL = {};
UEL.class_News =  function () {
	this.Instances = new Array();
	$(document).ready(function(){
		if (ds_News_Pages) {
				Spry.Data.Region.addObserver("section_News", { 
					onPostUpdate: function(notifier, data) {UEL.News.initialise(true);}
				});
		} else {
			UEL.News.initialise();
		}
	});
}
UEL.class_News.prototype.Instances = null;
UEL.class_News.prototype.SelectedItem = 0;
UEL.class_News.prototype.Items = 0;
UEL.class_News.prototype.ItemW = 0;
UEL.class_News.prototype.isInitialised = false;
UEL.class_News.prototype.Slide = null;
UEL.class_News.prototype.Timer = null;
UEL.class_News.prototype.TimerOn = true;
UEL.class_News.prototype.TimerInterval = 10000;
UEL.class_News.prototype.AutoPlay = true;
UEL.class_News.prototype.funcTimer = function () {
	UEL.News.next();
};

//........................................................................:initialise
UEL.class_News.prototype.initialise =  function (isForced) {
	if (!this.isInitialised || isForced) {
		//$("#news_Prev img").mouseover(function(){ this.src = });
		this.setup();
		this.isInitialised = true;
		if (this.AutoPlay) {this.play();} else {this.pause();}
	}
}
//........................................................................:setup
UEL.class_News.prototype.setup =  function () {
		this.Slide = $("#section_News ul.News");//n.childNodes[1];
		this.Items = this.Slide.children("li");
		this.ItemW = this.Slide.parent().innerWidth();
		this.Items.each(function (i) {this.style.width = UEL.News.ItemW + 'px';} );
		this.Slide.css({width: this.ItemW * this.Items.length + 'px'});
		$("#news_PageCount").text(this.Items.length);
}
//........................................................................:
UEL.class_News.prototype.startAuto =  function () {
	UEL.News.stopAuto();
	if (UEL.News.TimerOn) UEL.News.Timer = setInterval(UEL.News.funcTimer, UEL.News.TimerInterval);
}
//........................................................................:
UEL.class_News.prototype.stopAuto =  function () {
	if (UEL.News.Timer) clearInterval(UEL.News.Timer);
}

//........................................................................:
UEL.class_News.prototype.play =  function () {
	$("#news_Play").css({display: "none"});
	$("#news_Pause").css({display: "inline"});
	this.TimerOn = true;
	this.startAuto();
}
UEL.class_News.prototype.pause =  function () {
	$("#news_Play").css({display: "inline"});
	$("#news_Pause").css({display: "none"});
	this.TimerOn = false;
	this.stopAuto();
}

UEL.class_News.prototype.next =  function () {
	this.initialise();
	this.SelectedItem++;
	if (this.SelectedItem >= this.Items.length) this.SelectedItem = 0;
	this.move();
}
UEL.class_News.prototype.prev =  function () {
	this.initialise();
	this.SelectedItem--;
	if (this.SelectedItem < 0) this.SelectedItem = this.Items.length - 1;
	this.move();
}
UEL.class_News.prototype.move =  function () {
	if (this.Slide) {
		this.Slide.animate({left: '-' + (this.SelectedItem * this.ItemW) + 'px'}, 750);
		$("#news_PageNo").text(this.SelectedItem + 1);
		this.startAuto();
	}
}

if (!UEL.News) UEL.News = new UEL.class_News();

