$(document).ready(function() {
	$(".colorbox").colorbox({maxWidth:"90%", maxHeight:"90%", opacity:".95", initialWidth:"100px", initialHeight:"100px" });
	$('.slideshow li').dumbCrossFade({'slideType':'fade', 'showTime':6000, 'transitionTime':1000});
	
	$("ul.sub-nav").parent().addClass("with-sub")
	$("ul.sub-nav").parent().append("<span class=\"drop-trigger\"></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)

	$("#nav-main ul li span.drop-trigger").click(function() { //When trigger is clicked...

		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.sub-nav").slideDown('fast').show(); //Drop down the subnav on click

		$(this).parent().hover(function() { 
		}, function(){
			$(this).parent().find("ul.sub-nav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
			$(this).parent().addClass("hover"); 
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
			$(this).parent().removeClass("hover"); 
	});
	
	
	$.viewMap = {
		'35-Indiv' : $([]),
		'25-SS' : $([]),
		'45-House' : $('fieldset .hidden-fields'),
		'35-SSHouse' : $('fieldset .hidden-fields')
	};
	$('#fields-membership-type').change(function() {
		// hide all
		$.each($.viewMap, function() { this.hide(500, 'swing'); });
		// show current
		$.viewMap[$(this).val()].show(500, 'swing');
	});
	
	$('#fields-phone-primary').change(function() {
		$('#fields-night_phone_a').val($('#fields-phone-primary').val().substring(0,3));
		$('#fields-night_phone_b').val($('#fields-phone-primary').val().substring(4,7));
		$('#fields-night_phone_c').val($('#fields-phone-primary').val().substring(8,12));
	});
	
});

