// JavaScript Document

$(document).ready(function() {
	// Initial Vars
	var currentMask;
	var menuHeight;
	var menuSpeed = 300;
	var mediaPage = 0;
	var mediaTotal = 3;
	
	// Set iframe Menu Heights
	/*
	$("#menu1 .menu .menuWrapper").height(134);
	$("#menu2 .menu iframe").height(164);
	$("#menu3 .menu iframe").height(186);
	$("#menu4 .menu iframe").height(90);
	$("#menu5 .menu iframe").height(68);
	*/
	
	
	if(iPadVersion==true){
		currentMask==null;
		var targetMask;
		
		$(".menuTitleBlue, .menuTitleGreen").click(function() {
			targetMask = $(this).parent().parent().parent();
			//no menu is open
			if(currentMask==null){
				//open menu
				currentMask = targetMask;
				menuHeight = $(this).parent().parent().height();
				$(currentMask).stop().animate({top:511 - (menuHeight- 24), height:menuHeight}, menuSpeed);
			
			//same menu is already open...not currently working
			}else if(currentMask == targetMask){
				//close menu
				alert("same menu");
				$(currentMask).stop().animate({top:511, height:24}, 100);
				currentMask = null;
			
			//a different menu is open
			}else{
				//close open menu and open new menu
				$(currentMask).stop().animate({top:511, height:24}, 100);
				currentMask = targetMask;
				menuHeight = $(this).parent().parent().height();
				$(currentMask).stop().animate({top:511 - (menuHeight- 24), height:menuHeight}, menuSpeed);
			}
			
		});
		
		//old toggle version
		/*
		$('.menuTitleBlue, .menuTitleGreen').toggle(function() {
		  	currentMask = $(event.currentTarget).parent().parent().parent();
			menuHeight = $(this).parent().parent().height();
			$(currentMask).stop().animate({top:511 - (menuHeight- 24), height:menuHeight}, menuSpeed);
		}, function() {
		  	$(currentMask).stop().animate({top:511, height:24}, menuSpeed);
		});
		*/
		
	}else{
		
		
		// Menu Hover
		$(".menu").hover(function(event) {
			currentMask = $(event.currentTarget).parent();
			menuHeight = $(this).height();
			$(currentMask).stop().animate({top:511 - (menuHeight- 24), height:menuHeight}, menuSpeed);
		},
		
		// Hover Out
		function() {
			$(currentMask).stop().animate({top:511, height:24}, menuSpeed);
		});
		
		// Reset Menus on Sub Nav Click
		
		$(".menu").click(function() {
			$(currentMask).stop().animate({top:511, height:24}, 100);
		});
		
	}
	
	
	
	
	// Media Slide
	$(".mediaButton").click(function() {
		if(mediaPage < mediaTotal-1) {
			mediaPage++;		 
		} else {
			mediaPage = 0;
		}
		$("#media").stop().animate({left:mediaPage *(-932)}, menuSpeed);
	});
	
	// Home page video link
	/*
	$(".homeVidLink").click(function() {
		$("#VidWrapper").show();
	});
	*/
	
	//Features section News Ticker
	var currHeadline = 4;
	var newHeadline = 0;
	var pause = 5000;
	var headlineArray = new Array(".rssHeadline0",".rssHeadline1",".rssHeadline2",".rssHeadline3",".rssHeadline4");
	
	function rotateNews(){
		$(headlineArray[newHeadline]).fadeIn();
		$(headlineArray[currHeadline]).fadeOut();
		currHeadline = newHeadline;
		if(newHeadline==4){
			newHeadline=0;
		}else{
			newHeadline ++;
		}
		
	}
	//display first headline
	rotateNews();
	interval = setInterval(rotateNews, pause);
	
	
	
});


	
