$(function() {
	$("a.lightbox").lightBox({
		imageLoading: "/theme/grandform/img/lightbox-ico-loading.gif",
	    imageBtnClose: "/theme/grandform/img/lightbox-btn-close.gif", 
	    imageBtnPrev: "/theme/grandform/img/lightbox-btn-prev.gif",
	    imageBtnNext: "/theme/grandform/img/lightbox-btn-next.gif",
	    imageBlank: "/theme/grandform/img/lightbox-blank.gif"
	});
});

$(function () {
    setInterval(switchImage, 5000);

    $(".call-to-action").click(function () {
        $(".top-shadow").append("<div id='overlay'></div>");
        $("#overlay").css({ opacity: 0 }).animate({ opacity: 0.5 });

        $("#overlay").add("#action").click(function () {
            $("#overlay").fadeOut("slow", function () {
                $(this).remove();
            });
        });
    });

});

function switchImage() {
    var shown = $("img.shown");
    var next = shown.next("img");
    var element = null;
    if (next.length != 0) {
        element = next;
    } else {
        element = $("#gallery img").first();
    }
    element.addClass("shown").css({ opacity: 0 }).animate({ opacity: 1 }, 1200);
    shown.removeClass("shown");

 var shown = $("li.shown");
    var next = shown.next("li");
    var element = null;
    if (next.length != 0) {
        element = next;
    } else {
        element = $("#buttons li").first();
    }
    element.addClass("shown");
    shown.removeClass("shown");
}

/*var elements = 2;
var width = 960;
var final = elements * width;
var startposition = 0;

$(function () {
$("#gallery").click(function () {
if (startposition < (final - width) ) {
startposition = startposition + width;
$("#gallery img").animate({ "left": "-" + startposition });
} else {
$("#gallery img").animate({ "left": "+" + 0 });
startposition = 0;
}
});
});*/

$(function () {
$("#gallery #arrow-next").click(function () {
var shown = $("#gallery > .shown");
var next = shown.next("img");
if (next.length == 0) {
next = $("#gallery > img").first();
};
shown.removeClass("shown");
next.addClass("shown");
 });
 $("#gallery #arrow-prev").click(function () {
 var shown = $("#gallery > .shown");
var next = shown.prev("img");
if (next.length == 0) {
next = $("#gallery > img").last();
};
shown.removeClass("shown");
next.addClass("shown");
});
});
