﻿function BigSlides() { }
BigSlides.Imgs = "#big-images";
BigSlides.Index = -1;
BigSlides.Timer = null;
BigSlides.Init = function () {
    if ($("li", BigSlides.Imgs).size()) {
        BigSlides.Switch();
    }
}
BigSlides.Switch = function () {

    if (BigSlides.Index >= ($("li", BigSlides.Imgs).size() - 1))
        BigSlides.Index = 0;
    else
        BigSlides.Index++;

    //Set image
    var nextSlide = $("li:eq(" + BigSlides.Index + ")", BigSlides.Imgs);
    var fadeSpeed = 1000;
    var imgUrl = $(nextSlide).attr("title");
    // Fade text only when text is different
    var fadeText = ($("#big-image-info").text() != $(nextSlide).text());

    var image = new Image();
    image.onload = function () {

        $("#big-image-container").attr("style", "background-image:url('" + imgUrl + "');");

        if (fadeText) {
            $("#big-image-info *").delay(250).fadeOut(1000);
            fadeSpeed = 2000;
        }
        else
            fadeSpeed = 8000;

        $("#big-image-container-2").fadeOut(fadeSpeed, function () {
            $("#big-image-container-2").attr("style", "background-image:url('" + imgUrl + "');").show();

            if (fadeText) {
                $("#big-image-info").html($(nextSlide).html());
                $("#big-image-info > *, #big-image-info > * > *").fadeIn(500);
				}

            $("#debug xmp").html(imgUrl);
            BigSlides.Timer = setTimeout("BigSlides.Switch()", "8000");
        });
    };
    image.src = imgUrl;
}

// BigGallery User Control
$("#big-gallery-images a").live('click', function () {
    // set url in big image
    $("#big-gallery-image-link").attr('href', $(this).attr("rel"));

    // set url in magnifier
    $("a[name=magnifier]").attr('href', $(this).attr("rel"));
    // re-init the shadowbox
    Shadowbox.setup();
});
