$(document).ready(function(){

    var webelieve = {
        container: '#we-believe-wrapper',
        hiddenContainer: '#we-believe-hidden',
        duration: 9000,
        transitionTime: 750,
        resizeTime: 750,
        i: 1,
        totalBeliefs: 0,
        beliefs: $('.inactive-belief'),
        lockedHeight: '',
        currentBeliefHeight: '',
        showNextBelief: function() {
        
            clearTimeout();
        
            // get the next belief
            var belief = webelieve.beliefs[webelieve.i];
            
            if(!$.browser.msie) {
         
            var b = $(belief).clone().animate({opacity: 0.01},1,function(){
                           });
            
            
            // adjust the iterator
            if (webelieve.i == webelieve.totalBeliefs-1) {
                webelieve.i = 0;
            } else {
                webelieve.i++;
            }
            
            // hide the current belief and show the next belief
            $('.active-belief').animate({opacity: 0.01},webelieve.transitionTime,function(){
                $(this).remove();
                $(webelieve.container).html(b);
    
                // figure out the new height
                var pxheight = b.height();
                
                if(pxheight != webelieve.currentBeliefHeight  && webelieve.lockedHeight == false) {
                    $(webelieve.container).animate({height:pxheight},webelieve.resizeTime,'easeOutBack',function(){
                        b.addClass('active-belief').removeClass('inactive.belief').animate({opacity: 1},webelieve.transitionTime,function(){
                        $(this).css('filter','none');
                        });
                    });
                } else {
                    b.animate({opacity: 1},webelieve.transitionTime,function(){
                       b.addClass('active-belief').removeClass('inactive.belief');
                       $(this).css('filter','none');
                    })
                }
            });
            
            } else {
                var b = $(belief).clone();
                $(webelieve.container).html(b); 
                // adjust the iterator
            if (webelieve.i == webelieve.totalBeliefs-1) {
                webelieve.i = 0;
            } else {
                webelieve.i++;
            }

            
            }
            setTimeout(webelieve.showNextBelief,webelieve.duration);
                  
        },
        init: function(lockedheight) {
          // do we want to lock the height
          webelieve.lockedHeight = lockedheight;
           
          // lock in the height as necessary
          
              if(lockedheight==false && !$.browser.msie) {
                var pxheight = $('.active-belief').height();
                $(webelieve.container).height(pxheight);
              } else if(!$.browser.msie) {
                $(webelieve.container).height(lockedheight);
              }
            
          // we want to check to see if user is using IE
          // If Yes, set a quick transition time.
          if (navigator.appName == 'Microsoft Internet Explorer') {
            webelieve.transitionTime = 15;
          }
         
          // first see how many beliefs we have…
          webelieve.totalBeliefs = webelieve.beliefs.length;      
          
         setTimeout(webelieve.showNextBelief,webelieve.duration);
        } // end init
    };
    
    webelieve.init(false);


});
