var busy = false;

$(document).ready(function(){
$('#content').animate({opacity: 1.0}, 200);

$('#next,#slideshow').click(function(){
slideSwitch();
});

$('#prev').click(function(){
slideSwitchPrev();
});

});

$(window).load(function(){
$('#textbox').jScrollPane();
$('#slideshow').animate({opacity:1.0},200);
}
);

function slideSwitch() {
if(!busy){
	busy = true;
    var $active = $('#slideshow IMG.active');
    //alert($active.next().length);
	if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    var $next =  $active.prev().length ? $active.prev()
        : $('#slideshow IMG:last');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 200, function() {
            $active.removeClass('active last-active');
            busy = false;
        });
	updateCounter('+');
    }    
}

function slideSwitchPrev(){

if(!busy){
	busy = true;
    var $active = $('#slideshow IMG.active');
	if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');



    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 200, function() {
            $active.removeClass('active last-active');
            busy = false;
        });
    updateCounter('-');    
    }
}

function updateCounter(s){

	if(s == '+'){
		if(currentImg < numberImg){
		currentImg++;
		}
		else{
		currentImg = 1;
		}
	}
	else if(s== '-'){
		if(currentImg > 1){
		currentImg--;
		}
		else{
		currentImg = numberImg;
		}
	}
	document.getElementById('counter').innerHTML = currentImg + ' | ' + numberImg;
}













