var timeout = 8000;
var animtime = 500;

$(window).load(function() {
    $("#serviceinner").css("top", "-120px");
    $(".servicescroll:last").insertBefore($(".servicescroll:first"));
    var $service = $(".servicescroll:eq(3)");
    $service
        .removeClass("servicescroll")
        .addClass("servicescrollDark");
    var $txtcont = $("#gallerytext");
    $txtcont.children("h2").html($service.children("h2").html());
    $txtcont.children("div").html($service.children(".galtext").html());
    $(".servicescrollDark a.img")
        .clone()
        .prependTo($("#galleryimages"))
        .fadeIn(animtime, function() {
            $txtcont.animate({ left: "0px" }, animtime, function() {
                setTimeout(slide, timeout);
            });
        });
    $.getJSON("http://twitter.com/statuses/user_timeline/bizitsupport.json?count=7&callback=?", twitterCallback2);
});

function slide() {
    $("#gallerytext").animate({ left: "632px" }, animtime, function() {
        $(this).css("display", "none");
        $("#serviceinner").animate({ top: "0px" }, animtime, function() {
            $(".servicescroll:last").insertBefore($(".servicescroll:first"));
            $(".servicescrollDark")
                .removeClass("servicescrollDark")
                .addClass("servicescroll");
            $(".servicescroll:eq(3)")
                .removeClass("servicescroll")
                .addClass("servicescrollDark");

            var $txtcont = $("#gallerytext");
            $txtcont.children("h2").html($(".servicescrollDark h2").html());
            $txtcont.children("div").html($(".servicescrollDark .galtext").html());

            $(".servicescrollDark a.img")
                .clone()
                .prependTo($("#galleryimages"))
                .css("display", "block");

            //fade out and remove the last image
            $("#galleryimages a.img:last img").fadeOut(animtime, function() {
                $(this).parent().remove();
            });
            
            //after animation reset
            $(this).css({ top: "-120px" });
            $("#gallerytext").css("display", "block").animate({ left: "0px" }, animtime, function() {
                setTimeout(slide, timeout);
            });
        });
    });
}

