function slideSwitch(){
    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}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

function slideSwitchBack(){
    var $active = $('#slideshow img.active');

    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}, 1000, function() {
            $active.removeClass('active last-active');
        });
}


$(document).ready(function(){

	$("#hp_play").hide();
	var intervalId = setInterval( "slideSwitch()", 6000);
	$("#hp_pause").click(function(){
		clearInterval(intervalId);
		$("#hp_pause").hide();
		$("#hp_play").show();
	});
	$("#hp_play").click(function(){
		var intervalId = setInterval( "slideSwitch()", 6000);
		$("#hp_pause").show();
		$("#hp_play").hide();
		$("#hp_pause").removeAttr("onclick");
		$("#hp_pause").click(function(){
			clearInterval(intervalId);
			$("#hp_pause").hide();
			$("#hp_play").show();
		});
	});
	
	$("#hp_next").click(function(){
		slideSwitch();
	});
	
	$("#hp_prev").click(function(){
		slideSwitchBack();
	});
});

