$(document).ready(function(){
	

	// landing Page Properties
	// 1
	if ($('#landingPageProperties1').size()) {
		$('#landingPagePropertiesNext1').click(function(){
			var $current = ($('#landingPageProperties1 li.active'));
			var $next = $current.next();
			if (!$next.length) $next = $('#landingPageProperties1 li:first');
			
			$next.fadeIn('slow');		
			$next.addClass('active');
			$current.hide();
			$current.removeClass('active')

			$('#landingPagePropertiesCount1 .showing').html( $('#landingPageProperties1 li').index($next)+1 );
			
		});	

		$('#landingPagePropertiesPrev1').click(function(){
			var $current = ($('#landingPageProperties1 li.active'));
			var $next = $current.prev();
			if (!$next.length) $next = $('#landingPageProperties1 li:last');
			
			$next.fadeIn('slow');		
			$next.addClass('active');
			$current.hide();
			$current.removeClass('active')
			
			$('#landingPagePropertiesCount1 .showing').html( $('#landingPageProperties1 li').index($next)+1 );
			
		});	

		if ( $('#landingPageProperties1 li').size() > 1 ) {
			
			$('#landingPagePropertiesCount1 .total').html( $('#landingPageProperties1 li').size() );
			$('#landingPagePropertiesNext1').click();
			$('#landingPagePropertiesNav1').show();
		} else {
			$('#landingPagePropertiesNext1').click();
			$('#landingPagePropertiesNav1').hide();
		}
	}	

	// 2
	if ($('#landingPageProperties2').size()) {
		$('#landingPagePropertiesNext2').click(function(){
			var $current = ($('#landingPageProperties2 li.active'));
			var $next = $current.next();
			if (!$next.length) $next = $('#landingPageProperties2 li:first');
			
			$next.fadeIn('slow');		
			$next.addClass('active');
			$current.hide();
			$current.removeClass('active')

			$('#landingPagePropertiesCount2 .showing').html( $('#landingPageProperties2 li').index($next)+1 );
			
		});	

		$('#landingPagePropertiesPrev2').click(function(){
			var $current = ($('#landingPageProperties2 li.active'));
			var $next = $current.prev();
			if (!$next.length) $next = $('#landingPageProperties2 li:last');
			
			$next.fadeIn('slow');		
			$next.addClass('active');
			$current.hide();
			$current.removeClass('active')
			
			$('#landingPagePropertiesCount2 .showing').html( $('#landingPageProperties2 li').index($next)+1 );
			
		});	

		if ( $('#landingPageProperties2 li').size() > 1 ) {
			
			$('#landingPagePropertiesCount2 .total').html( $('#landingPageProperties2 li').size() );
			$('#landingPagePropertiesNext2').click();
			$('#landingPagePropertiesNav2').show();
		} else {
			$('#landingPagePropertiesNext2').click();
			$('#landingPagePropertiesNav2').hide();
		}
	}	

	// 3
	if ($('#landingPageProperties3').size()) {
		$('#landingPagePropertiesNext3').click(function(){
			var $current = ($('#landingPageProperties3 li.active'));
			var $next = $current.next();
			if (!$next.length) $next = $('#landingPageProperties3 li:first');
			
			$next.fadeIn('slow');		
			$next.addClass('active');
			$current.hide();
			$current.removeClass('active')

			$('#landingPagePropertiesCount3 .showing').html( $('#landingPageProperties3 li').index($next)+1 );
			
		});	

		$('#landingPagePropertiesPrev3').click(function(){
			var $current = ($('#landingPageProperties3 li.active'));
			var $next = $current.prev();
			if (!$next.length) $next = $('#landingPageProperties3 li:last');
			
			$next.fadeIn('slow');		
			$next.addClass('active');
			$current.hide();
			$current.removeClass('active')
			
			$('#landingPagePropertiesCount3 .showing').html( $('#landingPageProperties3 li').index($next)+3 );
			
		});	

		if ( $('#landingPageProperties3 li').size() > 1 ) {
			
			$('#landingPagePropertiesCount3 .total').html( $('#landingPageProperties3 li').size() );
			$('#landingPagePropertiesNext3').click();
			$('#landingPagePropertiesNav3').show();
		} else {
			$('#landingPagePropertiesNext3').click();
			$('#landingPagePropertiesNav3').hide();
		}
	}	
	
	// featured properties page
	if ($('.featuredPropertiesTitle').size()) {
		$('.featuredPropertiesTitle').click( function() {
			$('#' + $(this).attr('id') + "Nav").click();
		});
	}
});

function openFeaturedPropertiesSection(sWhich) {
	$('.featuredPropertiesSection').hide();
	$('#' + sWhich + "Section").show();
	if ( ! $('#' + sWhich + "Nav").parent().hasClass("open")) {
		$('#' + sWhich + "Plus").click();
	}
}
function submitRESearch() {
	var propertyType = $('#formPropertyType').val();
	if (propertyType == "") {
		alert("Please select a property type");
		$('#formPropertyType').focus();
		return false;
	} else {
		$('#RESearchForm').attr('action', '/cbmr/Search-For-' + propertyType + ".aspx");
		return true;
	}
	return false;
}

function addFormField(form, fieldName, fieldValue) {
    var inputField = document.createElement("input");
    inputField.setAttribute("name", fieldName);
    inputField.setAttribute("id", fieldName);
    inputField.setAttribute("type", "hidden");
    inputField.setAttribute("value", fieldValue);
    form.appendChild(inputField);
}
