$(document).ready(function(){
	$('ul li:first-child').addClass('first-child');
	$('ul li:last-child').addClass('last-child');
	$('.entry p:first-child').addClass('first-child');
	
	var post = $('.switcher li a.active').attr("href");
	$('.switcher li a').click(function(e){
		e.preventDefault();
		var newpost = $(this).attr("href");
		if (post != newpost) {
			$('.switcher li a').removeClass('active');
			$(this).addClass('active');
			$(newpost).css("left", "300px").show().animate({"left": "0px"},1);
			$(post).animate({"left": "-260px"},1000).hide();
			//$(newpost).show().animate({"left": "20px"},1);
			//$(newpost).animate({"left": "20px"},1);
			$(newpost+" p").css("marginLeft", "300px").animate({"marginLeft": "0px"},800);
			//$(newpost+" p").animate({"marginLeft": "0px"},800);
			$(newpost+" .more_events").css("marginLeft", "300px").animate({"marginLeft": "0px"},1000);
			//$(newpost+" .more_events").animate({"marginLeft": "0px"},1000);
			post = newpost;
		}
	});
	
	$(".search-form .txt").focus(function(){
		if(this.value == this.title) {
			this.value = "";
		}
	});
	$(".search-form .txt").blur(function(){
		if(this.value == "") {
			this.value = this.title;
		}
	});
	
	$('#mainNav>li:not(.current_page_item, .current_page_ancestor, .parent)').css({backgroundPosition:"0 -40"}).hover(
		function(){$(this).stop().animate({backgroundPosition:"(-386 -40)"}, {duration:300, complete:function(){$(this).children('a').css({color:"#fff"})}}).children('a').css({color: "#4b81d4"})},
		function(){$(this).stop().animate({backgroundPosition:"(0 -40)"}, {duration:200, complete:function(){$(this).css({backgroundPosition: "0 -40"})}}).children('a').css({color: "#144369"})}
	);
	$('#mainNav>li.parent:not(.current_page_item, .current_page_ancestor)').css({backgroundPosition:"0 -40"}).hover(
		function(){$(this).stop().animate({backgroundPosition:"(-386 -40)"}, {duration:300, complete:function(){$(this).children('a').css({color:"#fff"})}}).children('a').css({color: "#4b81d4"})},
		function(){$(this).stop().animate({backgroundPosition:"(0 -40)"}, {duration:200, complete:function(){$(this).css({backgroundPosition: "0 -40"})}}).children('a').css({color: "#144369"})}
	);
	$('.tab-nav li a').click(function(e){e.preventDefault();});
	var tab = $('.tab-nav li.active a').hash;
	$('.tab-nav li a').hover(function(e){
		$('#callout > div').hide();
		$('#callout > div').filter(this.hash).show();
		$('.tab-nav li').removeClass('active');
		$(this).parent().addClass('active');
	});

	if($(".open-modal").length > 0) {
		$(".open-modal").overlay({
			api: true,
			target: '#micro-site',
			absolute: true,
			top: 130,
			expose: {
				opacity: 0.85,
				maskId: 'exposeMask'
			},
			onBeforeLoad: loadPage,
			close: '.close'
		});
	}
	$('#exposeMask').click(function(e){});
loadPage(); //For some reason IE needs you to 'seed' the function call on page load.
});
closeModal = function(fileUrl) {
	$(".open-modal").each(function(){$(this).overlay().close()});	
};
var loadPage = function() {
	var url = null;
	if($('.info .timeout').length > 0)
		$('.info .timeout').remove();
	if($('#modalPage').length == 0)
		$('.info').prepend('<iframe id="modalPage" src="" width="100%" height="100%"></iframe>');
	if($('.info .loading').length == 0)
		$('.info').prepend('<div class="loading"><img src="/helpers/themes/pei/images/pei_loading1.6.gif" alt="" /></div>');
	$('html, body').animate({scrollTop:0}, 'slow');
	$(".info #modalPage").css("visibility", "hidden");
	if( typeof(this.getTrigger) == "function")
		url = this.getTrigger().attr("href");
	if(url != null) {
		$(".info #modalPage").src(url, function(duration) {
			$(".info #modalPage").css("visibility", "visible");
			$(".loading").remove();
		}, {
			timeout: 5000,
			timeoutDuration: 30000,
			onTimeout: function() { 
				$(".loading").remove(); 
				if($('.info .timeout').length == 0)
					$('.info').prepend('<div class="timeout"><p>Your request has timed out.  Please close the modal and try again.</p></div>');
			}
		}
	    );
	}
};

