$.noConflict();
jQuery(document).ready(function($) {
	$('#search-query').focus(function() {
		$(this).filter(function() {
			return $(this).val() == 'Site search...';
		}).removeClass('watermark').val('');
	});

	$('#search-query').blur(function() {
		$(this).filter(function() {
			return $(this).val() == '';
		}).addClass('watermark').val('Site search...');
	});

	$('li a.target').mouseenter(function() {
		$(this).parent().addClass('activated'); 
		$(this).next().show();
	});

	$('li').mouseleave(function() {
		if ($(this).hasClass('activated')) {
			$(this).removeClass('activated');
			$(this).children('ul').hide();
		}
	});

	$('div.reflect_archive_list h2 a').click(function(e) {
		if ($(this).hasClass('open')) {
			$(this).removeClass('open');
			$(this).parent().next().hide();
			e.preventDefault();
		}
		else {
			$(this).addClass('open');
			$(this).parent().next().show();
			e.preventDefault();
		}
	});

	$('a[rel="external"]').click(function(e) {
		window.open($(this).attr('href'));
		e.preventDefault();
	});

	$('div#ticker div').bind('marquee', function(e, sRight) {
		var iDuration;
	
		if (sRight == 'new') {
			$(this).css('right', '-' + $(this).width() + 'px');
			iDuration = (626 + $(this).width()) / 40;
		}
		else {
			sRight = sRight.substring(0, sRight.length - 2);
			iDuration = (626 - sRight) / 40;
		}

		$(this).animate({ right: $(this).parent().width() }, iDuration * 1000, 'linear', function() {
			$(this).trigger('marquee', ['new']);
		});
	}).trigger('marquee', ['new']);

	$('div#ticker').mouseenter(function() {
		$('div#ticker div').stop();
	});

	$('div#ticker').mouseleave(function() {
		$('div#ticker div').trigger('marquee', [$('div#ticker div').css('right')]);
	});

	if ($('div#home-header').length) {
		//var showSlide = Math.floor(Math.random() * 6);
		var showSlide = 0;
		//$('img#slide-' + showSlide).show();
		//$('p#caption-' + showSlide).show();

		if (showSlide != 0) {
			$('p#title-' + showSlide).addClass('selected');
		}

		var hideSlide = showSlide;

		if (showSlide == 5) {
			showSlide = 0;
		}
		else {
			showSlide++;
		}

		setInterval(slideShow, 8000);
	}

	function slideShow() {
		$('p.slide-title').removeClass('selected');
		$('p#title-' + showSlide).addClass('selected');

		//$('p#caption-' + hideSlide).fadeOut('slow');
		//$('p#caption-' + showSlide).fadeIn('slow');

		//$('img#slide-' + hideSlide).fadeOut('slow');
		//$('img#slide-' + showSlide).fadeIn('slow');

		hideSlide = showSlide;

		if (showSlide == 5) {
			showSlide = 0;
		}
		else {
			showSlide++;
		}
	}
	
	$('select#category').change(function() {
		window.location.href = '/news-events/calendar-of-events' + $(this).val();
	});
});

