//##############################################################################
//##  DOM																	  ##
//##############################################################################
$(document).ready( externalLinks );
/*###########################################
##  Dropdown Menus						   ##
###########################################*/
/* Options */
var __global_menuContainer = '.navigation';
var __global_menuObject = '#primaryNavigation';

/* Controls */
$(document).ready(function() {
	var lis = $(__global_menuContainer).children('li').get();
    $.each(lis, function(){
      $(this).hover(
	    function () { //on
	      $(this).addClass("sfhover")
	    }, 
	    function () { //off
	      $(this).removeClass("sfhover")
	    }
	  );
    });
});

/*###########################################
##  Legacy Transparency					   ##
###########################################*/
$(document).ready(function() {
  /* Body */
  $("img").each(function(){ //fix legacy transparency
    var fileExtension = $(this).attr("src").substr($(this).attr("src").lastIndexOf(".png"));
    if (fileExtension == ".png") { $(this).addClass("transparent"); }
  });
});

/*###########################################
##  Cuf—n Init							   ##
###########################################*/
Cufon.replace('#primaryNavigation h2', { hover: true, 
										 fontFamily: 'Museo Sans 500',
										 textShadow: '2px 2px rgba(0, 0, 0, 0.2)'
									   });
Cufon.replace('.heading', { fontFamily: 'Museo Sans 500', hover: false });
Cufon.replace('.heading b', { fontFamily: 'Museo Sans 900', hover: false });
Cufon.replace('.bodyCopy h1, .bodyCopy h2, .bodyCopy h3, .bodyCopy h4', { fontFamily: 'Museo Sans 500', hover: false });
Cufon.replace('.bodyCopy h1 > b, .bodyCopy h2 > b, .bodyCopy h3 > b, .bodyCopy h4 > b', { fontFamily: 'Museo Sans 900', hover: false });

/*###########################################
##  Shadowbox Init						   ##
###########################################*/
Shadowbox.init({
	players: ["iframe", "html"]
});

/*###########################################
##  Paramater Edits						   ##
###########################################*/
$(document).ready(function() { //Styles for Primary Navigation
  var primNav = $(__global_menuObject);
  $.each(primNav,function(){
    var links = $(this).find('h2').get();
    $.each(links, function(i){
      var clean = __global_menuObject.replace(/[^a-zA-Z]+/g,'');
      $(this).addClass(clean+(i+1));
    });
  });
});
$(document).ready(function() { //Styles for Amenities SubNav
  var amenities = $('#amenities');
  $.each(amenities,function(){
    var links = $(this).find('a').get();
    $.each(links, function(){
      if ($(this).attr("title")) {
        var fmt = $(this).attr("title").toLowerCase();
        var clean = fmt.replace(/[^a-zA-Z]+/g,'');
        $(this).addClass(clean);
      }
    });
  });
});

/*###########################################
##  Feature Slideshow					   ##
###########################################*/
var loc = window.location.pathname; loc = loc.toString();
var inside = (loc.length >= 2)?true:false;
if (!inside) {
  $('#featureSlides').cycle({ 
		fx:    'fade',  
		timeout: 20000, //how long to wait between slides
		speed:  2000, //how long transition takes
		pause: 1 //stop on mouseover
  });
}

//##############################################################################
//##############################################################################
//##  User Handler Functions												  ##
//##############################################################################
function externalLinks() {
  var exs = $('a[rel=external]');
  $.each(exs, function() {
    if ($(this).attr('href')) { $(this).attr('target','_blank'); }
  });
}
//##############################################################################
//##############################################################################

if('#event_form'){
	$(document).ready(function() {
		$("#event_toggle").click(function () {
		  $("#online_form").toggle();
		  return false;
		});

		$().ready(function() {
			$("#event_form").validate({
				errorLabelContainer: $('#online_form_errors'),
				rules: {
					state: {
						required: true,
						minlength: 2
					},			
					zip: {
						required: true,
						minlength: 5,
						number: true
					}
				},
				
				messages: {
					name: "Please enter your name",
					address: "Please enter your address",
					city: "Please enter your city",
					state: {
						required: "Please enter your state",
						state: "Your state must be two letters"
					},
					zip: {
						required: "Please enter your zip code",
						minlength: "Your zip code must be 5 digits",
						number: "Your zip code must contain digits only"
					},
					phone: {
						required: "Please enter your phone number",
						phone: "Please enter a valid phone number."
					},				
					email: {
						required: "Please enter your email address",
						email: "Please enter a valid email address"
					},
					number_attending: "Please enter the number attending, including yourself.",
					attendee_names: "Please enter the names of those attending, including yourself."
				}

			});
		}); 
	});	
}

if('#ask_the_pro'){
	$(document).ready(function() {
		$().ready(function() {
			$("#ask_the_pro").validate();
		});
	});
}

if('#contactform'){
	$(document).ready(function() {
		$().ready(function() {
			$("#contactform").validate();
		});
	});
}
