/*

	Minishow helps you create embedded slideshows on your website.
	It was written by Pawel Knapik (http://pawel.saikko.com)
	and uses the great moo.fx by Valerio Proietti (http://mad4milk.net)
	
	Minishow is distributed with MIT-style license.
	This is version 0.1, 16.04.2006.
*/

var minishow = {
	current : 0,
	max : 0,
	transitions : [], 
	el : {},
	init : function(el) {
		this.el = el;
		
		var slides = getElementsByClass('slide',el);
		this.max = slides.length;

		/* this is required to reverse the z-order of slides, so the first in the code is on top etc */
		for(var i = slides.length-1;i>=0;i--) {
			slides[i].style.zIndex = -i*5;
		}

		/* this is to create the next/prev navigation. you can re-write it with innerHTML if you wish. */
		var nav = document.createElement('div');
		nav.className = 'shownav';
		var p = document.createElement('a');
		var n = document.createElement('a');
		p.setAttribute('href','javascript:void(minishow.prev())');
		p.setAttribute('id','prevSlide');
		p.className = 'disabled';
		p.appendChild(document.createElement('span').appendChild(document.createTextNode('previous')));
		n.setAttribute('href','javascript:void(minishow.next())');
		n.setAttribute('id','nextSlide');
		n.appendChild(document.createElement('span').appendChild(document.createTextNode('next')));
		nav.appendChild(p);	nav.appendChild(n);
		el.appendChild(nav);
		
		/* adding "js" class to the slideshow container has two purposes:
		   1. slideshow is accessible when javascript is disabled
		   2. you can have different look for non-interactive version */
		   
		Element.addClassName(el,'js');
	},
	
	next : function() {
		var c = this.current;
		var currentSlide = getElementsByClass('slide',this.el)[c];
		
		/* you can change fx.Width to fx.Opacity for different transition.
		   Additionally you can use the moo.fx options to customize the transition (duration, onComplete) */
		
		   
		if(!this.transitions[c]) this.transitions[c] = new fx.Width(currentSlide)
		this.transitions[c].toggle();
		
		c == 0 ? Element.removeClassName('prevSlide','disabled') : c == this.max-2 ? Element.addClassName('nextSlide','disabled') : '';	
		c < this.max ? this.current++ : '';
			
	},
	
	prev : function() {
		var c = this.current;
		this.transitions[c-1].toggle();
		c > 0 ? this.current-- : '';
		
		c <= this.max ? Element.removeClassName('nextSlide','disabled') : '';
		c <= 1 ? Element.addClassName('prevSlide','disabled') : '';
	}	
}

/*
	getElementsByClass - idea by Dustin Diaz, shortened by Pawel Knapik.
*/
function getElementsByClass(s,n,t) {
	var c=[], e=(n?n:document).getElementsByTagName(t?t:'*'),r=new RegExp("(^|\\s)"+s+"(\\s|$)");
	for (var i=0,j=e.length;i<j;i++) r.test(e[i].className)?c.push(e[i]):''; return c }
	

window.onload = function() { minishow.init($('minishow')); }

