$(document).ready(function() {		
	//Execute the slideShow
	slideShow();
});

var isHover = false;
function slideShow() {try{
    $('#right').click(function(){isHover = false;gallery(1);isHover = true;});
	$('#left').click(function(){isHover = false;gallery(-1);isHover = true;});
//	var toping = (($("#gallery a").height() / 2) - ($('#right').height() / 2));
//	$('#right').css({'top':toping +'px'});
//	$('#left').css({'top':toping +'px'});
	$('#right').mouseover(function () {$('#right').css({'visibility':''});$('#left').css({'visibility':''});});
	$('#right').mouseout(function () {$('#right').css({'visibility':'hidden'});$('#left').css({'visibility':'hidden'});});
	$('#left').mouseover(function () {$('#right').css({'visibility':''});$('#left').css({'visibility':''});});
	$('#left').mouseout(function () {$('#right').css({'visibility':'hidden'});$('#left').css({'visibility':'hidden'});});
	$("#gallery img").mouseover(function () {$('#right').css({'visibility':''});$('#left').css({'visibility':''});});
	$("#gallery img").mouseout(function () {$('#right').css({'visibility':'hidden'});$('#left').css({'visibility':'hidden'});});
	
    $('#gallery img').css({'opacity': '0.0'});
	$('#gallery img:first').css({'opacity': '1.0'});
	setInterval('gallery(1)',6000);
	}catch(err){alert(err);}
}

function gallery(control) {
    if(!isHover)
    {
	    var current = ($('#gallery img.show')?  $('#gallery img.show') : $('#gallery img:first'));
	    var next;
	    if(control>0)
	    {
	        next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#gallery img:first') :current.next()) : $('#gallery img:first'));	
	    }
	    else
	    {
	        next = ((current.prev().length) ? ((current.prev().hasClass('caption'))? $('#gallery img:last') :current.prev()) : $('#gallery img:last'));	
	    }
	    //Get next image caption
	    var caption = next.find('img').attr('rel');	
	    //Set the fade in effect for the next image, show class has higher z-index
	    next.css({opacity: 0.0})
	    .addClass('show')
	    .animate({opacity: 1.0}, 1000);
        //Hide the current image
	    current.animate({opacity: 0.0}, 1000)
	    .removeClass('show');
	    //Set the opacity to 0 and height to 1px
	    $('#gallery .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });	
	    //Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
	    $('#gallery .caption').animate({opacity: 0.7},100 ).animate({height: '100px'},500 );
	    //Display the content
	    $('#gallery .content').html(caption);
	}
}

