$(document).ready(function() {

	// handle search form
	$(".search-block input").focusin(function() {
		if ($(this).val()=="Search churchillservices.com") { $(this).val(""); }
	});
	$(".search-block input").focusout(function() {
		if ($(this).val()=="") { $(this).val("Search churchillservices.com"); }
	});
	$(".search-block").parent().submit(function() {
		if ($(".search-block input").val()=="Search churchillservices.com") {
			alert("Please enter one or more keywords.");
			return false;
		} else {
			return true;
		}
	});

	// handle opening of offsite links
	$('[rel*="nofollow"]').click(function(){
        window.open(this.href);
        return false;
    });

	// add the main menu
	$("ul.sf-menu").supersubs({ extraWidth:1 }).superfish();

	$(function() {
		var zIndexNumber = 1000;
		$('div').each(function() {
			$(this).css('zIndex', zIndexNumber);
			zIndexNumber -= 10;
		});
	});

});

// Custom script
window.onload = function(){
	// normal slides
	$('.slides').cycle({
		fx: 'scrollLeft',
		timeout: 9000,
		speedIn: 1500,
		speedOut: 3000,
		requeueOnImageNotLoaded: true
	}) //.cycle("destroy");

	// normal slides
	$('.logo-cycle').cycle({
		fx: 'fade',
		requeueOnImageNotLoaded: true
	}).fadeIn('slow');

	$('.slides').fadeIn('slow', function() {
		// Animation complete
		$('.servmenu-block .green').show(275, function() {
			// Animation complete
			$('.servmenu-block .blue').show(275, function() {
				// Animation complete
				$('.servmenu-block .cyan').show(275, function() {
					// Animation complete
					// handle hovers
					$('.servmenu-block .blue h2 a').hover(
						function () {
							// animate blue items in
							$('.servmenu-block .blue p, .servmenu-block .blue ul').stop(true, true).show();
						}, 
						function () {
							// animate blue items out
							$('.servmenu-block .blue p, .servmenu-block .blue ul').stop(true, true).hide();
						}
					);
					$('.servmenu-block .cyan h2 a').hover(
						function () {
							// animate blue items in
							$('.servmenu-block .cyan p, .servmenu-block .cyan ul').stop(true, true).show();
						}, 
						function () {
							// animate blue items out
							$('.servmenu-block .cyan p, .servmenu-block .cyan ul').stop(true, true).hide();
						}
					);
					$('.servmenu-block .green h2 a').hover(
						function () {
							// animate blue items in
							$('.servmenu-block .green p, .servmenu-block .green ul').stop(true, true).show();
						}, 
						function () {
							// animate blue items out
							$('.servmenu-block .green p, .servmenu-block .green ul').stop(true, true).hide();
						}
					);
				});
			});
		});
	});

}

