// ================================
//    Hero swf
// ================================
function hero() {
	 	var flashvars = {
			media: "/_media/flv/eclipse_home.flv",
			aspectratio: "16:9",
			autoplay: "1",
			fullscreenpage: "true",
			fsreturnpage: "true"
		};
		var params = {
			allowfullscreen: "true",
			bgcolor: "#000000",
			quality: "best"
		};
		var attributes = {};
   		 swfobject.embedSWF("/_ui/skin/swf/eclipse_video_player.swf", "hero-flash", "617", "347", "9.0.124.0","/_ui/skin/swf/expressInstall.swf", flashvars, params, attributes);
 
}

// ================================
//    Hero Text
// ================================

function rotateHeadlines() {
		 
	//add a class of headline to all the containers and hide them
	$('#headline-container div').addClass('headline').hide();
			
	//Get the first headline and set to visible
	$('#headline-container div#headline_0').addClass('current').show();
	
	//Call the rotator function to run the slideshow, 10000 = change to next image after 10 seconds
	setInterval(function () {
	  rotate();
	}, 7000);	
}

function rotate(current) {	
	
	//Get the first headline and set to visible
	var length = ( $('#headline-container div.headline').length - 1 ),
		 
		 current = $("#headline-container div").index( $('div.current'));
		 
	if (current < length) {
		 next = current + 1;
	}
	//if at the end, reset to first headline
	else if ( current == length) {
		next = 0;
	}
	
	//Hide the current headline
	$('#headline-container div#headline_' + current).removeClass('current').fadeOut(800)
	
	//Wait for fadeOut to end, then fadeIn next headline
	setTimeout(function() {
    	$('#headline-container div#headline_' + next).addClass('current').fadeIn(800)
    }, 1000);	
	
};



function heroText() {
	 $.ajax({
		 //find the headlines xml doc
		 type: "GET",
		 url: "/_ui/skin/xml/heroText.xml",
		 dataType: "xml",
		 success: function(xml) {
			
			//clear hard-coded headline
			$('#headline-container h1, #headline-container h2').remove();
			
			var i = 0;
			
			//cycle through xml, find and populate headlines			
			$(xml).find('benefit').each(function(){
				
				var headline_text = $(this).find('headline').text();
				
				var subhead_text = $(this).find('subhead').text();
				
				//add each headline and subhead to a container div
				$('#headline-container').append('<div id="headline_' + i + '"><h1>' + headline_text + '</h1></div>');
				$('#headline-container div#headline_' + i + '  h1').after('<h2>' + subhead_text + '</h2>');
				
				i++;
				
			});
			
			//rotate the headlines
			rotateHeadlines();
			
		 }		 
	 });  
} 



// ================================
//    Start it up
// ================================
  
$(document).ready(function() {
		
	//load hero swf
	hero();
	
	//load hero text rotation
	heroText();
	
	
});