$(document).ready(function() {

function open(elem) {
	elem.removeClass('subClosed').addClass('subOpen');
	elem.siblings().slideDown();
}

function close(elem) {
	elem.removeClass('subOpen').addClass('subClosed');
	elem.siblings().slideUp();
}

/* init sidebar menu */
$('.sidebarNav li:has(ul)').each(function(i) {

	$(this).children().filter('a:first').addClass('subClosed').toggle		(
      function () {
        open($(this));
      },
      function () {
        close($(this));
      });


	if (i===navOpen || navOpen===true) {
			$(this).children().filter('a:first').trigger('click')// add trigger
	} else {
			$(this).children('ul').hide(); // hide child ul
	}

});

// top menu animations
$('#mainNav a:not(.highlight)').hover(
	function() {
  $(this).animate({ 
        top: "0px"
      }, 250 );
  },
	function() {
		$(this).animate({ 
        top: "8px"
      }, 100 );
	});

// scrolling stuff

var elements = ['box1','box2','box3','box4','box5'];
for (i=0; i<elements.length;i++) {
	var id=elements[i]; // name of id in HTML
	var $id=$("#" + id); // jquery object
  if ($id.length > 0) { // check to see exists

	if ($id.find('li').size() > 1 ) { //make sure more than one list item
		$id.addClass('scroller');

		//build nav controls
		var navhtml = '<span class="' + id + 'prev"><img src="images/arrowPrev.gif" width="6" height="16" alt="Previous" /></span>&nbsp;&nbsp;<span class="' + id + 'next">Next&nbsp;&nbsp;<img src="images/arrowNext.gif" width="6" height="16" alt="Next" /></span>&nbsp;&nbsp;&nbsp;&nbsp;';
		var header=$id.prev();
		var span=header.find(".elementNav");
		if (span.length>0) {
	 		span.prepend(navhtml);
		} else {
			navhtml = '<span class="elementNav">' +navhtml + '</span>';
			header.append(navhtml);
		}
		$('#' + id).serialScroll({
			items: 'li',
			prev: '.' + id + 'prev',
			next: '.' + id + 'next',
			duration: 500,
			cycle:true,
			force: true,
			interval: 10000
		});
  }
}
}

//For Print Button
function poptest() {
 var popu = window.open('','','width=1,height=1,left=0,top=0,scrollbars=no');
 if (!popu) { alert('Please turn off your popup blocker'); }
 popu.close()
}


//overlay (WTF we still need this?
$("a[rel^='prettyPhoto']").prettyPhoto();

//Welcome box links in new window
$('.boxNote a[href^=http://]').attr('target','_blank');
});


