// jQuery(document).ready(function() {

//	jQuery('#cycle').cycle({
//		fx: 'fade'
//	});

//	jQuery('figure.gallery-item a').attr('rel','gallery');
//	jQuery('figure.gallery-item a[rel="gallery"]').fancybox();

// });

$(document).ready(function(){
	
	$('header').click(function(){
		window.location = '/';
	});
	
	$('#quoteFormContainer').overlay({ mask: '#303030', top: '5%' });
	
	var oAPI = $('#quoteFormContainer').data('overlay');
	
	$('.quoteType').click(function(){
		if ($(this).hasClass('getTypeFromPrevious')) {
			var clickedType = $(this).parent().prev('p').children('.quoteType').html();
		} else if ($(this).is('nav li')) { // if this is a menu item, get the type from the child link
			var clickedType = $(this).children('a').html();
		} else {
			var clickedType = $(this).html();
		}
		
		$('form#quoteForm option').each(function(){
			var type = $(this).val();
			if (type == clickedType) {
				$(this).attr('selected', 'selected');
				changeFormType(type);
			}
		});
		
		oAPI.load();
		
		return false;
	});
	
	$('h3.quoteType').hover(
		function(){
			$(this).addClass('active');
		},
		function(){
			$(this).removeClass('active');
		}
	);
	
	$('#insurance_type').change(function(){
		var type = $(this).find("option:selected").val();
		changeFormType(type);
	});
	
	function changeFormType(type) { // show appropriate fields for selected type of insurance
		if ($('#insurance_type').find('option:selected').val() == 'Group Insurance') {
			$('div.group').show();
			$('div.individual').hide();
		} else {
			$('div.individual').show();
			$('div.group').hide();
		}
		
		if ($("#insurance_type").find('option:selected').val() == 'Life and Retirement') {
			$('div.life').show();
		} else {
			$('div.life').hide();
		}
		
		if ($("#insurance_type").find('option:selected').val() == 'Property and Casualty / Commercial Insurance') {
			$('div.property').show();
		} else {
			$('div.property').hide();
		}
	}
	
	$('#quoteForm').validate();
});

