/* imageCaption.js - requires jquery */
/* Edited 2009-01-01 MJY */

	// to add new image pairs, follow the pattern here; pay CAREFUL ATTENTION to the ',' at the end of every line except the last
	var image_url = new Array(
		new Array('home-1.jpg','home-1b.jpg'),
		new Array('home-2.jpg','home-2b.jpg'),
		new Array('home-3.jpg','home-3b.jpg'),
		new Array('home-4.jpg','home-4b.jpg'),
		new Array('home-5.jpg','home-5b.jpg'),
		new Array('home-6.jpg','home-6b.jpg'),
		new Array('home-7.jpg','home-7b.jpg')
		
	);

	// this is the path to the background images
	var gPath = 'http://216.92.252.234/graphics/';

	// ----- no user-serviceable parts below here ------

	var imageId = (Math.floor(Math.random() * image_url.length) );
	var bgUrl1 = gPath + image_url[imageId][0];
	var bgUrl2 = gPath + image_url[imageId][1];

	// these are the values to be set for the 'background' CSS
	var backGround_1 = "#526931 url('" + bgUrl1 + "') no-repeat scroll 0% 0%";
	var backGround_2 = "transparent url('" + bgUrl2 + "') no-repeat scroll 0% 0%";

	// preload the images
	var bgImage1 = new Image(); 
	var bgImage2 = new Image(); 
	bgImage1.src = bgUrl1;
	bgImage2.src = bgUrl2;

/* js for image handling looks for img tags with caption class, 
gets the img width, wraps a div around the image and sets the div width to the image width, 
grabs the next paragraph and moves that inside the div 
Example: <img src="img-118" class="caption left" alt="" /> */ 
	$(window).bind("load", function(){
		$("img.caption").each(function(){
			var caption = null;
			var imgWidth = this["width"];
			//	var reqWidth = imgWidth + 10;
			var reqWidth = imgWidth;
			var addClass = '';

			if ($(this).hasClass('left')) {
				addClass = ' left';
			} else if ($(this).hasClass('right')) {
				addClass = ' right';
			}

			if ($(this).next().is('p')) {
				caption = $(this).next();
				$(this).wrap("<div class='figure" + addClass + "' style='width:"+reqWidth+"px'></div>");
				var captionText = caption.html();
				$(this).after("<p>"+captionText+"</p>");
				$(caption).remove();
			} else if ($(this).parent().is('p')) {
				caption = $(this).parent().next();
				$(this).parent().wrap("<div class='figure" + addClass + "' style='width:"+reqWidth+"px'></div>");
				if ($(caption).is("p")) {
					var captionText = caption.html();
					$(this).parent().after("<p>"+captionText+"</p>");
					$(caption).remove();
				}
			}
		});
	});
	
	/* js for showing and hiding rich footer or site map, edited 8.4.08 sc */
	$(document).ready(function(){
		$("a.show").click(function(){
			$("#footer1, #home #footer2").slideToggle("slow");
			if($("a.show").text() == "Hide Site Map") {
					$("a.show").text("Show Site Map");
				} else {
					$("a.show").text("Hide Site Map");
				}
				return false;
		 // $(this).toggleClass("active");
		});

		$('#home #wrapper').css("background", backGround_1);
		$('#home #footer-top').css("background", backGround_2);

	});
