
/* **************************************************************************************
 *                                                                                      *
 *  jquery.jhu.js                                                                       *
 *  JQUERY CODE FOR JHU MUSEUMS SITE                                                    *
 *                                                                                      *
 *  b. Creative Group                                                                   *
 *                                                                                      *
 **************************************************************************************** */

var pageIs = function(searchString) {
	if((window.location.pathname.indexOf(searchString) == -1) || (window.location.pathname.indexOf(searchString) == false)) return false;
	else return true;
};

jQuery.fn.isChildOf = function(b){ 
	return (this.parents(b).length > 0); 
};

/* ON READY FUNCTION |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| */

$(document).ready(function() {

/* PREFLIGHT ============================================================================ */

// hide splitmenus
$('ul.split').css('opacity', 0).css('top', -100);

// hide splitmenus
$('li.primary').css('background-position-y', '-100px');

// prep the calendar list
$(".calendarList>li.event").colorize('#b8851b', '#cec262', [1,1,1], "background-color");
$(".calendarList li.event .event_information").hide();
/* $(".event_title").truncate(60); */
$(".calendarList li.event").hide();
$(".calendarList li.upcoming_event").show();

/* ================================================================================== END */

/* EXTERNAL LINKING ===================================================================== */

// make sure rel=external links open a new window,
// and make sure we account for the links inside of calendar list items.
$('a').click(function(){
	if($(this).isChildOf('.calendarList li')) {
		if($(this).attr('rel') == 'external') {
			window.open($(this).attr('href'));
			return false;
		} else window.location = $(this).attr('href');
	} else {
		if($(this).attr('rel') == 'external') {
			window.open($(this).attr('href'));
			return false;
		}
	}
});

/* ================================================================================== END */

/* FRONT PAGE BEHAVIORS ================================================================= */

var timer = 400;
$('li.primary').each(function(){
	$(this).oneTime(timer, function(){
		$(this, '').animate({
			backgroundPositionY: '0'
		}, 500, 'easeOutQuad', function(){
			$("#nav1 ul.nav li.primary-group").splitmenu();
		});
	});
	timer += 150;
});
	
/* ================================================================================== END */

/* CALENDAR BEHAVIORS =================================================================== */

// update jump widgets
$('#jump-widget select').change(function(){
	$(this).parent('form').submit();
});

// show & hide event information on click-toggle
if($(".calendarList li").length > 1) {
	$(".calendarList li").toggle(function(){
		$(".event_information", this).slideDown("slow", "easeOutQuad");
	}, function(){
		$(".event_information", this).slideUp("slow", "easeInQuad");
	});
} else {
	$(".event_information", ".calendarList li").slideDown("slow", "easeInQuad");
}

// show & hide events that are not imminent
$("div#event_view").toggle(function(){
	var c = 0;
	var t = $(".calendarList li.event").length;
	$(".calendarList li.event").eq(c).slideDown("slow", "easeOutQuad");
	$("div#event_view").removeClass("see_all").addClass("animating"); // give user visual feedback
	c++;
	$(".calendarList").everyTime(150, function(){
		if(c == t) {
			// give user text feedback
			$("div#event_view p").html('See only upcoming events<span class="assistive">...</span>');
			$("div#event_view").removeClass("animating").addClass("hide_all");
		}
		$(".calendarList li.event").eq(c).slideDown("slow", "easeOutQuad");
		c++;
	});
}, function(){
	var t = 0;
	var c = $(".calendarList li").length;
	$(".calendarList li.event").not(".upcoming_event").eq(c).slideUp("slow", "easeOutQuad");
	$("div#event_view").removeClass("hide_all").addClass("animating"); // give user visual feedback
	c--;
	$(".calendarList").everyTime(150, function(){
		if(c == t) {
			// give user text feedback
			$("div#event_view p").html('See all scheduled events<span class="assistive">...</span>');
			$("div#event_view").removeClass("animating").addClass("see_all");
		}
		$(".calendarList li.event").not(".upcoming_event").eq(c).slideUp("slow", "easeInQuad");
		c--;
	});
});


/* ================================================================================== END */

/* CALENDAR BEHAVIORS =================================================================== */

$('#availability #jump-widget input').css('display', 'none');
$('#jump-widget select').change(function(){
		$(this).parent('form').submit();
});
	
/* ================================================================================== END */

/* COLLECTION IMAGERY =================================================================== */

// cycle through images in collections
$('.collection .imagery').cycle();

/* ================================================================================== END */

});

/* |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| END EVENT */

/* ON LOAD FUNCTION ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| */

$(window).load(function(){
  $("#home #slideshow").cycle({
  	fx: 'fade',
    timeout: 8000,
    continuous: 20,
    speed: 5000,
    slideExpr: $("#slideshow img"),
    before: function(currSlideElement, nextSlideElement) {
      $('#ss_caption').text($(nextSlideElement).attr('alt')).show();
    },
    pause: true,
    next: $('#home #slideshow')
  });
});

//window.onload = function(){
//	$(document).iealpha();
/* 	$('#header *').iealpha(); */
//}

/* |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| END EVENT */
