function display (category) {
	var whichcategory = document.getElementById(category);
	if (whichcategory.className=="show") {
		whichcategory.className="hide";
	} else {
		whichcategory.className="show";
	}
}

function checkrequired(which) {
	var pass=true;
	if (document.images) {
		for (i=0;i<which.length;i++) {
			var tempobj=which.elements[i];
			if (tempobj.name.substring(0,8)=="required") {
				if (((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value=='')||
				(tempobj.type.toString().charAt(0)=="s"&&
				tempobj.selectedIndex==0)) {
					pass=false;
					break;
         		}
      		}
   		}
	}
	if (!pass) {
		shortFieldName=tempobj.name.substring(8,30).toUpperCase();
		alert("Please make sure you've indicated "+shortFieldName+".");
		return false;
	}
	else
	return true;
}


// right sub nav function - collapsed

/*
function initMenu() {
  $('#menu ul').hide();
  $('#menu li a').click(
    function() {
        $(this).next().slideToggle('normal');	
      }
    );
  }
*/

// right sub nav funtion - open

function initMenu() {
	$('#menu ul').hide();	// change back to hide() after debug
	if ($('#menu ul').is('.active')) {   
		$('#menu ul.active').show();
	}
	if ($('#menu ul li').is('.active')) { //#elm has the class} else { //#elm doesn't have the class}  
		$('li.active').parent().addClass("active");	  
		$('#menu ul.active').show();
	}
	$('#menu a').mouseenter(function() {
		
		var checkElement = $(this).next();
		
		if((checkElement.is('ul')) && (checkElement.is(':visible'))) { 
			return false;
		}
		
		if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
			$('#menu ul:visible').slideUp('normal');
			checkElement.slideDown('normal');
			return false;
		}
	});
}


function slide(item) {
	//if active is not set, default to 1
	if( !item ) {
		item = 1;
	}
	//Set position for slider
	var top = ((item * 32) - 24) + "px";
	//Animated hiding of sub-nav if open

	$('#popNav-hider').stop().animate({width:'142px'}, 200, function() {
		//Animate slider to position
		
		$('#slider').stop().animate(
			{ top: top },
			{
			duration: '200',
			easing: 'easeOutCubic',
			complete: function() {
				if( subBool ) {
					$('.popNav').hide();
					$('#popNav-hider').height($('#slideNav').height());
					openSub(item,top);
				}
			}
		});
	});
}


function openSub(item,top) {
	//Set position for sub-nav
	var popH = $('#popNav' + item).height();
	var slideH = $('#slideNav').height();
	var topPos = $('#slider').css('top').split('p')[0];
	$('#popNav-hider').height(parseInt(topPos) + parseInt($('#popNav'+item).height()) + 'px');
	//Offsets position of sub-nav if positioned too far down or is very long
	if(popH > (slideH - topPos) && popH < slideH) {
		var offset = (popH - (slideH - topPos));
		var offPos = (topPos - offset) + "px";
		$('#popNav' + item).css({"top" : offPos});
	} else if (popH > slideH) {
		$('#popNav' + item).css({"top" : top});
	} else {
		$('#popNav' + item).css({"top" : top});
	}
	//Animated showing of sub-nav
	$('#popNav'+item).show();
	// fix nav modules width issue in IE 6
	if ($('html').hasClass('ie6')) {
		$('#popNav-hider').stop().animate({width:'10px'},200);
	} else {
		//alert('hit');
		$('#popNav-hider').animate({width:'0px'},200);
	}
	open = item;
}


// These two functions run after Flash intro complete
function showNav() {
	$('#flash-content').attr('wmode','transparent').css({'height':'530px'});
	if ($('html').hasClass('ie8') || $('html').hasClass('ie7')) {
		$('#left').fadeIn(750);
	} else {
		$('#left').css('visibility', 'visible').animate({opacity:1},750);
	}
	$('#left').fadeIn(750); 			//.animate({opacity:1},750);
	$('#footer').children().fadeIn(750,function() {
		});
		
	showLogo();
	// if ie 6 the turn off flash !!!! hacky
}
function showLogo() {
	$("#logo").css('visibility','visible').animate({opacity:1},750);
}

//Set global variables
var open;
var subBool=false;

$(document).ready(function() {
	
	$('#sitemap a.folder').click(function() {
		var obj = $(this);
		var closed = obj.hasClass('closed');
		
		if (closed) {
			obj.nextAll('div.indent:first').slideDown('fast').end().removeClass('closed').prev('div.bullet').addClass('open');
		} else {
			obj.addClass('closed').prev('div.bullet').removeClass('open');
			obj.nextAll('div.indent:first').add(obj.nextAll('div.indent:first').children('div.indent:visible')).slideUp('fast');
			obj.nextAll('div.indent:first').children('div.bullet.open').removeClass('open').next('a.folder').addClass('closed');
		}
		return false;
	});
//
// If Flash variables are set
	if (typeof attributes != 'undefined') {
		
		// If Flash is installed
		if (swfobject.hasFlashPlayerVersion(fv) && (!$('html').hasClass('ie6') && !$('html').hasClass('android'))) {
			// Hide HTML Elements
			$('#logo,#center,#right')
				.css({'opacity':0,'visibility':'hidden'});
			$('#left').hide();
			$('#footer').children().hide();
			// Run Flash
			swfobject.embedSWF("/swf/final_demo_r10.swf", "flash-content", "1000", "450", fv, "", flashvars, params, attributes);
		
		// If Flash is not installed
		} else {
			// Remove Flash container
			$('#flash-content').remove();
		}
	
	// If Flash variables are not set
	} else {
		// Remove Flash container
		$('#flash-content').remove();
	}

	initMenu(); // initiate right subnav
	
	if ($('html').hasClass('mobile')) { 
		subBool=true; 
	} else {
		//Move slider and open sub-nav on hover
		$('#slideNav>li').mouseenter(function() {
			subBool = false;
			//$(this).animate({ paddingRight: '10px' }, 400);
			$('#slider').stop()
			var item = $(this).attr('item');
			if($('#popNav' + item).html()) {
				subBool = true;
			}
			slide(item);
		});
		//Close sub-nav and reset slider on leave
		$('#slider-container').mouseleave(function() {
			var active = $('#slideNav li.active').attr('item');
			subBool = false;
			slide(active);
		});
	}
	
	//Get item number of active selection and set its default position
	var active = $('#slideNav li.active').attr('item');
	slide(active);
	
	//Set height of sub-nav hider
	$('#popNav-hider').height($('#slideNav').height());
	
	//DD_roundies.addRule('#profile_card', '8px');
	
	
	// disable scrollpanes for mobile browsers
	if ($('html').hasClass('mobile')) {
		$('#blockholder').jScrollPane({showArrows:false,  scrollbarWidth:0}).parent().css('height', $('#blockholder').height());
		$('.video-scroller').removeClass('video-scroller');
		$('#detailholder').jScrollPane({showArrows:false, scrollbarWidth:0}).parent().css('height', $('#detailholder').height());
		$('#blocknav').jScrollPane({showArrows:false,	  scrollbarWidth:0}).parent().css('height', $('#blocknav').height());
		$('#print_email_icons1').hide();
	} else {
		// initialize scrollpanes for desktop browsers
		$('#blockholder').jScrollPane({showArrows:true});
		$('#detailholder').jScrollPane({showArrows:true});
		$('.video-scroller').jScrollPane({showArrows:true});
		$('#blocknav').jScrollPane({showArrows:true});
	}
	
	
	//
	// Featured Articles handler, mousing over changes the caption and "Read More >>" link href
	$('.article-image').mouseenter(function() {
		// fade out orange border for inactive images
		$('.active').stop().animate({"backgroundColor" : "#FFFFFF"}, 400).removeClass('active');
		// fade in orange border for the image hovered over
		$(this).stop().animate({"backgroundColor" : "#E88A1C"}, 400).addClass('active');
		// get caption & truncate if it's too long for #top-stories
		var caption = $(this).attr('alt');
		if (caption.length > 70) {
			$('#article').html(caption.substr(0,70)+'...');
		} else if (caption.length > 0) {
			$('#article').html(caption);
		} else {
			$('#article').html('<b>Error:</b> Article caption not found.');
		}
		// load url into "Read More >>" <a> tag
		$('#expand > a').attr('href', $(this).parent().attr('href'));
	});
	$('.article-image:first').stop().animate({"backgroundColor" : "#E88A1C"}, 400).addClass('active');
		
	
	//
	// Featured Practice handler, an orange overlay detailing the name of the featured practice
	// Featured Practice handler, an orange overlay detailing the name of the featured practice
	$('#featured-practice').hover(function() {
		$('#text').fadeIn(800);
	}, function() {
		$('#text').fadeOut(800);
	});
	//
	// Lighter Side handler, instead of redirecting to a page this calls slideDown() on the element containing all lighter side data
	if ($('#blockholder').length > 0) {
		var blocks=$('#blockholder').parent();
		blocks.css('display', 'none');
		blocks.slideDown(3000);
		$('#lighter_header_img').fadeIn(1500);
		$('#email_iconBtn1').fadeOut(1500);
	}
	
	// Setup lighter side direct links within page
	$('.light').attr('href', SERVER_HOST + '/Lighter_Side/');
	
	
	//
	// Back To Top handler, generates a "Back to Top" link on the bottom of pages which stretch beyond the window.
	//						only called when there are no other .blueLink <h5>s on the page
	var exemptIDs=[1,9,5,10,11,73,74];
	
	if ($(document).height() > $(window).height()) {
		var showTopLink=true;
		for (c in exemptIDs) {
			if (exemptIDs[c] == PAGE_ID) {
				showTopLink=false;
			}
		}
		if (showTopLink) {
			$('#top-link').show();
		}
	}
	
	//
	// vLoad handler, make all .video_icons load HTML5 video or the SSP player.swf object
	$('.video_link, .video').vLoad();
	

});
