//onload
$(function(){
    VM.init();
});

var VM = {
    imgloop: 0,
    zindex: 1,

    /**
    * init
    **/
    init: function() {
        //add event handler
        VM.animate();
        //var lang = (navigator.language? navigator.language : navigator.userLanguage).substring(0, 2).toUpperCase();
        //VM.select(lang);
    },
    
    /**
    * animate
    **/
    animate: function() {        
        VM.zindex++;
        //reset bottom imgs
        $("#animation .abottom").each(function() {
            $(this).css("right", "-549px");
        });
        
        //switch classnames
        $("#animation img").each(function() {
            if ($(this).attr("class") == "atop") {
                $(this).removeClass("atop").addClass("abottom");
            } else {
                $(this).removeClass("abottom").addClass("atop");  
            }
        });

        //change image, increase z-index, animate
        $("#animation .atop").each(function() {
            $(this).attr("src", $(this).attr("src").replace(/\d/g, VM.imgloop));
            $(this).css("z-index", VM.zindex);
            if (this.offsetWidth > 300) {
                $(this).animate({"right": -12}, 1500);
            } else {
                $(this).animate({"right": -12}, 2200);
            }
        });
        (VM.imgloop == 9) ? (VM.imgloop = 0) : VM.imgloop++;

        setTimeout("VM.animate()", 5000);
        return;
    },

    error: function(e) {
        log(e);
        log("ERROR:");
    }

}