$(document).ready(function() {
		
$('#coin-slider').coinslider({ width: 257, height: 248, effect: 'rain', navigation: false, delay: 3000, sDelay: 70, spw: 3, sph: 2, links: false });
	
});



$(function() {
	
	// Drop-down menu
	$("#nav > li").mouseenter(function() {
		This = $(this);
		Submenu = This.find(".submenu");
		
		if (typeof timer == "number") {
			clearTimeout(timer);
			timer = "";
			
			VisibleSubmenu = $("#nav .submenu:visible");
			if (VisibleSubmenu.parent().attr("class") != This.attr("class")) {
				hideSubmenu();
			}
		}
		
		Submenu.slideDown(200);
		
	}).mouseleave(function() {
		timer = setTimeout("hideSubmenu()", 300);
	});

	$( "#dialog" ).dialog({ autoOpen: true, modal: true , closeOnEscape: true, draggable: false, resizable: false });

  	$("#slides").slides({	preload: true,
				preloadImage: 'images/slideloading.gif',
				play: 5000,
				pause: 2500,
				hoverPause: true });

	$('#slideshow').nivoSlider({ effect: "fade", pauseTime:3000, controlNav: false });
	
	$(".page-template-accreditations-php .video_link, .page-template-accreditations-php .video_thumb").click(function() {
		$("#shadow").css({width: $("body").width(), height: $("body").height()}).fadeIn(200);
		$("#overlay").slideDown(300);
		return false;
	});
	
	$("#shadow").click(function() {
		$("#overlay").hide(300);
		$("#shadow").fadeOut(300);
		return false;
	});

	
	$("#contact input").focus(function() {
		This = $(this);
		Placeholder = This.attr("placeholder");
		
		if (Placeholder == This.val()) {
			This.val("");
		}
	}).blur(function() {
		This = $(this);
		
		if (This.val() === "") {
			This.val(This.attr("placeholder"));
		}
	});
	
	$("#map_links a").click(function() {
		showDots($(this).attr("class"));
		$(this).addClass("active");
		
		return false;
	}).mouseenter(function() {
		showDots($(this).attr("class"));
	}).mouseleave(function() {
		if (!$(this).hasClass("active")) {
			hideDots();
		}
	});
	
	createImageMap();
	
	$("div.shape").mouseenter(function() {
		Class = $(this).attr("class");
		Class = Class.split(" ");
		Class = Class[1];
		
		showDots(Class);
		$("#map_links a."+Class).addClass("active");
	}).mouseleave(function() {
		mapTimer = setTimeout("hideDots()", 200);
	});
	
	// Contact Form
	$("#contact").submit(function(e) {
		e.preventDefault();
		$("#data").html('<img src="/wp-content/themes/turtlerock/images/loading.gif" alt="Loading..." id="loading" />');
		$.post($(this).attr("action"), $(this).serialize(), function(data) {
			D = $.parseJSON(data);
			Div = $("#data");
			
			if (D.error) {
				Div.html("<b>"+D.message+"</b>");
			} else {
				Div.html("<strong>"+D.message+"</strong>");
			}
		});
	});
});

// Map
// Map Object with dot's coordinates in left,top strings
// relative to the parent div
Map = {
	infant: {
		room1: "348,276",
		room2: "378,266"
	},
	toddler: {
		room1: "408,255",
		room2: "448,243"
	},
	preschool: {
		room1: "455,327",
		room2: "502,308"
	},
	prekinder: {
		room1: "490,228",
		room2: "552,288",
		room3: "579,246",
		room4: "605,269"
	},
	kinder: {
		room1: "528,216"
	},
	office: {
		room1: "409,324",
		room2: "419,352"
	},
	kitchen: {
		room1: "324,286"
	}
}

function createImageMap() {
	// Adds divs to act as shapes in an image map
	Classes = ["infant", "toddler", "preschool", "prekinder", "kinder", "office", "kitchen"];
	for (var n in Classes) {
		// Select Map top category first
		Dots = Map[Classes[n]];
		
		for (var i in Dots) {
			Dot = Dots[i];
			Coord = Dot.split(",");
			Width = 30;
			Height = 30;
			
			Div = $("<div>");
			Div.addClass("shape "+Classes[n]);
			Div.css({
				left: (Coord[0]-(Math.floor(Width/2)))+"px",
				top: (Coord[1]-(Math.floor(Height/2)))+"px"
			});
			
			$("#content_box .content").append(Div);
		}
	}
}

function showDots(Class) {	
	hideDots();

	Dots = Map[Class];
	
	for(var i in Dots) {
		Dot = Dots[i];
		
		Coord = Dot.split(",");
		
		Img = $("<img>");
		Img.attr("src", "/wp-content/themes/turtlerock/images/blank.gif");
		Img.addClass("dots "+Class)
		Img.css({
			left: Coord[0]+"px",
			top: Coord[1]+"px",
		}).css("opacity", 0);
		
		$("#content_box .content").append(Img);
	}
	
	$("#content_box .content > img").animate({
		opacity: 1,
		top: "-=10"
	}, 300).animate({
		top: "+=10"
	}, 200);
	
	return false;
}

function hideDots() {
	clearTimeout(mapTimer);
	
	// Delete old dots
	$("#content_box .content > img").animate({
		opacity: 0
	}, 300, function() {
		$(this).remove();
	});
	
	$("#map_links a").removeClass("active");
}

function hideSubmenu() {
	$("#nav .submenu").slideUp(100);
}

