jQuery(window).load(function(){
	$('#loader').fadeOut(300, function() {
		$('#loader').remove();
    });
});

function setColor (control, color) {
	if (control.style) {
		if (control.value != control.defaultValue) {
			control.style.color = color;
		}
		else {
			control.style.color = '';
		}
	}
}

$(document).ready(function() {
	
	var v = jQuery("#c_form").validate({
		submitHandler: function(form) {
			jQuery(form).ajaxSubmit({
				success: function() {
					$("#contact_form_success").removeClass("inactive");
					$("#contact_form").addClass("inactive");
					$('#contact_form').fadeOut(500);
					$('#contact_form_success').delay(500).fadeIn('slow');
				} 
			});
		}
	});
	
	var vc = jQuery("#o_form").validate({
		submitHandler: function(form) {
			jQuery(form).ajaxSubmit({
				success: function() {
					$("#contact_form_success").removeClass("inactive");
					$("#opt_in").addClass("inactive");
					$('#opt_in').fadeOut(500);
					$('#contact_form_success').delay(500).fadeIn('slow');
				} 
			});
		}
	});
	
	// keep background slideshow fullscreen during window resizes
	$(window).resize(function() {
		var h = $(document).height();
		$("html").height(h);
		$("#background_slideshow").height(h);
	});
	
	// keep background slideshow fullscreen during window scrolling
	$(window).scroll(function() {
		var h = $(document).height();
		$("html").height(h);
		$("#background_slideshow").height(h);
	});

	
	// hide inactive divs
	$("#contact_form_success").hide();
	$(".inactive").hide();
	$(".map_inactive").hide();
	
	$('#background_slideshow').cycle({
		fx:			'fade',
		timeout:	10000
	});
	
	$("input[name='contact_type']").imageTick({ // the selector can be a class as well
		tick_image_path: "img/radio_selected.png", 
		no_tick_image_path: "img/radio.png",
		image_tick_class: "radios"
	});

	$('#nav_home').data('target', '#opt_in');
	$('#nav_contact').data('target', '#contact_form');
	$('#nav_map').data('target', '#map');
	
	
	$('#nav_home,#nav_contact,#nav_map').click(function() {
		var selector = $(this).data('target');
		$(".contentdiv").addClass("inactive");
		$(selector).removeClass("inactive");
		$(".inactive").fadeOut(500, function() {
			$("html").height("100%");
			$("#background_slideshow").height("100%");
	    });

		$(selector).delay(500).fadeIn(500, function() {
			var h = $(document).height();
			$("html").height(h);
			$("#background_slideshow").height(h);
	    });
	});
	
	$('#nav_map').click(function() {
		var selector = $(this).data('target');
		$(".contentdiv").addClass("inactive");
		$(selector).removeClass("inactive");
		$(".inactive").fadeOut(500, function() {
			$("html").height("100%");
			$("#background_slideshow").height("100%");
	    });
		
		$(selector).delay(500).fadeIn(500, function() {
			var h = $(document).height();
			$("html").height(h);
			$("#background_slideshow").height(h);
	    });
	    
	    $('#map_nav').show();
	});
			
	$('#evt').data('target', '#evt_pop');
	$('#elt').data('target', '#elt_pop');
	$('#nct').data('target', '#nct_pop');
	$('#norcal').data('target', '#norcal_pop');
	$('#az').data('target', '#az_pop');
	
	$('#evt,#nct,#elt,#norcal,#az').mouseover(function() {
		var selector = $(this).data('target');
		$(".map_contentdiv").addClass("map_inactive");
		$(selector).removeClass("map_inactive");
		$(".map_inactive").stop(true, true).fadeOut(500);
		$(selector).stop(true, true).fadeIn(500);
	});
	
	$('#evt,#nct,#elt,#norcal,#az').mouseout(function() {
		var selector = $(this).data('target');
		$(".map_contentdiv").addClass("map_inactive");
		$(selector).removeClass("map_inactive");
		$(".map_inactive").stop(true, true).fadeOut(200);
		$(selector).stop(true, true).fadeOut(200);
	});
	
});
