
var Slider =
{	
	fx    : null,
	fire  : true,
	ul    : null,
	width : 960,
	nodes : [],
	
	settings : {},
	
	load : function(settings)
	{
		this.settings = settings || {};
		
		this.ul	= $('content-slider');
		var z   = 0;
		
		var allNodes = this.ul.getElementsByTagName('li');
		
		for (var i = 0; i < allNodes.length; i++) 
	   	{
			if (allNodes[i].parentNode  == this.ul )
			{
				this.nodes[z] = allNodes[i];
				z++;
			};
	   	};
	   	
		this.fx = new Fx.Morph(this.ul, {
			duration: 500
		});
		
		$('slidenext').onclick = function() {
			Slider.next();
		};
		
		$('slideprev').onclick = function() {
			Slider.prev();
		};
	},

	next : function()
	{
		var left = parseInt(this.ul.style.left) - this.width; 

		if (this.ul.offsetWidth < (-1*left+100)) {
			left = 0;
		};
		
		left = this.check(left);
		
		if (this.settings['onslide']) {
			this.settings['onslide'](left);
		};
		
		this.fx.cancel();
		this.fx.start({
			left : left +'px'
		});
	},
	
	prev : function()
	{
		var left = parseInt(this.ul.style.left) + this.width; 
		
		if (left > 0) {
			left = 0;
		};
		
		left = this.check(left);
		
		if (this.settings['onslide']) {
			this.settings['onslide'](left);
		};
		
		this.fx.cancel();
		this.fx.start({
			left : left +'px'
		});
	},
	
	goTo : function(elm, ancor)
	{
		var nodes = this.nodes;
		var left  = 0;
		
		for (var i = 0; i < nodes.length; i++) 
	   	{
			if (elm.id != nodes[i].id)
			{
				left = left-this.width;
				continue;
			};
			
			i = nodes.length;
	   	};
		
		if (this.settings['onslide']) {
			this.settings['onslide'](left);
		};
		
		this.fx.cancel();
		this.fx.start({
			left : left +'px'
		});
	},
	
	check : function(iT)
	{
		if (iT == 0) {
			return 0; 
		};
		
		if (iT > this.nodes.length*this.width) { 
			return 0; 
		};
		
	    if (Math.abs(iT)%this.width  != 0)
	    {
	    	var nZ = Math.round(iT/this.width);
	    	nZ     = nZ*this.width
	    	
	    	return nZ;
	    };
	    
		return iT;
	}	
};
