/* Sound Sleep */
$(document).ready(function() {

	// Clear form field on focus
	$('.txt').focus( function() { if( $(this).val() == $(this).attr("defaultValue") ) { $(this).val(''); } });
	$('.txt').blur( function() { if( $(this).val() == "" ) { $(this).val( $(this).attr("defaultValue") ); } });

	// GOOGLE MAP COLORBOX
	$(".googlemap").colorbox({width:"80%", height:"80%", iframe:true});
	
	// YOUTUBE COLORBOX
	$("#videolist li a").colorbox({width:"550px", height:"441px", iframe:true, href:function(){var url = $(this).attr('href'); return url; } });
	
	
	// auto-add-in 'read more' hooks after 1 bullet points
	$("ul.readmorelimit").each(function() {
		var elem = $(this); 
		// break up list into separate lists, more than 4 is toggle_container
		if ( elem.children("li").length > 1 )
		{
			elem.after('<ul class="toggle_container">');            // add hidden container after current element
			var hiddenContainer = elem.next(".toggle_container");   // save a reference to it
			elem.children("li").slice(1).appendTo(hiddenContainer); // move the children past the limit
			hiddenContainer.after('<p class="trigger"><a href="#">READ MORE</a> <img src="/images/li_content.jpg" alt="" /></p>'); // read more button
		}
	});
	
	//Hide (Collapse) the toggle containers on load
	$(".toggle_container").hide(); 

	//Switch the "Open" and "Close" state per click
	$("p.trigger a").toggle(function(){
		$(this).text('READ LESS');
		}, function () {
		$(this).text('READ MORE');
	});
	//Slide up and down on click
	$("p.trigger a").click(function(){
		$(this).parent().prev(".toggle_container").slideToggle("slow");
	});
	
	// Sidebar contact form
	$("#sideform .submit").click(function(){
		$("span.error").hide();
		var hasError = false;
		if ($("#pform-name").val() == 'Name') {
			$("#pform-name").after('<br /><span class="error">Field Above is Required</span>');
			hasError = true;
		} 
		if ($("#pform-email").val() == 'Email') {
			$("#pform-email").after('<br /><span class="error">Field Above is Required</span>');
			hasError = true;
		} 
		if(hasError == true) {return false;}
	});

	$("#sideform").validate( { ignoreTitle: true, errorElement: "span", messages: {Purpose: { required: "<br />Field Above is Required"}} } );



});
