var imageIx = 0;
function switchImage(ix) {
    var current = imageIx;
    imageIx = imageIx + ix;
    if(ix == 1) {
        if(imageIx >= images.length) {
            imageIx = 0;
        }
        var next = images[imageIx];
        if($("#img_" + imageIx).length == 0) {
            var img = new Image();
            img.onload = function() {
                $("#images").animate({height:images[imageIx].height + "px"});
                $("#img_" + current).animate({left:"-" + images[current].width + "px"});
                $("#img_" + imageIx).animate({left:"0px"});
            };
            img.id = "img_" + imageIx;
            img.alt = next.alt;
            img.title = next.alt;
            img.style.left = next.width + "px";
            img.src = next.src;
            $("#images").append(img);
        }
        else {
            $("#images").animate({height:images[imageIx].height + "px"});
            $("#img_" + current).animate({left:"-" + images[current].width + "px"});
            $("#img_" + imageIx).css("left", images[imageIx].width + "px");
            $("#img_" + imageIx).animate({left:"0px"});
        }
    }
    else if(ix == -1) {
        if(imageIx < 0) {
            imageIx = images.length - 1;
        }
        var next = images[imageIx];
        if($("#img_" + imageIx).length == 0) {
            $("#loading").fadeIn();
            var img = new Image();
            img.onload = function() {
                $("#loading").fadeOut();
                $("#img_" + current).animate({left:images[current].width + "px"});
                $("#img_" + imageIx).animate({left:"0px"});
            };
            img.id = "img_" + imageIx;
            img.alt = next.alt;
            img.title = next.alt;
            img.style.left = "-" + next.width + "px";
            img.src = next.src;
            $("#images").append(img);
        }
        else {
            $("#img_" + current).animate({left:images[current].width + "px"});
            $("#img_" + imageIx).css("left", "-" + images[imageIx].width + "px");
            $("#img_" + imageIx).animate({left:"0px"});
        }
    }
    return false;
}
$(document).ready(function(){
    $("#previous").click(function(){
        return switchImage(-1);

    });
    $("#next").click(function(){
        return switchImage(1);
    });
    $("#links > ul > li > a").hover(function(){
            $(this).css("text-decoration", "underline");
        },
        function(){
            $(this).css("text-decoration", "none");
    });
    $("#booking-form").submit(function(){
        $("#id_lkjhgf").val("fghjkl");
    });
});

