$(document).ready(function() { slideShow(); });

var intId;

function Slide() 
{
gallery();
intId = setInterval('gallery()',5000);
}

function slideShow() {
	$('#gallery a').css({opacity: 0.0});
	$('#gallery a:first').css({opacity: 1.0});
	$('#gallery .caption').css({opacity: 0.7});
	$('#gallery .caption').css({width: $('#gallery a').find('img').css('width')});
	$('#gallery .content').html($('#gallery a:first').find('img').attr('rel')).animate({opacity: 0.7}, 400);
	SlNums(0);
	intId = setInterval('gallery()',5000);
}


function gallery() {
	var current = ($('#gallery a.show')?  $('#gallery a.show') : $('#gallery a:first'));
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#gallery a:first') :current.next()) : $('#gallery a:first'));	
	var caption = next.find('img').attr('rel');	
	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);
	current.animate({opacity: 0.0}, 1000).removeClass('show');
	var num = current.find('img').attr('alt');
	$('#gallery .caption').animate({opacity: 0.0}, { queue:false, duration:50 }).animate({height: '1px'}, { queue:true, duration:300 });	
	$('#gallery .caption').animate({opacity: 0.7},100 ).animate({height: '100px'},500 );
	$('#gallery .content').html(caption);
	SlNums(num);
}


function DisplaySlide(i) 
{
var selected = $('#gallery a:eq(' + i + ')');
var caption = selected.find('img').attr('rel');	
$('#gallery a').removeClass('show');	
selected.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);
$('#gallery .caption').css({opacity: 0.0}).css({height: '1px'});
$('#gallery .caption').animate({opacity: 0.7},100 ).animate({height: '100px'},500 );
$('#gallery .content').css({opacity: 0.0});
$('#gallery .content').animate({opacity: 1.0},300);
$('#gallery .content').html(caption);
SlNums(i);
}

function PauseSlide(i) { DisplaySlide(i); clearInterval(intId); intId = setInterval('gallery()',5000); } 

function SlNums(e)
{
var current = ($('#gallery a.show')?  $('#gallery a.show') : $('#gallery a:first'));
var num = $('#gallery a').length;
if (e == num) { e = 0; }
var sel;
var t = '<ul>';
for (i = 0; i < num; i++)
{
ix = i + 1;
if (i == e) { sel = ' class="sel"'; }
else { sel = ''; }
t = t + '<li id="' + i + '"' + sel + '>' + ix + '</li>';
}
t = t + '</ul>';
$('#res').html(t);
$('#res li').click(function (){ var i = $(this).attr('id'); PauseSlide(i); });
}
