$(document).ready(function(){

$('#container').append('<div class="push"></div>');
$("table.college").each(function(index) {
	$(this).find("tr:first td").each(function(index) {
		  var thisTD = this;
		  var thisTDcontents = $(this).html();
		  var newElement = $("<th>" + thisTDcontents + "</th>");
		  $.each(this.attributes, function(index) {
				$(newElement).attr(thisTD.attributes[index].name, thisTD.attributes[index].value);
		  });
		  $(this).after(newElement).remove();
	});
	$(this).find("tr:first").wrap("<thead></thead>");
	$(this).find("thead").each(function () {
		$(this).prependTo($(this).parent().parent());
	});
});
$("table.college").tablesorter(); 
	$(".college th.header").hover(function() {
					$(this).css("color","#dba72e"); 
				}, function() {
					$(this).css("color","#E7DDD3"); 
				});
				

$(".tab-row ul li:last").addClass("last-child");
$("blockquote p").append('<img src="/images/common/bq_right.gif" />');
$("blockquote p br").remove();

			$('#nav-main ul ul')
				.each(function () {
					$(this)
						.find('li')
						.wrapAll('<span class="link-group"></span>');
					$(this)
						.find(('.spotlight'))
						.wrapAll('<span class="spotlight-group"></span>');
			});
			$('.spotlight-group')
				.each(function () {
					$(this).prependTo($(this).parent().parent());
			});

			$('.link-group')
				.each(function () {
					$(this).find('li:even')
						.each(function () {
							$(this)
								.add($(this).next())
								.wrapAll('<span></span>');
						});	
				});	

$(".inquire a").html('<img src="/images/nav/consta.png" alt="" class="a" /><img src="/images/nav/constb.png" alt="" class="b" />');
$(".inquire .a").hover(
	function() {
	$(this).stop().animate({"opacity": "0"}, 200);
},
	function() {
	$(this).stop().animate({"opacity": "1"}, 200);
});

$('#header .search .input').focus(function() {
         $(this).animate({width: 120}, 'slow');
});

$('#header .search .input').blur(function() {
          $(this).animate({width: 53}, 'slow');
 });
$('#header .searchli').insertBefore("#nav-const2 ul li#nav-li-offices__resources").wrap('<li></li>');


$('#nav-main ul li ul').append('<div class="clear"></div>');
$("table.styled tr:nth-child(odd)").addClass("alt");  // Add alt class to alternating rows on styled tables
$(".table-container td a").parent().addClass("event"); // Add event class to month view 
$(".table-container td h4").parent().parent().parent().addClass("event"); // Add event class to month view
if($("#gallery-form #select-gallery").children().length <= 2) { $(".gallery-teaser form").addClass("none"); $(".gallery select").addClass("none"); }
if($(".gallery-attachment dl.image-list dt").length > 1){$(".gallery-attachment .gallery-directional").removeClass("none");}

$(".gallery-attachment dl.image-list dt:first").addClass("active");
$(".gallery-attachment dl.image-list dd:first").addClass("active");
$(".gallery-attachment dl.image-list dt:not(.active)").addClass("none");
$(".gallery-attachment dl.image-list dd:not(.active)").addClass("none");
	
	var changeButtons = function(){
		// Change display state of buttons
		// If not first child or last child: display next and prev
		if( !$(".gallery-attachment dl.image-list dt:first").hasClass("active") && !$(".gallery-attachment dl.image-list dt:last").hasClass("active") ){
			$(".gallery-previous a").removeClass("disabled");
			$(".gallery-next a").removeClass("disabled");
		} 
		// If first child: display next, disable prev
		if( $(".gallery-attachment dl.image-list dt:first").is(".active") ){
			$(".gallery-next a").removeClass("disabled");
			$(".gallery-previous a").addClass("disabled");
		} 
		// If last child: display prev, disable next
		if( $(".gallery-attachment dl.image-list dt:last").is(".active") ){
			$(".gallery-previous a").removeClass("disabled");
			$(".gallery-next a").addClass("disabled");
		}
		
		SI_clearFooter();
	}
	
	var updateImages = function(){
		$(".gallery-attachment dl.image-list dt.active").addClass("none");
		$(".gallery-attachment dl.image-list dd.active").addClass("none");
		$(".gallery-attachment dl.image-list dt.active").removeClass("active");
		$(".gallery-attachment dl.image-list dd.active").removeClass("active");
	}
	
	$(".gallery-next a").click(function(){	
		if(!$(this).hasClass("disabled")){
			var nextImg = $(".gallery-attachment dl.image-list dd.active");
			updateImages();
			nextImg.next().removeClass("none");
			nextImg.next().next().removeClass("none");
			nextImg.next().addClass("active");
			nextImg.next().next().addClass("active");
			changeButtons();
		}
	});
	$(".gallery-previous a").click(function(){		
		if(!$(this).hasClass("disabled")){
			var prevImg = $(".gallery-attachment dl dt.active");
			updateImages();
			prevImg.prev().addClass("active");
			prevImg.prev().prev().addClass("active");
			prevImg.prev().removeClass("none");
			prevImg.prev().prev().removeClass("none");
			changeButtons();
		}
	});
	
	/* Add alt class to gallery thumbnails - Not being used yet */
	$(".gallery-thumbnails ul li:odd").addClass("alt");
	
	if ((typeof Sys !== "undefined") && (typeof Sys.Application !== "undefined")) {
	  Sys.Application.notifyScriptLoaded();
	  if (Sys.WebForms){
	   Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(showhide);
	  }
	 } 
	else {
	  showhide(); 
	 }
	
	function showhide () {
		$("dl.bio > dt").wrapInner('<a href="#" class="button" />');
		$("dl.bio").show();
		$("dl.bio > dd").hide();
			 
		$('dl.bio > dt a').click(function(){
			$("dl.bio > dd").slideToggle();
			return false;
		});
	}
	/*
//Request Information Toggles
$("#container").prepend('<div id="requestinfo"><div class="inner"><p class="lead-in">Message here</p><div class="columns"><form action="#" method="post" name="contactForm" id="contactForm" class="form validate"><div class="col1"><input type="text" name="name" id="name" value="Parent Name" title="Parent Name" class="required" tabindex="1" /><input type="text" name="studentname" id="studentname" value="Student Name" title="Student Name" class="required" tabindex="2" /><input type="text" name="email" id="email" value="Email Address" title="Email Address" class="required email" tabindex="3" /></div><div class="col2"><input type="text" name="schoolorg" id="schoolorg" value="School/Organization" title="School/Organization" class="required" tabindex="2" /><input type="text" name="phone" id="phone" value="Phone Number" title="Phone Number" class="phone" tabindex="4" /><input type="text" name="address" id="address" value="Address" title="Address" class="address" tabindex="4" /></div><div class="col3"><input type="hidden" name="interest" value="Online Inquiry" /><textarea id="comments" name="comments" title="Comments" cols="40" rows="5" tabindex="5">Question/Comments</textarea></div><div class="col4"><input type="hidden" name="from" value="requestinfo" /><input type="hidden" name="FormNameKey" value="Contact Us" /><input type="hidden" name="pageaction" value="DB" /><input type="hidden" name="ModuleID" value="140" /><input type="reset" name="reset" id="reset" value="Cancel" /><input type="submit" name="submit" id="submit" value="Send" /></div></form></div></div></div>');
$('#nav-link-inquire').click(function() {
	$('#requestinfo').slideToggle(400);
	$('#nav-link-inquire').parent().toggleClass("active");
	$("#requestinfo").toggleClass("active");
	return false;
});
$('#requestinfo input#reset').click(function() {
	$('#requestinfo').slideToggle(400);
	$('#nav-link-inquire').parent().removeClass("active");
	$("#requestinfo").toggleClass("active");
	$('#contactForm span.error').addClass("none");
	$('#contactForm').reset();
	return false;
});

//Request Information Watermark
$("#requestinfo form input#name").Watermark("Your Name","#999999");
$("#requestinfo form input#email").Watermark("Email Address","#999999");
$("#requestinfo form input#phone").Watermark("Phone Number","#999999");
$("#requestinfo form input#schoolorg").Watermark("School/Organization","#999999");
$("#requestinfo form textarea#comments").Watermark("Comments","#999999");
	$('#requestinfo form').submit(function () {
		$.Watermark.HideAll();
		if($(this).is(':valid')) {
			return true;
		} else {
			$.Watermark.ShowAll();
			return false;
		}
	});
	$('#requestinfo form').submit(function() {
		if(!$(this).valid()) {
			$.Watermark.ShowAll();
		}
	});
	$(':submit').click(function() {
		$.Watermark.HideAll();
	});
	*/
});

