$(document).ready(function() {

	// Set z-index variable higher than any 'postcard thumbnail' object.
	var myZIndex = 10;
	
	// Listener for CSS 'postcard' class for mouse over/hover event.
	$(".postcard").mouseover(function() {
		// Change the z-index on the object. This brings the object to the fore. Then increment the 'myZIndex' variable.
		$(this).css("zIndex",myZIndex++);
	});
	
	// Listener for CSS 'postcard' class for click event
	$(".postcard").click(function() {
		// Set variables.
		// Get the pathname of the current page.
		var pathname = location.pathname;
		// Get the src of the postcard image clicked.
		var postcardSrc = this.src;
		// Check if page is 'Walks' page.
		if (pathname.indexOf("walks.php") != -1) {
			// Get the image file name of the postcard thumbnail clicked.
			postcardSrcFilename = postcardSrc.replace(/^http:\/\/.*\.dohertys\.ie\/.*\/([^/]+)$/i, "$1");
			// Load the appropriate iframe with Google maps location depending on the postcard image clicked.
			switch (postcardSrcFilename) {
				case "find_us.png":
					$("#display-iframe").load('scripts/walks_iframes/iframe1.txt');
					break;
				case "walk1.png":
					$("#display-iframe").load('scripts/walks_iframes/iframe2.txt');
					break;					
				case "walk2.png":
					$("#display-iframe").load('scripts/walks_iframes/iframe3.txt');
					break;
				case "walk3.png":
					$("#display-iframe").load('scripts/walks_iframes/iframe4.txt');
					break;
				case "walk4.png":
					$("#display-iframe").load('scripts/walks_iframes/iframe5.txt');
					break;
				case "walk5.png":
					$("#display-iframe").load('scripts/walks_iframes/iframe6.txt');
					break;					
				default:
					// Do nothing
					// alert("Other");
			}
		} else {
			// Check if page is 'Find Us' or 'Walks' page.
			if ((pathname.indexOf("find_us") != -1) || (pathname.indexOf("walk") != -1)) {
				// If the image is the Google image, then show the Google iframe & hide the image
				if (postcardSrc.indexOf("google.png") != -1) {
					$("#display-img").hide();
					$("#display-iframe").show();				
				// If the image is not the Google image, then hide the Google iframe & show the image
				} else {
					$("#display-iframe").hide();
					$("#display-img").show();	
				}
			}
			// Get the info of the object clicked
			var srcStr = this.src;
			var altStr = this.alt;
			var titleStr = this.title;
			// Replace the postcard/thumbnail info with the large image info
			srcStr = srcStr.replace("small", "large");
			srcStr = srcStr.replace("png", "jpg");
			// Get the object to swap to
			target = document.getElementById("display-img");
			// Update the object
			target.src = srcStr;
			target.alt = altStr;
			target.title = titleStr;
		} 
	});	
	
	// Listener for CSS 'open' class for click event	
	$(".open").click(function() {
		window.open(this.href, "", "left=400px, toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=800, height=600");
		return false;
	});
	
});
