	$(document).ready(function(){
		/* $('#banner_caption').css('opacity', 1);  */
		/* $('#banner_nav a').css('opacity', .50); */
	});
	
	var index = -1;
	var title = '';
	var subtitle = '';
	var action = '';
	var init = 0;

	function remove_caption(){
		// reset the active captions
			
			$('#active_caption').fadeOut(100, function(){

					if(init > 0){
						// $('#active_caption #ac_title').html('').removeClass('ac_title_' + (index + 1));
						$('#active_caption #ac_title').html('').removeClass();
					}else{
						init = init + 1;
					}
					$('#active_caption #ac_subtitle').html('').removeClass('ac_subtitle_' + (index + 1));
					$('#active_caption #ac_action').html('').removeClass('ac_action_' + (index + 1));
					$('#active_caption').css('display', 'block');
					
			});
	}
	
	// ---------------------------------------------------------
	// type-writer effect
	// 
	// 		typeText() function used from the following link and
	//			       customized for this project 
	//		http://www.hungry-media.com/code/jQuery/tickerType/
	// ---------------------------------------------------------
		var isInTag = false;
		var c = 0;
		var last_title_class = '';

		function typetext() {
			
			var thisChar = title.substr(c, 1);
			//if( thisChar == '<' ){ isInTag = true; }
			//if( thisChar == '>' ){ isInTag = false; }
			
			if(c == 0){
				$('#active_caption #ac_title').addClass('ac_title_' + (index + 1)).html(title.substr(0, c++));
			}else{
				$('#active_caption #ac_title').html(title.substr(0, c++));
			}

			if( c < title.length + 1 ){
				if( isInTag ){
					typetext();
				}else{
					setTimeout("typetext()", 10);
				}
			}else {
					c = 1;
					title = "";
					
					$('#active_caption #ac_subtitle').addClass('ac_subtitle_' + (index + 1))
													 .css({opacity: 0})
													 .css('margin-left','-50px')
													 .html(subtitle).animate({opacity:1, marginLeft: "0px"}, 300, function(){
																
																if(jQuery.browser.msie){
																	$(this).get(0).style.removeAttribute('filter');
																}
																
																$('#active_caption #ac_action').css({opacity: 0})
																							   .css('margin-left','-50px')
																							   .html(action).animate({opacity:1, marginLeft: "0px"}, 300, function(){
																										c = 0;
																										
																											if(jQuery.browser.msie){
                      																	$(this).get(0).style.removeAttribute('filter');
                      																}
																										
																										$('#banner').cycle('resume');	
																								});											  
														
													  });
				
			}//else...
		}//function...
	
	
	$('#nav_container #banner_nav a').click(function(){ 
				// remove_caption();
	});
	
	$(window).load(function(){
	
			$('#banner').cycle({
				fx: 		'fade',
				timeout:	7000,
				speed:		700,
				pager:  	'#banner_nav', 
				next:		'#next_banner',
				prev:		'#prev_banner', 
				before:		remove_caption, 
				after:		show_next_caption
			});

			function show_next_caption(curr, next, opts){
		
				$('#banner').cycle('pause');

				// $('#nav_container a').fadeTo('fast', .15).removeAttr('href');
				// $('#nav_container a').removeAttr('href');
				
				// Get the index of this new image
				index = opts.currSlide;
				
				// find the number of banners 
				var num_banners = $('#banner').children().size();
		
				// ------------------------------------------------------------
				// Capture the title, subtitle and action  for the next caption
				// ------------------------------------------------------------
					title = $('#banner_caption #caption_' + (index + 1) + ' .title').html();
					subtitle = $('#banner_caption #caption_' + (index + 1) + ' .subtitle').html();
					action = $('#banner_caption #caption_' + (index + 1) + ' .action').html();
				
				// ------------------------
				// Display the next caption
				// ------------------------
					typetext();
		
				// resume in type writer function call-back instead
				// $('#banner').cycle('resume');
			}

		});// window.load(...
