// JavaScript Document
//Jump Menu Function For Testimonials
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//Pop Up Window
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//Load Images and Swap Images
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
  }

function randomMainImage() {
				var mainImageArray = new Array();
				mainImageArray[0] = "mainImage.jpg";
				mainImageArray[1] = "mainImage_2.jpg";
				mainImageArray[2] = "mainImage_3.jpg";
					$("div#mainImage img#main").attr("src", "/images/"+mainImageArray[randomNum]);
				clearInterval(clearTime);
				randomNum++;
				if(randomNum == 3) {
					randomNum = 0;
				}
		}
		var clearTime;
		var randomNum = 0;
//jQuery
  $(document).ready(function() {

  	//Change Navigation to DIN BLACK//
  	Cufon.replace("#navigation ul li a");
  	//Sub Navigation New Menu //
  	$(".subNav").hide();
  	$("#navigation ul li").hover(function(e) {
  		if ($(this).children().is("#navigation ul.subNav")) {
  			$(this).children("#navigation ul.subNav").slideDown(0);

  		}
  	}, function() {
  		//currentSubNav.;
  		if ($(this).children().is("#navigation ul.subNav:visible")) {
  			$("#navigation ul.subNav:visible").slideUp(0);
  			
  		}
  	});	
  	$("#navigation ul.subNav").mouseleave(function(e) {
  		e.preventDefault();
  		var hideSub = setTimeout(function() {
  			$("#navigation ul.subNav").slideUp(0);
  		}, 800);
  		$("#navigation ul.subNav").mouseenter(function() {
  			clearTimeout(hideSub);
  		});
  	});
	
	/* Main Image Rotation */
		//Images Array
		var clearTime = setInterval("randomMainImage()", 8000);


  	//Alternate BG Colors Testimonials 
  	$("#testimonialsBox .testimonialList ul li:odd").css('background-color', '#3b3b3b');
  	//Drop Down menus
  	var subOpen = 0;
  	//Buttons Active Stage Variables
  	//Editorial Button
  	$('.editorialBtn').hover(function() {
  		$('.subEd').slideDown(400);
  	}, function() {
  		$('.subEd').mouseenter(function() {
  			subOpen = 1;
  		});
  		setTimeout(function() {
  			if (subOpen == 1) {
  				$('.subEd').mouseleave(function() {
  					$('.subEd').slideUp(400);
  					subOpen = 0;
  				});
  			} else {
  				$('.subEd').slideUp(400);
  			}
  		}, 500);
  	});
  	//Features Button
  	$('.featuresBtn').hover(function() {
  		$('.subFea').slideDown(400);
  	}, function() {
  		$('.subFea').mouseenter(function() {
  			subOpen = 1;
  		});
  		setTimeout(function() {
  			if (subOpen == 1) {
  				$('.subFea').mouseleave(function() {
  					$('.subFea').slideUp(400);
  					subOpen = 0;
  				});
  			} else {
  				$('.subFea').slideUp(400);
  			}
  		}, 100);
  	});
  	//Features > Looking Forward
  	$('.lfOpen').hover(function() {
  		$('.subLF').slideDown(400);
  	}, function() {
  		$('.subLF').mouseenter(function() {
  			subOpen2 = 1;
  		});
  		setTimeout(function() {
  			if (subOpen2 == 1) {
  				$('.subLF').mouseleave(function() {
  					$('.subLF').slideUp(400);
  					subOpen2 = 0;
  				});
  			} else {
  				$('.subLF').slideUp(400);
  			}
  		}, 100);
  	});
  	//Interviews Button
  	$('.interviewsBtn').hover(function() {
  		$('.subInt').slideDown(400);
  	}, function() {
  		$('.subInt').mouseenter(function() {
  			subOpen = 1;
  		});
  		setTimeout(function() {
  			if (subOpen == 1) {
  				$('.subInt').mouseleave(function() {
  					$('.subInt').slideUp(400);
  					subOpen = 0;
  				});
  			} else {
  				$('.subInt').slideUp(400);
  			}
  		}, 100);
  	});
  	//History Button
  	$('.historyBtn').hover(function() {
  		$('.subHis').slideDown(400);
  	}, function() {
  		$('.subHis').mouseenter(function() {
  			subOpen = 1;
  		});
  		setTimeout(function() {
  			if (subOpen == 1) {
  				$('.subHis').mouseleave(function() {
  					$('.subHis').slideUp(400);
  					subOpen = 0;
  				});
  			} else {
  				$('.subHis').slideUp(400);
  			}
  		}, 100);
  	});
  	//Mission Button
  	$('.missionBtn').hover(function() {
  		$('.subMis').slideDown(400);
  	}, function() {
  		$('.subMis').mouseenter(function() {
  			subOpen = 1;
  		});
  		setTimeout(function() {
  			if (subOpen == 1) {
  				$('.subMis').mouseleave(function() {
  					$('.subMis').slideUp(400);
  					subOpen = 0;
  				});
  			} else {
  				$('.subMis').slideUp(400);
  			}
  		}, 100);
  	});
  	//Accordion for the Look and Feel page
  	$(".accordionContent").hide();
  	$(".accordionLink").click(function() {
  		$(this).next().slideToggle("slow");
  	});
  	//Scroller Links to open Areas of the Looking Forward Section
  	var scientific = "sr";
  	var youth = "yp";
  	var information = "is";
  	var smart = "st";
  	var social = "ss";
  	var monitoring = "madp";
  	var resources = "re";
  	var hash = window.location.hash.substr(1);
  	//Begin If Statements
  	if (hash == scientific) { $("#sr").next().show(); }
  	if (hash == youth) { $("#yp").next().show(); }
  	if (hash == information) { $("#is").next().show(); }
  	if (hash == smart) { $("#st").next().show(); }
  	if (hash == social) { $("#ss").next().show(); }
  	if (hash == monitoring) { $("#madp").next().show(); }
  	if (hash == resources) { $("#re").next().show(); }

  	//Scroller Function
  	$(".leftArrow").hide();
  	$(".leftArrow").click(function() {
  		$(".itemsContainer:visible").fadeOut(500, function() {
  			$(this).prev().fadeIn(500);
  		});
  		$(".rightArrow").fadeIn(300);
  		$(".leftArrow").fadeOut(300);
  	});
  	$(".rightArrow").click(function() {
  		$(".itemsContainer:visible").fadeOut(500, function() {
  			$(this).next().fadeIn(500);
  		});
  		$(".leftArrow").fadeIn(300);
  		$(".rightArrow").fadeOut(300);
  	});
  	//var currentItems = 1;
  	/*$(".leftArrow").click(function() {
  	if(currentItems == 1) {
  	$(".itemsContainer:visible").fadeOut("slow", function() { 
  	$("div.itemsContainer:hidden").fadeIn("slow");
  	currentItems = 2;
  	console.log(currentItems);
  	});	
  	} 
  	if(currentitems == 2) {
  	$(".itemsContainer 2").fadeOut("slow", function() {
  	$(".itemsContainer 1").fadeIn("slow");
  	currentItems = 1;
  	});
  	}
  	});*/
  	/*$(".rightArrow").click(function() {
  	if(currentItems == 1) {
  	$("div.itemsContainer 1").fadeOut("slow", function() { 
  	$("div.itemsContainer 2").fadeIn("slow");
  	currentItems = 2;
  	});	
  	} else {
  	$("div.itemsContainer 2").fadeOut("slow", function() {
  	$("div.itemsContainer 1").fadeIn("slow");
  	currentItems = 1;
  	});
  	}
  	});*/
  });