// JavaScript Document
 
	$(document).ready(function(){
		$(".seeAllMedia").click(function() {
			$(this).prev("div").toggleClass("active");
			return false;
		});
		
		// this adds the css to ALL "not" first ".category" items
		$(".genContent").each(function() {
			$(this).children("a.category").not("a.category:first").css("margin-left", "2px");
		});
		/*
		$(".genPortlet .programs").each(function() {
			$(this).children(".portletTitle").not(".portletTitle:first").addClass("portletTitleExtra");
		});
		*/
		$("#micro_landing .row:first").addClass("firstRow");
		$("#micro_landing .row .portletTitle:first").addClass("firstTitle");
		
		
		//this sets the video tab feature
		$('#featuredvid > ul').tabs();
		
		//drop down nav - for dept sites
		/* compliance update
		$("ul.nav li").hover(function(){
			$(this).addClass("active");
			$(this).children("a").addClass("active");
			$(this).children("ul").css("display", "block");
			$(this).children("div").css("display", "block");
			},function(){
				$(this).removeClass("active");
				$(this).children("a").removeClass("active");
				$(this).children("ul").css("display", "none");	
				$(this).children("div").css("display", "none");
		});
		*/
		
		$("ul.nav li").hover(function(){
			$(this).addClass("active");
			$(this).children("a").addClass("active");
			$(this).children("ul").addClass("active");
			$(this).children("div").addClass("active");
			},function(){
				$(this).removeClass("active");
				$(this).children("a").removeClass("active");
				$(this).children("ul").removeClass("active");
				$(this).children("div").removeClass("active");
		});
		
		// this adds the class of "last" to any genPortlet in a row
		$(".row .genPortlet:last-child").addClass("last");
	  
	  //portlet Height
	  /*currently the following isn't working - it's supposed to read off the size of the portlets and resize them*/
	  /*
	  $(window).load(function(){
		  
		 $('.row').each(function(){
			var $this = $(this);
			
			var maximum = Math.max($this.children().eq(0).height(),$this.children().eq(1).height(),$this.children().eq(2).height(), $this.children().eq(3).height(), 404);
			$this.children().each(function(){
				var $this = $(this);
				$this.height(maximum);
				if($this.children().length == 1 && $this.children().hasClass('genPortlet') == true){
					$this.children().height(maximum);
				}
			});
		 });
	  });
	  
	  */
	  
//new tabs - this is for the News, Events and social media
	var $wrapper = $('div.wrapper');
	if($wrapper.length){
			$('ul.tabWrapper li.tab a').click(function() {
				var $this = $(this);
				var whichTab = $this.parent().prevAll('li.tab').length;
				$this.closest('div.wrapper').children('div').eq(whichTab).addClass('active').siblings().removeClass('active');
				$this.parent().addClass('active').siblings().removeClass('active');
				
				/* NEW for equal heights */
				/* also not working for now. Leave out.
				var $row = $this.closest('div.row');
				$row.children().css('height','auto');
				var maximum = Math.max($row.children().eq(0).height(),$row.children().eq(1).height(),$row.children().eq(2).height(), $row.children().eq(3).height(), 404);
				$row.children().each(function(){
					var $this = $(this);
					$this.height(maximum);
					if($this.children().length == 1 && $this.children().hasClass('genPortlet') == true){
						$this.children().height(maximum);
					}
				});
				*/
				return false;
			});

	}

//new pager
	var $pagerWrapper = $('div.portletPagerWrapper');
	if($pagerWrapper.length){
			
			$pagerWrapper.each(function(){
				$this = $(this);
				var $tabWrapper = $this.children('ul.tabWrapper').children('li.next');
				var totalDivs = $this.children('div').length;
				
				for(i=0; i<totalDivs; i++){
					if(i==0){
						$('<li class="tab active"><a href="#">' + (i+1) + '</a></li>').insertBefore($tabWrapper);
					}else{
						$('<li class="tab"><a href="#">' + (i+1) + '</a></li>').insertBefore($tabWrapper);
					}
				}
			});
			
			//var tabLength = $pagerWrapper.children('div').length;
			$('ul.tabWrapper li.tab a').click(function() {
				var $this = $(this);
				var whichTab = $this.parent().prevAll('li.tab').length;
				$this.closest('div.portletPagerWrapper').children('div').eq(whichTab).addClass('active').siblings().removeClass('active');
				$this.parent().addClass('active').siblings().removeClass('active');
				return false;
			});
			
			$('ul.tabWrapper li.prev a').click(function() {
				var $this = $(this);
				var $closestPPW = $this.closest('div.portletPagerWrapper');
				var whichTab = $closestPPW.children('div.active').prevAll().length - 1;
				$closestPPW.children('div').removeClass('active');
				
				if(whichTab == -1){
					$closestPPW.children('div:last').addClass('active');
					$this.parent().siblings().removeClass('active').parent().children('li.tab:last').addClass('active');
				}else{
					$closestPPW.children('div').eq(whichTab).addClass('active');	
					$this.parent().siblings().removeClass('active').parent().children('li.tab').eq(whichTab).addClass('active');
				}
				return false;
			});
			
			$('ul.tabWrapper li.next a').click(function() {
				var $this = $(this);
				var $closestPPW = $this.closest('div.portletPagerWrapper');
				var totalDivs = $closestPPW.children('div').length;
				var whichTab = $closestPPW.children('div.active').prevAll().length + 1;
				$closestPPW.children('div').removeClass('active');
				
				if(whichTab == totalDivs){
					$closestPPW.children('div:first').addClass('active');
					$this.parent().siblings().removeClass('active').parent().children('li.tab:first').addClass('active');
				}else{
					$closestPPW.children('div').eq(whichTab).addClass('active');	
					$this.parent().siblings().removeClass('active').parent().children('li.tab').eq(whichTab).addClass('active');
				}
				return false;
			});
	}
	

	  /*to make the following 508 compliant I took off the slideToggle and replaced with a CSS state and and opacity animator*/
	  //$("#quickLinksWrapper").opacity();
	  //doesn't work in ie6 
	  $("#quickLinksWrapper").css({ opacity: 0.5 }); //added to lower opacity in the beginning
	  //once clicked the following takes place
	  $(".quickLinksBtn").click(function(){
		//$(this).next("div").slideToggle("slow");
		//$(this).next("div").toggleClass("active").animate({"height": "430px"},"slow");
		// doesn't work in ie6 
		$(this).next("div").toggleClass("active").animate({"opacity": "1.0"},"slow"); //this animates in but not out so next time you click on button it
		//$(this).next("div").toggleClass("active");
		//$(this).next("div").toggleClass("active").fadeIn(5000);
		$(this).toggleClass("active"); 
		return false;
	  });
	  
});

(function($){$.browserTest=function(a,z){var u='unknown',x='X',m=function(r,h){for(var i=0;i<h.length;i=i+1){r=r.replace(h[i][0],h[i][1]);}return r;},c=function(i,a,b,c){var r={name:m((a.exec(i)||[u,u])[1],b)};r[r.name]=true;r.version=(c.exec(i)||[x,x,x,x])[3];if(r.name.match(/safari/)&&r.version>400){r.version='2.0';}if(r.name==='presto'){r.version=($.browser.version>9.27)?'futhark':'linear_b';}r.versionNumber=parseFloat(r.version,10)||0;r.versionX=(r.version!==x)?(r.version+'').substr(0,1):x;r.className=r.name+r.versionX;return r;};a=(a.match(/Opera|Navigator|Minefield|KHTML|Chrome/)?m(a,[[/(Firefox|MSIE|KHTML,\slike\sGecko|Konqueror)/,''],['Chrome Safari','Chrome'],['KHTML','Konqueror'],['Minefield','Firefox'],['Navigator','Netscape']]):a).toLowerCase();$.browser=$.extend((!z)?$.browser:{},c(a,/(camino|chrome|firefox|netscape|konqueror|lynx|msie|opera|safari)/,[],/(camino|chrome|firefox|netscape|netscape6|opera|version|konqueror|lynx|msie|safari)(\/|\s)([a-z0-9\.\+]*?)(\;|dev|rel|\s|$)/));$.layout=c(a,/(gecko|konqueror|msie|opera|webkit)/,[['konqueror','khtml'],['msie','trident'],['opera','presto']],/(applewebkit|rv|konqueror|msie)(\:|\/|\s)([a-z0-9\.]*?)(\;|\)|\s)/);$.os={name:(/(win|mac|linux|sunos|solaris|iphone)/.exec(navigator.platform.toLowerCase())||[u])[0].replace('sunos','solaris')};if(!z){$('html').addClass([$.os.name,$.browser.name,$.browser.className,$.layout.name,$.layout.className].join(' '));}};$.browserTest(navigator.userAgent);})(jQuery);
browser = function(){

            var OSName="Unknown OS";
            var browser = "";
            if (navigator.appVersion.indexOf("Mac")!=-1) OSName="Mac";
            if (navigator.appVersion.indexOf("Win")!=-1) OSName="PC";
            bodyClass = $.browser.className+OSName
            $("body").addClass(bodyClass);
//
}


