$(document).ready(function(){
 	// declare interval var
 	var bb_interval;
 	// declare tagline elements
 	var tagline_container = $("#tagline-container");
	var tagline_header = $(".tagline-header");
	var tagline = $(".tagline");
	
	tagline_header.css('opacity', '0');
   	tagline.css('opacity', '0');
	tagline_header.css('visibility', 'visible');
	tagline.css('visibility', 'visible');
	// declare brandbox elements
 	var brandbox2 = $("#brandbox2");
 	var brandbox3 = $("#brandbox3");
 	var brandbox4 = $("#brandbox4");
 	var brandbox5 = $("#brandbox5");
 	
	// set initial opacity of brandboxes to 0 except for first
 	brandbox2.css('opacity', '0');
 	brandbox3.css('opacity', '0');
 	brandbox4.css('opacity', '0');
 	brandbox5.css('opacity', '0');
 	
 	//tagline_header.css('opacity', '0');
 	
 	// set interval times 
  	var speed = 2500;
  	var pause = 7000;
  	// start counter at 2 so we start fading into second brandbox
 	var counter = 2;
    
    /* brandbox rotator
     * iterate through brandbox elements prefixed with a number for easy use with
     * numeric counter. Transition to full opacity and fire callback function when each
     * animation is complete
    */
   			//tagline_header.html('True vision');
   			Cufon.set('fontFamily', 'GothamRounded');
   			Cufon.set('color', '#fff');
   			Cufon.set('separate', 'none');
			Cufon.replace('.tagline-header');
			tagline_header.animate({opacity: 1}, 3000);
   			tagline.animate({opacity: 1}, 3000);
   		
			
  	function rotateBrandbox() {
   		$("#brandbox"+counter).animate({
   			opacity: 1
   		}, speed, function() {
   			addText(counter);
   			counter++;	
   			if (counter > 5) {
   				brandbox2.css('opacity', '0');
 				brandbox3.css('opacity', '0');
 				brandbox4.css('opacity', '0');
 				brandbox5.css('opacity', '0');
   				counter = 1;
   			}
   		});
   		/* start fading tagline opacity to 0 while callback function transitions to full (1) */ 
   		
   		tagline_header.animate({opacity: 0}, 750);
   		tagline.animate({opacity: 0}, 750);   		  		
   	}
   	
   	function addText(num) {
   		if (num == 1) {
   			tagline_header.animate({ 
   				opacity: 1
   			}, 1000, function() {
   				tagline.animate({opacity: 1}, 1000);
   			});
   			
   		} else
   		if (num == 2) {
    		tagline_header.html('True innovation');
   			Cufon.set('fontFamily', 'GothamRounded');
   			Cufon.set('color', '#fff');
			Cufon.replace('.tagline-header');
			tagline.css('color', '#fff');
   			tagline.html('We develop solutions that lead the industry with cutting-edge technology.');
			
   			tagline_header.animate({ 
   				opacity: 1
   			}, 1000, function() {
   				tagline.animate({opacity: 1}, 1000);
   			});
   		} else
   		if (num == 3) {
   			//tagline_header_w2.css('display', 'inline');
   			tagline_header.html('True science');
   			Cufon.set('fontFamily', 'GothamRounded');
   			Cufon.set('color', '#ffffff');
			Cufon.replace('.tagline-header');
			tagline.css('color', '#ffffff');
   			tagline.html('Rooted in science, our products and services are both proven and reliable.');
   			
   			tagline_header.animate({ 
   				opacity: 1
   			}, 1000, function() {
   				tagline.animate({opacity: 1}, 1000);
   			});
   			
   		} else
   		if (num == 4) {
   			tagline_header.html('Truepower');
			tagline.css('color', '#005395');
   			tagline.html('Our unique ability to bring a client through the entire project lifecycle makes us more than a typical consultant - it makes us a partner in your success.');
   			Cufon.set('fontFamily', 'GothamRounded');
   			Cufon.set('color', '#005395');
			Cufon.set('fontSize', '36px');
   			Cufon.replace('.tagline-header');
   			tagline_header.animate({ 
   				opacity: 1
   			}, 1000, function() {
   				tagline.animate({opacity: 1}, 1000);
   			});
   			clearInterval(bb_interval);
   		}
   	}   	
   	bb_interval = setInterval(rotateBrandbox, pause);
});
