var ISPLS = ISPLS || {};


ISPLS.calendar = function(e) {
  e.preventDefault();
  var $this = $(this),
      action = $this.parent().attr('class'),
      $wrapper = $this.closest('.scroller-wrapper'),
      $cal = $this.closest('.cal-content');
      $link = $this.attr('href');
  
  $.get($link, function(data) {
    var $d = $(data),
        delta = (action === 'prev') ? '-100' : '100';
    
    $d.css({
      'left' : delta + '%',
      'position' : 'absolute'
    }).appendTo($wrapper);
    
    var newHeight = $d.height();
    
    $cal.add($d).animate({
      'left' : '-='+delta+'%'
    }, 250, function() {
      $cal.fadeOut(250).remove();
    });
    
    $wrapper.animate({
      'height' : newHeight
    }, 350);
  });
};

//main nav hover on a
$(".main_nav li ul").hover(
  function () {
  	$(this).prev('a').addClass("hover");
  },
  function () {
    $(this).prev('a').removeClass("hover");
  }
);


//main nav hover menus - ie fix
ISPLS.sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		};
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		};
	}
};
if (window.attachEvent) window.attachEvent("onload", ISPLS.sfHover);


// news archive
$('.js .archive_wrap').hide();
$(".archive_link").click( function(e) {
	e.preventDefault();
	var $tgt = $(e.target),
		$archive = $('.archive_wrap'),
		$this = $(this);
	if ($tgt.is('.archive_link .show')) {
		$archive.slideDown('normal');
		$this.find('span').addClass('close').removeClass('show');
	 } else if ($tgt.is('.archive_link .close')) {
		$archive.slideUp('normal');
		$(this).find('span').addClass('show').removeClass('close');
	} 
});


// icons for resources section
$('.solid_text a').filter(function() {
	return this.hostname && this.hostname !== location.hostname;
}).addClass('external');
$(".solid_text a[href$='.pdf']").addClass("pdf");

$('.subnav li:last').addClass('last');


// Page images - sitewide
$('.image_wrap img').each(function() {
	var $this = $(this),
		w = $this.attr('width'),
		$wrap = $this.parents('.image_wrap');
	$wrap.css('width', w);
	$wrap.siblings('.caption').css('width', w);
});
$('.caption').each(function() {
	var $this = $(this),
		$img = $this.prev('img'),
		w = $img.attr('width');
	$this.css('width', w);
	
});	


$('img.page_image').each(function() {
	var $this = $(this),
		w = $this.attr('width');
	$this.siblings('.caption').css('width', w);
});




/* Contact and Appt - user message */
$('div.user-message').delay(15000).slideUp('slow');

/* Last Blog entry */
$(".blog_entry:last").addClass("noborder");

