// JavaScript Document

//define an index of current image
var curIndex = 0;
var imgs = [];

//main function
jQuery.fn.trans = function($options){
	
	var current = jQuery(this);
	//define images to trans
	imgs = current.find('div.wizTransImages img');
	imgs.css('position','absolute');
	imgs.eq(curIndex).fadeIn('normal');
	
	//define the prev & next buttons
	if (imgs.length == 1 || imgs.length == 0){
		current.find('.wizTransPrev').click(function(){return false});
		current.find('.wizTransNext').click(function(){return false});
	} else {
		current.find('.wizTransPrev').click(function(){
			prev(imgs);
			return false;
		});
		current.find('.wizTransNext').click(function(){
			next(imgs);
			return false;
		});
		setInterval("next(imgs)", 5000);
	}
}

function prev(obj) {
	$(obj).eq(curIndex).fadeOut('normal');
	curIndex --;
	if (curIndex == -1) { curIndex = obj.length-1; }
	$(obj).eq(curIndex).fadeIn('normal');
}

function next(obj) {
	$(obj).eq(curIndex).fadeOut('normal');
	curIndex ++;
	if (curIndex == obj.length) { curIndex = 0; }
	$(obj).eq(curIndex).fadeIn('normal');
}
