﻿//$(function() {
//    $('#nav-gallery a').each(function() {
//        $(this).click(function() {
//            $('#gallery-image').attr('src', $(this).attr('href'));
//            return false;
//        });
//    });
//});
$(document).ready(function() {

    var slideShow = new Array();
    
    $('.gallery li a').each(function() {
        slideShow.push($(this).attr('href'));
    });
    
    if ($('#content-wrapper').hasClass('layout-home') || $('#content-wrapper').hasClass('layout-section')) {
        fadeinSlideshow("#slideshow", slideShow);
    } else {
        list();
    }
});
    function list() {
        $('.gallery a').click(function() {
            $('.gallery a').removeClass("selected");
            $(this).addClass("selected");
            $('#gallery-image').attr('src', $(this).attr('href'));
            return false;
        });
    };

    function fadeinSlideshow(elem, imageList, slideDuration, fadeSpeed, current) {
        var listSize = imageList.length;
        if (!current || current >= listSize) current = 0;
        if (!slideDuration) slideDuration = 5000;
        if (!fadeSpeed) fadeSpeed = 500;
        $(elem + " img").attr("src", imageList[current]);
        if (current == (listSize - 1)) {
            $(elem).css("background", "transparent url(" + imageList[0] + ") no-repeat");
        } else {
            $(elem).css("background", "transparent url(" + imageList[current + 1] + ") no-repeat");
        }
        $(elem + " img").animate({ opacity: "1" }, slideDuration).animate({ opacity: "0.01" }, fadeSpeed, function() {
        $(this).css("opacity", "1");
        fadeinSlideshow(elem, imageList, slideDuration, fadeSpeed, current + 1) });
    } 



