jQuery.noConflict();
(function ($) {
		
	//Plugin: Fallback for HTML5 input[placeholder]
	$.fn.inputPlaceholder = function() {
		if ( !Modernizr.input.placeholder ) {
			this.each(function() {
				var input = $(this);
				var origValue = input.attr('placeholder');
				input.val(origValue).focus(function () {
					if ( input.val() === origValue ) {
						input.val('');
					}
				}).blur(function () {
					if ( input.val() === '' ) {
						input.val(origValue);
					}
				});
			});
			return this;
		}
	};
	
	//Set sidebar height
	var sidebar = $('#sidebar-wrapper');
	var content = $('#content');
	var sidebarHeight = sidebar.height();
	var contentHeight = content.height();
	if ( sidebarHeight < contentHeight ) {
		sidebar.height(contentHeight + 80);
	}
	
	//Enable placeholders
	$('#content-footer input.text, #sidebar-newsletter input.text').inputPlaceholder();
	
	//Enable home page banner scrolling
	var slideshow = $('#slideshow-navigation ul');
	if ( slideshow.length ) {
		var scrollIndex = 0;
		slideshow.serialScroll({
			axis: 'y',
			duration: 1500,
			step: 1,
			cycle: true,
			items: 'li',
			interval: 5000,
			easing: 'linear',
			force: true,
			lazy: true,
			constant: true,
			onBefore: function (event, element) {
				var theUl = $(element).closest('ul');
				theUl.append(theUl.find('li:eq(' + scrollIndex + ')').clone());
				scrollIndex = scrollIndex + 1;
				theUl.animate({ top: '-=82' }, 1600); //IE7 fix
			},
			onAfter: function (element) {
				
			}
		});
		$('#slideshow-slides').cycle({ startingSlide: 1, speed: 1500, timeout: 5000 });
	}
	
	//Enable home page recent news scrolling
	var news = $('#in-the-news-scroller');
	if ( news.length ) {
		news.serialScroll({
			axis: 'x',
			duration: 500,
			step: 2,
			cycle: true,
			items: 'li',
			easing: 'linear',
			next: '#in-the-news-next',
			prev: '#in-the-news-prev'
		});
	}
	
	//Insert sidebar events
	var events = $('#sidebar-upcoming-events');
	if ( events.length ) {
		var calendarUrl = '/load-calendar.php';
		$.get(calendarUrl, function (data, textStatus, xhr) {
			events.find('p').remove();
			var rows = $(data).find('table#tbMonth tr');
			var realCurrentDate = new Date();
			var realCurrentDayOfMonth = parseInt(realCurrentDate.getDate()); //1-31
			var currentDate;
			var count = 0;
			rows.each(function (index, row) {
				if ( index > 0 ) {
					currentDateTemp = $(row).find('td:eq(0)').text();
					if ( /\d{1,2}\/\d{1,2}/.test(currentDateTemp) ) {
						currentDate = currentDateTemp.split('/');
					}
					if ( count < 5 && parseInt(currentDate[1]) >= realCurrentDayOfMonth )  {
						var eventTitle = $(row).find('td:eq(2)').text();
						var eventMonthNumber = currentDate[0];
						var eventDayNumber = currentDate[1];
						var eventLocation = $(row).find('td:eq(3)').text();
						var eventMarkup = '<div class="article">' +
										  '<div class="header">' +
										  '<h3>' + eventTitle + '</h3>' +
										  '<div class="time">' + eventDayNumber + '</div>' +
										  '</div>' + 
										  ( eventLocation ? '<p>at ' + eventLocation + '</p>' : '<p>&nbsp;</p>' ) +
										  '</div>';
						$('#upcoming-events').append(eventMarkup);
						count = count + 1;
					}
				}
			});
		});
	}
	
	//IE6 drop downs
	if ( $.browser.msie && parseFloat($.browser.version) < 7.0 ) {
		$('#primary-menu li').hover(
			function () {
				$(this).find('ul:first').show();
			},
			function () {
				$(this).find('ul:first').hide();
			}
		);
	}
	
})(jQuery);
