﻿

/********************************************************
 NOTE : THIS REQUIRES IMAGE-PRELOADER TO BE LOADED FIRST
********************************************************/
var battle_intro_rotator = 
{
    //properties
    images : [
                "../common/img/battle/popups/intro_001.jpg"
               ,"../common/img/battle/popups/intro_002.jpg"
               ,"../common/img/battle/popups/intro_003.jpg"
             ],
    current_image : 0,
    wait_time : 6,
    timer : 0,
    image_id : "intro_image",
    interval_id : "",
    
    
    //METHODS
    Start_Timer: function()
    {
        if(this.interval_id=="")
        {
            this.timer = this.wait_time;
            this.interval_id = window.setInterval("battle_intro_rotator.Timer_Interval();", 1000);
        }
    },
    
    Stop_Timer: function()
    {
        window.clearInterval(this.interval_id);
        this.interval_id="";
    },
    
    Timer_Interval: function()
    {       
        if(this.timer>0)
            this.timer--;
        else
            this.Show_Next_Image();
    },
    
    
    //methods
    Show_Next_Image : function()
    {
        this.Stop_Timer();
        
        if(this.current_image == this.images.length-1)
            this.current_image = 0;
        else
            this.current_image++;

        //slide image down
        var id = this.image_id;
        var newimage = this.images[this.current_image];
        $("#"+this.image_id).animate({
            opacity: 0
            ,top: 400
            }
            ,600
            ,function() 
            {
                // Animation complete.
                $("#"+id).attr("src", newimage);
            }
        );
        
        //slide image up
        $("#"+this.image_id).animate({
            opacity: 1
            ,top: '0'
            }
            ,600
            ,function() 
            {
                // Animation complete.
            }
        );
        
        //restart timer
        this.Start_Timer();
    },
    
    Preload : function()
    {
        //preload images
        var loader = new image_preloader();
        loader.Init
        (
            function()
            {
                //run after each image loads
            },
            function()
            {
                //run when done loading all images
                battle_intro_rotator.Start_Timer();
            } 
        );
        
        loader.Preload_Images(this.images);
    }
}

