/*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/

function slideSwitch() {
    var $active = $('#slideshowContainer img.active, #slideshowLabels ul li.active');

    if ( $active.length == 0 ) $active = $('#slideshowContainer img:last, #slideshowLabels ul li:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshowContainer img:first, #slideshowLabels ul li:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


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

    $next.css({opacity: 0.0})
    .addClass('active')
    .animate({opacity: 1.0}, 1000, function() {
        $active.removeClass('active last-active');
    });

	//update that shit
	$('#slideshowNum').html( $( $next[1] ).attr('title'));
}
function slideBack() {
    var $active = $('#slideshowContainer img.active, #slideshowLabels ul li.active');

    if ( $active.length == 0 ) $active = $('#slideshowContainer img:last, #slideshowLabels ul li:last');

    // use this to pull the images in the order they appear in the markup
    var $prev =  $active.prev().length ? $active.prev()
        : $('#slideshowContainer img:first, #slideshowLabels ul li:first');

    // uncomment the 3 lines below to pull the images in random order

    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


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

    $prev.css({opacity: 0.0})
    .addClass('active')
    .animate({opacity: 1.0}, 1000, function() {
        $active.removeClass('active last-active');
    });

/*	var slideNum = $('#slideshowLabels ul li.active').attr('title');*/
	//update that shit
	$('#slideshowNum').html( $( $prev[1] ).attr('title'));
}

function updateNumbs(nex) {
	/*	var slideNum = $('#slideshowLabels ul li.active').attr('title');*/
	$('#slideshowNum').html(function(){
		return parseInt($('#slideshowLabels ul li.active').attr('title'));
		/* if (parseInt($('#slideshowLabels ul li.active').attr('title')) < 1) {
			return parseInt($('#slideshowLabels ul li.active').attr('title'));
		} else {
			return parseInt($('#slideshowLabels ul li.active').attr('title')) + 1;
		}*/
	});
}

$(function() {
	var interval = setInterval( "slideSwitch()", 2500 );
	
	$('img#sliderRightBtn').click(function(){
		clearInterval( interval );
		slideSwitch();
	});
	
	$('img#sliderLeftBtn').click(function(){
		clearInterval( interval );
		slideBack();
	});
});

