﻿$(function() {
    var image = $('.image:first').attr("rel");
    $("#image").html('<img src="' + image + '" />');

    $(".image").mouseover(function() {

        clearInterval(stop_interval);

        $("#image").stop();
        var image = $(this).attr("rel");
        var title = $(this).attr("title");
        $("#image").animate({ opacity: "0.0" }, 300, function() {
            $("#image").html('<img src="' + image + '" />');
        });
        $("#image").animate({ opacity: "1.0" }, 300);
        

        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:first');
    $first.addClass('active');
    stop_interval = setInterval("slideSwitch()", 4000);
});