/***************************  
   Author: Luis Tello
   version: 2.0
   copyright 2011
****************************/

var rotatingCallout = {
    setRCTimeout:null,
    position:null,
    finalPosition:null,
    number:null,
    stHandle:null,
    nextCallout:null,
    ONE:null,
    pauseCallout:null,
    
    construct: function(){
        var that = this;
        this.pauseCallout = false;
        this.setRCTimeout = 10;
        this.position = 1;
        this.number = 1;
        this.finalPosition = 4;
        this.ONE = 1;
        this.setBtnListener();
        this.setPosition(this.position);
        if(!this.getPauseCallout()){
            this.stHandle = setTimeout(function(){that.cueNextSlide();},this.setRCTimeout*1000);
        }    
    },
    setPosition: function(value){
        this.position = value;
    },
    getPosition: function(){
        return this.position;
    },
    setPauseCallout: function(value){
        this.pauseCallout = value;
    },
    getPauseCallout: function(){
        return this.pauseCallout;
    },
    cueNextSlide: function(){
        var that = this;
        //advance image and btn
        if($("#callout"+this.number).hasClass("active")){
            $("#callout"+this.number).removeClass("active");
            $("#callout"+this.number).addClass("nonactive");
            $("#rc_btn"+this.number).attr('src','images/rc_btn'+this.getPosition()+'_nonactive.gif');       
            if(this.position == this.finalPosition){               
                this.number = this.ONE;
                this.nextCallout = this.ONE;
                $("#callout"+this.nextCallout).removeClass("nonactive");
                $("#callout"+this.nextCallout).addClass("active");
                $("#rc_btn"+this.nextCallout).attr('src','images/rc_btn_active.gif');
            }
            else{
                this.nextCallout = this.position+1;
                $("#callout"+this.nextCallout).removeClass("nonactive");
                $("#callout"+this.nextCallout).addClass("active");
                $("#rc_btn"+this.nextCallout).attr('src','images/rc_btn_active.gif');
            }
        }
        if(this.position == this.finalPosition){
            this.position = this.ONE;
        }
        else{
            this.position++;
            this.number++;
        }
        if(!this.getPauseCallout()){
            this.stHandle = setTimeout(function(){that.cueNextSlide();},this.setRCTimeout*1000);
        }
    },
    btnClick: function(value){
        if(this.getPauseCallout() == false){
            //turn off
            $("#callout"+this.number).removeClass("active");
            $("#callout"+this.number).addClass("nonactive");
            $("#rc_btn"+this.number).attr('src','images/rc_btn'+this.getPosition()+'_nonactive.gif');
            //turn on
            $("#callout"+value).removeClass("nonactive");
            $("#callout"+value).addClass("active");
            $("#rc_btn"+value).attr('src','images/rc_btn_active.gif');
            this.setPosition(value);
            this.number = value;
            clearTimeout(this.stHandle);
        }
    },
    setBtnListener: function(){
        var that = this;
        $('#rc_btn1').click(function(){
            that.btnClick(1);
        });
        $('#rc_btn2').click(function(){
            that.btnClick(2);
        });
        $('#rc_btn3').click(function(){
            that.btnClick(3);
        });
        $('#rc_btn4').click(function(){
            that.btnClick(4);
        });
        $('#rc_nextBtn').hover(
            function(){
                $('#rc_nextBtn').attr('src','images/next_btn_hover.gif');
            },
            function(){
                $('#rc_nextBtn').attr('src','images/next_btn_nohover.gif');
            }
        );
        $('#rc_nextBtn').click(function(){
            if(that.getPosition() == that.finalPosition){
                that.btnClick(1);
            }
            else{
                that.btnClick(that.getPosition()+1);
            }
        });
    }
};





