<!--/*||||		Agency: Digitas	Chicago												||||*/-->
<!--/*||||		Developer: Ryan Ore													||||*/-->
<!--/*||||		Date: Dec 2011							||||*/-->
/* 
Description
Modified from Jared Wheeler's version on Emerson.com/neverbeendonebefore for the emerson.com home  
*	Removed a lot of stuff not being used. (navigation between sliedes primarily.)
*		-If we wanted it back, see jared's version on   
*	Added a slidup menu for external navigation.
*/




/*			Variables			*/
			
var curHeroNum;
var heroArray;
var intervalID;
var timerActive = true;
var defaultDuration;
var currentDuration = defaultDuration = 4;
var $menu = {};


/*			Init Functions			*/

function initHeroComponent(_defaultHeroNum, _heroArray){
	curHeroNum = _defaultHeroNum;
	heroArray = _heroArray;
	for(var i = 0; i < heroArray.length; i++){
		jQuery(heroArray[i]).stop(true, true).hide();
	}
	jQuery("#hero-container").css("visibility", "visible");
	changeHero(_defaultHeroNum);
	resetTimer();
	initSlidingMenu();
}

/*		View Functions		*/
		
		
function changeHero(_newHeroNum){
	for(var i = 0; i < heroArray.length; i++){
		if(i != _newHeroNum){
			jQuery(heroArray[i]).fadeOut(1000, function(){});
		} else {
			currentDuration =  jQuery(heroArray[i]).attr('duration')  ||  defaultDuration;
			jQuery(heroArray[i]).fadeIn(1000, function(){
				var _top  = $(this).attr('top')+'px';
				if ( ! $.browser.msie ) { 
								$('.hero-content').css('opacity','0');
								$(this).find('.hero-content')
									.animate({'top': _top} ,{queue:false, duration:1000, easing: 'swing'})
									.animate({'opacity':'1'} ,{	queue:false, duration:2000, easing: 'swing'});
						}
						else{
							$(this).find('.hero-content').animate({'top': _top} ,{queue:false, duration:1000, easing: 'swing'});
						}
			});
			
		}
	}
}


function nextHero()
{
	if(curHeroNum < heroArray.length-1){
		curHeroNum++;
		changeHero(curHeroNum);
	} else {
		stopTimer();
	}
}


/* 		Timer Functions		*/

function resetTimer(){
	timerActive = true;
	window.clearInterval(intervalID);
	if(timerActive == true){
		intervalID = setInterval(function() { nextHero(); }, currentDuration * 1000 );
	}
}
		
		
function stopTimer(){
	timerActive = false;
	window.clearInterval(intervalID);
}



/*		Menu Functions 	*/

function initSlidingMenu(){
	$menu = $('div#slideup-menu');
	menuPos = -$menu.height() + 30 + 'px';
	$menu.css({'opacity':'1', 'bottom':menuPos});
	$('#menu-button').css({'opacity':'1'});
	// $('a#menu-button.no-js').css('display','none');
	closeMenu();
	
	$('#menu-button').click( function(){
		openMenu();
		$menu.addClass('opened');
		$(this).fadeOut();
	})
	$('#menu-close-button').click( function(){
		closeMenu();
		$(this).fadeOut('slow');
		$menu.removeClass('opened');
	})
}

function closeMenu(){
	$menu.removeClass('opened').stop().animate( {'bottom': menuPos} ,{queue:false, duration:600, easing: 'swing'});
}

function openMenu(){
	$menu.addClass('opened').stop().animate( {'bottom':0+'px'} ,{queue:false, duration:400, easing: 'swing'});
}






