//-------------------------------------------------------------------
// START: CRITICAL IMPORTS/DEPENDENCIES
//-------------------------------------------------------------------
	// color plugin
	document.writeln('<script type="text/javascript" src="/global/js/jquery/color.js"></script>');

//-------------------------------------------------------------------
// START: NAV SETTINGS
//-------------------------------------------------------------------
		
	// menu delay
	var iMenuDelay = 250 // time for rollover - in milliseconds - before menu loads
	
	// cover settings
	var sCoverColor = "#ffffff";
	var iCoverOpacity = 0.9;
	var iCoverSpeedIn = 1000;
	var iCoverSpeedOt = 200;
	var iCoverZindex = 799;
	
//-------------------------------------------------------------------
// START: NAV VARIABLES
//-------------------------------------------------------------------
	var area;
	var setDelay = null;
	var bMenuActive = false
	var bMenuMoving = false;
	
	
//-------------------------------------------------------------------
// START: NAV FUNCTIONS
//-------------------------------------------------------------------

// JQUERY - START READY FUNCTIONS
$(document).ready(function(){

	//-------------------------------------------------------------------
	// JQUERY - Page Set Up
	if (!$.browser.opera && !($.browser.msie && $.browser.version<7.0) ) {
		fncMenuSetUp();
	
		//-------------------------------------------------------------------
		// JQUERY - "Menu Controls"
		
		// add more delay time to ie
		if ($.browser.msie) {
			iMenuDelay=iMenuDelay+100;
		}
		
		// mouse over
		$("#nav a").mouseover(function() {
			jQuery.fn.fncMenuControl(true)
		});
	
		// mouse outs
		$("#nav a").mouseout(function() {		
			jQuery.fn.fncMenuControl(false)
		});
		
		$("#spark_menu").mouseout(function(e) {
			if (e.toElement) { area = e.toElement; }
			if (e.relatedTarget) { area = e.relatedTarget; }
			if (e.srcElement) { source = e.srcElement;}
			if (e.target) { source = e.target;}
					
			if ($(source).parent().attr('class')=='menu' && $(area).parent().attr('class')!='menu'  && $(area).attr('class')!='expanded' && $(area).parent().attr('class')!='expanded' &&$(area).parent().attr('class')!='linkdicator' && $(area).attr('class')!='menu') {
				if (!$.browser.msie) {
					fncMenuClose();
					jQuery.fn.fncPulseSetTimer();
				} else	{
					if (e.pageX>$(source).width() || $(source).parent().attr('id')=='news') {
						fncMenuClose();
						jQuery.fn.fncPulseSetTimer();
					}
				}
			}
			
			if (!bMenuFallen) {
				//fncMenuCoverOff();
			}
		});
	}  // do not show or use the drop down menus on Opera or IE 6
	
	
	jQuery.fn.fncMenuControl = function(bOn,e) {		
		if(bOn) {					
			setDelay=setTimeout(jQuery.fn.fncMenuControl_MouseOver,iMenuDelay);
		} else {
			clearTimeout(setDelay);
			jQuery.fn.fncPulseSetTimer();
		};
	}; //fncMenuControl
	
	jQuery.fn.fncMenuControl_MouseOver = function() {
		if (document.getElementById('navoption9').style.top=='1px') {
			if (typeof cyclic != "undefined") {
				clearInterval(cyclic);
			}
			fncMenuOpen();
			
			jQuery.fn.fncPulseRemove();
			jQuery.fn.fncPulseClearTimer();
		}
	}; //fncMenuControl_MouseOver
	
	
	//-------------------------------------------------------------------
	// JQUERY - "Pulse Controls"
	
	// add the pulse
	jQuery.fn.fncPulsePlay = function() {
		// clear the timer
		jQuery.fn.fncPulseClearTimer();
		
		// clean up
		jQuery.fn.fncPulseRemove();
		
		// add the word, set default opacity
		$("#page_container").append('<div id="pulse" style="background:#eaeaea;color:'+iPulseStartColor+';left:'+iPulseStartPositionX+'px;top:'+iPulseStartPositionY+'px;">Spark</div>');
		$("#pulse").css({background:"none"});
				
		// now animate it into stop 1
		$("#pulse").animate({opacity:iPulseStop1Opacity,color:iPulseStop1Color,top:iPulseStop1PositionY+"px",left:iPulseStop1PositionX+"px"},iPulseStop1SpeedIn, iPulseStop1TypeIn, function() {
			
			// rest here
			$("#pulse").animate({opacity:iPulseStop1Opacity},iPulseStop1Rest, function() {
																					   
				// move to end
				$("#pulse").animate({opacity:iPulseEndOpacity,color:iPulseEndColor,top:iPulseEndPositionY+"px",left:iPulseEndPositionX+"px"},iPulseEndSpeedIn, iPulseEndTypeIn, function() {
					// remove the pulse
					jQuery.fn.fncPulseRemove();
					
					// set the timer
					jQuery.fn.fncPulseSetTimer();
				}); // end: move to end
			}); // end: stop 1 rest 
		}); // end: move into stop 1	
	}; //fncPulseAdd
	
	// remove the pulse
	jQuery.fn.fncPulseRemove = function() {		
		// if it exists, then remove it
		if ($("#pulse").length>0) {
			$("#pulse").remove();
		}
	}; //fncPulseRemove
	
	// set the pulse timer
	jQuery.fn.fncPulseSetTimer = function() {
		bPulseTimerIsSet=true;
		setPulseTimer=setTimeout(jQuery.fn.fncPulsePlay,iPulseDelay);
	}; //fncPulseRemove
	
	// clears the pulse timer
	jQuery.fn.fncPulseClearTimer = function() {
		//alert("now");
		if (bPulseTimerIsSet) {
			// clear timer			
			clearTimeout(setPulseTimer);
		}
		bPulseTimerIsSet=false;
	}; //fncPulseRemove
	
	// turn on the pulse timer when the page loads
	if (!$.browser.msie) {
		jQuery.fn.fncPulseSetTimer();
	}
	
}); // end jQuery load

//-------------------------------------------------------------------
// START: MENU FUNCTIONS
//-------------------------------------------------------------------

function fncMenuSetUp() {
	for(m=0;m<items.length;m++) {
		
		if ($.browser.msie) {
			iOpacityThis = 1;
		} else {
			iOpacityThis = 0.4;
		}
		
		var mitem=jQuery('<div><\/div>').addClass('menu').attr('id',item_id[m]).css({color: '#ffffff', position:'absolute', top: '1px',left:'15px',padding:'0',textTransform: 'uppercase', opacity: iOpacityThis,fontFamily: 'arial, sans', width:'auto', display: 'block'});
		
		// load all nav items into container
		mitem.appendTo('#spark_menu');
		
		// add words to each item
		$('#'+item_id[m]).html("<p>"+items[m]+"</p>");
		
		origWidth.push($('#'+item_id[m]).width());
				
		// ie specific updates
		if ($.browser.msie) {
			$("#"+item_id[m]).css({fontSize: '68px', paddingTop: '2px' });
		}
		
		$("#"+item_id[m]).css({letterSpacing: '-28px'});
		
		if (m>0) { // safari needs width to accordian words correctly
			$("#"+item_id[m]).css({width: '675px'});
		}
		
		if (m%2==1)	{
			$('#'+item_id[m]+' p').css({color: '#fe1818'});
		} else	{
			$('#'+item_id[m]+' p').css({color: '#171717'});
		}
	}
} // function fncMenuSetUp

function fncMenuOpen() {
	bMenuActive = true;
	
	if ($.browser.msie) {
		//
	} else {
		$('#spark_menu').animate({opacity:'1'},50);	
	}
	
	$('#spark_menu').css({display:'block'});
	
	$('#spark_menu').css({height:'700px'});
	
	$('#spark_menu div').each(function(i) {
		$("#"+item_id[i]).css({letterSpacing: '-5px'});		
	});
	
	
	fncMenuFall();
} // function fncMenuOpen

function fncMenuFall() {
	bMenuMoving = true
	
	$("#nav a").animate({opacity: '.03'},10 );
	
	$("#"+item_id[0]).remove();
		
	$('div').each(function(i) {
		if (i%2==1) {
			$('#'+item_id[i]).css({color: '#FD3130'});
		} else	{
			$('#'+item_id[i]).css({color: '#313130'});
		}
		
		$("#"+item_id[i]).css( { width: 'auto',cursor: 'pointer' });
		
		// make sure the first time is wider than the word "spark"
		if (i==1) {
			if ($("#"+item_id[i]+" p").width()<220) { 
				$("#"+item_id[i]+" p").css( {width: '220px'});
			}
		}
		
		// get current height/placement
		h=$("#"+item_id[i]).height()+2;
	
		if ($.browser.msie) {
			if ($.browser.version<7.0) { 
				h=50; 
			} else {
				h=56;	
			}
		}
		
		// do fall here
		if ($("#"+item_id[i]).css('letter-spacing')=='-5px' && $("#"+item_id[i]).css('color') != 'rgb(255, 255, 255)') {
			$("#"+item_id[i]).animate({opacity:'.99',top: 1+((h)*(i-1))+'px'},300, function() {  
				$("#"+item_id[i]).css({opacity:'.99'}); 
				if (i==items.length-1) {
					fncMenuEventAdd();
					bMenuFallen=true;
				}
			});
		} else	{
			return;
		}
	});	
	
	fncMenuCoverOn();
} // function fncMenuFall

function fncMenuClose() {
	$('div').each(function(i) {
		$("#"+item_id[i]).animate({opacity:'0.1',top: '1px'},300, function() {
			$("#"+item_id[i]).css({color:'#ffffff', filter:'alpha(opacity=5)'});
			if (i==items.length-1) {
				fncMenuRise();
				if ($.browser.msie) {
					$('#spark_menu').css({display:'none'});
				} else {				
					$('#spark_menu').animate({opacity:'0'},50, function() {
						$('#spark_menu').css({display:'none'});
						bMenuActive = false;
						bMenuMoving = false
						
					});
				}
			}
		});
	
		for(m=0;m<items.length;m++) {
			$("#"+item_id[m]).unbind('mouseover');
		}
	});
	
	$("#nav a").css({opacity:'.99'});
	
	$('#spark_menu').css({height:'80px'});
	
	bMenuFallen=false;
	fncMenuCoverOff();
} // function fncMenuClose

function fncMenuRise() {
	llen=false;
	bMenuMoving = true;
	
	$('#spark_menu div').each(function(i) {
		
		if (document.getElementById(item_id[i+1]+'_expanded')) {
			$('#'+item_id[i+1]+'_expanded').remove();
		}
		
		if (document.getElementById(item_id[i+1]+'_linkdicator')) {
			$('#'+item_id[i+1]+'_linkdicator').remove();
			
		}
		
	});
	
} // fncMenuRise


//-------------------------------------------------------------------
// START: BACKGROUND FADE FUNCTIONS
//-------------------------------------------------------------------

function fncMenuCoverOn() {
	
	var sDocHeight = $(document).height();
	
	// if it exists, skip creating
	if ( $("#cover_menu").length == 0 ) {
		// create it
			var sHTML = "<div id=\"cover_menu\" style=\"position:absolute;top:0px;left:0px;width:100%;height:"+sDocHeight+"px;z-index:"+iCoverZindex+";background:"+sCoverColor+";opacity:0;\"></div>";
			
			// apprend it
			$("#page_container").append(sHTML);
	}
	
	$('#cover_menu').animate({opacity:iCoverOpacity}, iCoverSpeedIn);
} // fncMenuCoverOn

function fncMenuCoverOff() {
	
	$('#cover_menu').animate({opacity:0}, iCoverSpeedOt, function() {
		$('#cover_menu').remove();
	});
	
} // fncMenuCoverOff


