/*
	Homeimgs v0.1 for Nyne home page <nyne.co.nz>
	Requires MooTools 1.2
	
	Author: Andrew Ferri <andrew@blacksheepcreative.co.nz>
	Created: 2 February 2009
*/

var Homeimgs = new Class({
	Implements: [Options, Events],
	
	options: {
		morphDuration: 800,
		morphInterval: 3000,
		top: -453,
		morphTransition: Fx.Transitions.Sine.easeOut,
		mainContainer: $('home-noflash')
	},
	
	initialize: function(options)
	{
		this.setOptions(options);
		this.mainContainer = this.options.mainContainer;
		
		this.cImg = 1;
		
		this.ul = this.mainContainer.getElement('ul');
		this.totalImgs = 0;
		this.ul.getElements('img').each(function(el){
			this.totalImgs++;
		}.bind(this));
		this.ul.addClass('js');
		this.ul.morph = new Fx.Morph(this.ul, {duration: this.options.morphDuration, transition: this.options.morphTransition});
		this.ulClone = this.ul.clone().inject(this.ul,'after').addClass('clone').set('opacity',0);
		this.ulClone.morph = new Fx.Morph(this.ulClone, {duration: this.options.morphDuration, transition: this.options.morphTransition});
		
		this.morph.periodical(this.options.morphInterval,this);
	},
	
	morph: function()
	{
		this.ul.morph.start({'opacity': 0});
		this.ulClone.morph.start({'opacity': 1});
		this.setUls.delay(this.options.morphDuration,this);
	},
	
	setUls: function()
	{
		var top1 = this.options.top * this.cImg;
		var cImg1 = this.cImg + 1;
		if (cImg1 >= this.totalImgs)
		{
			cImg1 = 0;
		}
		var top2 = this.options.top * cImg1;
		this.cImg++;
		if (this.cImg >= this.totalImgs)
		{
			this.cImg = 0;
		}

		this.ul.setStyle('top', top1);
		this.ulClone.setStyle('top', top2);
		this.ul.setStyle('opacity', 1);
		this.ulClone.setStyle('opacity', 0);
	}
});