﻿function image_next(){
	
	 	clearInterval(stop_interval);

        $("#image").stop();
		
		var $active = $('.gallery_images a.active');
	
		if ($active.length == 0) $active = $('.gallery_images a:last');
	
		var $next = $active.next().length ? $active.next()
			: $('.gallery_images a:first');
	
		$active.addClass('last-active');
	
		$next.addClass('active');
		$active.removeClass('active last-active');
		
		var image = $next.attr("rel");
		var title = $next.attr("title");
		$("#image").addClass('active').animate({ opacity: "0.0" }, 1000, function() {
			
			$("#image").html('<img src="' + image + '" />');
			$active.removeClass('active last-active');
		});
		$("#image").animate({ opacity: "1.0" }, 1000);    

        return false;
	
	}
	
function image_prev(){
	
	 	clearInterval(stop_interval);

        $("#image").stop();
		
		var $active = $('.gallery_images a.active');
	
		if ($active.length == 0) $active = $('.gallery_images a:first');
	
		var $next = $active.prev().length ? $active.prev()
			: $('.gallery_images a:last');
	
		$active.addClass('last-active');
	
		$next.addClass('active');
		$active.removeClass('active last-active');
		
		var image = $next.attr("rel");
		var title = $next.attr("title");
		$("#image").addClass('active').animate({ opacity: "0.0" }, 1000, function() {
			
			$("#image").html('<img src="' + image + '" />');
			$active.removeClass('active last-active');
		});
		$("#image").animate({ opacity: "1.0" }, 1000);    

        return false;
	
	}


function slideSwitch() {
    var $active = $('.gallery_images a.active');

    if ($active.length == 0) $active = $('.gallery_images a:last');

    var $next = $active.next().length ? $active.next()
        : $('.gallery_images a:first');

    $active.addClass('last-active');

    $next.addClass('active');
    $active.removeClass('active last-active');
    
    var image = $next.attr("rel");
    var title = $next.attr("title");
    $("#image").addClass('active').animate({ opacity: "0.0" }, 1000, function() {
        
        $("#image").html('<img src="' + image + '" />');
        $active.removeClass('active last-active');
    });
    $("#image").animate({ opacity: "1.0" }, 1000);    
    
}

$(function() {
    var $first = $('.gallery_images a:last');
    $first.addClass('active');
	slideSwitch();
    stop_interval = setInterval("slideSwitch()", 4000);
});
