$(document).ready(function() {

	handle_mouseovers("#masthead h1 a[href], #nav .nav li a[href]");

	// seems to work with Firefox & IE
	$bodybg = $("body").css("background-color");
	// alert($bodybg);
	if (($bodybg == "rgb(173, 149, 100)") || ($bodybg == "#ad9564")) {
		//alert('css enabled');
	} else {
		// alert('css disabled');
	}
	/*
		make CSS3 selectors work on (ahem) non-compliant browsers
	*/
	$("#main div.listgroup-3").css("position", "relative");
	$("#main div.listgroup-3").css("margin-left", "85px");
	$("#main div.listgroup-3 ul").css("list-style", "none");
	$("#main div.listgroup-3 ul").css("width", "205px");
	$("#main div.listgroup-3 ul").css("top", "0px");
	$("#main div.listgroup-3 ul").css("border-right", "1px solid #84877c");
	$("#main div.listgroup-3 ul").css("left", "0px");
	$("#main div.listgroup-3 ul:nth-child(2), #main div.listgroup-3 ul:nth-child(3)").css("position", "absolute");
	$("#main div.listgroup-3 ul:nth-child(2)").css("left", "200px");
	$("#main div.listgroup-3 ul:nth-child(2)").css("width", "185px");
	$("#main div.listgroup-3 ul:nth-child(2), #main div.listgroup-3 ul:nth-child(3)").css("padding-left", "25px");
	$("#main div.listgroup-3 ul:nth-child(3)").css("left", "410px");
	$("#main div.listgroup-3 ul:nth-child(3)").css("border-right", "none");
	$("#main div.listgroup-3 li").css("margin", "0");
	$("#main div.listgroup-3 li").css("padding", "0");
	$("#main div.listgroup-3 ul li:nth-child(even)").css("color", "#333");
	$("#main div.listgroup-3 ul li:nth-child(odd)").css("color", "#ccab6e");

	//$("#contact #main dl.inline").css("border", "1px dotted white");
	$("#contact #main").css("height", "160px");
	//$("#contact #main p:eq(0)").css("border", "1px dotted yellow");
	$("#contact #main p:eq(0)").css("margin", "22px 0 0px 0");
	$("#contact #main dl.inline").css("width", "70%");
	$("#contact #main dl.inline").css("height", "40px");
	$("#contact #main dl.inline").css("margin-left", "160px");

	// JQuery selector:   dl.inline > dd:eq(0)
	// is equivalent to:  dl.inline dd:nth-of-type(0n+1)
	$("#contact #main dl.inline > dt").css("clear", "none");
	$("#contact #main dl.inline > dd").css("width", "20%");
	$("#contact #main dl.inline > dt:eq(1)").css("width", "40px");
	$("#contact #main dl.inline > dt:eq(2)").css("visibility", "hidden");
	$("#contact #main dl.inline > dd:eq(0)").css("border-right", "1px solid #84877c");
	$("#contact #main dl.inline > dd:eq(0)").css("width", "130px");
	$("#contact #main dl.inline > dd:eq(1)").css("width", "50px");
	$("#contact #main dl.inline > dd:eq(2)").css("width", "500px");
	$("#contact #main dl.inline > dd:eq(2)").css("padding-left", "50px");
	$("#contact #main dl.inline > dd:eq(2)").css("padding-left", "50px");

	$("#testimonials #main p:nth-child(odd)").css("color", "#333");
	$("#testimonials #main p:nth-child(even)").css("color", "#ccab6e");

	// find the tallest <ul> inside div.listgroup-3
	// apply that height to div.listgroup-3
	$maxheight	= 0;
	$heights		= ''
	$("#main div.listgroup-3").children("ul").each( 
	  function(){
			$curheight	= $(this).height();
			$heights	  += '-' + $curheight;
			if ($curheight > $maxheight) {
				$maxheight = $curheight;
			}
	  }
	);
	//alert('heights: ' + $heights + "\n" + 'max height: ' + $maxheight);
	$("#main div.listgroup-3").css("height", $maxheight + "px");

	// create cross-fade photos
	$(function() {

		$('#home #navphotos-center').crossSlide({
		  sleep: 2,
		  fade: 1
		}, [
		  { src: 'images/faucet.jpg' },
		  { src: 'images/kitchen.jpg' },
		  { src: 'images/shower.jpg' }
		]);

		$('#about #navphotos-center').crossSlide({
		  sleep: 2,
		  fade: 1
		}, [
		  { src: '../images/bathroom.jpg' },
		  { src: '../images/bath-faucet.jpg' },
		  { src: '../images/curtain-striped.jpg' }
		]);

		$('#services #navphotos-center').crossSlide({
		  sleep: 2,
		  fade: 1
		}, [
		  { src: '../images/vanity.jpg' },
		  { src: '../images/faucet-tiles.jpg' }
		]);

		$('#testimonials #navphotos-center').crossSlide({
		  sleep: 2,
		  fade: 1
		}, [
		  { src: '../images/dark_partition.jpg' },
		  { src: '../images/faucet-diptych.jpg' }
		]);

		$('#contact #navphotos-center').crossSlide({
		  sleep: 2,
		  fade: 1
		}, [
		  { src: '../images/faucet-shower.jpg' },
		  { src: '../images/shower-faucets.jpg' }
		]);

	});

});

// $selector will usually be an "a[href]" tag
// function handles mouseovers, mouseouts, preloading of nested <img>s
function handle_mouseovers($selector) {
	// alert('ok');
	// preload images
	$($selector).each(function() {
		// Set the original src
		rollsrc = $(this).children("img").attr("src");
		rollON = rollsrc.replace('_off', '_on');
		newImg = new Image(); 				// create new image obj
		$(newImg).attr("src", rollON);	// set new obj's src
	});

	$($selector).mouseover(function(){
		imgsrc = $(this).children("img").attr("src");
		if (typeof(imgsrc) != 'undefined') {
			imgsrcON = imgsrc.replace('_off', '_on');
			$(this).children("img").attr("src", imgsrcON);
		}
	});

	$($selector).mouseout(function(){
		if (typeof(imgsrc) != 'undefined') {
			$(this).children("img").attr("src", imgsrc);
		}
	});

}

