// JavaScript Document



$(document).ready(function() {

	//last-child resets

	$('p:last-child').css('margin', '0');

	$('#footer-nav li:last-child').css('border-right', 'none');
	
	//sneak in clearfix on IDX pages
	$('#IDX-searchPageWrapper, #IDX-searchForm').addClass('clearfix');
	
	//Add Text to property type dropdown
	$('#propTypeSelect').before('<span class="propTypeSelectDesc">Choose Your Property Type</span>');
	
	//$('#IDX-maxPriceLabelQS').text('Max Price');
	
	//#('#IDX-showcaseWrapper').css('width','9999px');
	
	$('.IDX-showcaseRemarks').each(function(){
		$(this).after('<p style="font-size: 10px; color: #d9002a;">Click Image To View Property</p>');
	});
	
	
	
	
	//featured listing rotator
	$('#IDX-showcaseWrapper tr:first-child').clone().appendTo('#IDX-showcaseWrapper tbody');
	

	function featuredListingAnimation(){
				
		var featPause = 5000;
		var featAnimation = 800;
		
		//var movesNumber = $('#IDX-showcaseWrapper tr').size() - 2;
//		var moveAnimation = $(this).animate({top: '-=272px' }, featAnimation).animate({top: '-=0px' }, featPause);
//		var moveRepeat = moveAnimation * movesNumber
//		console.log(moveRepeat);
		
		
		$('#IDX-showcaseWrapper')
			.animate({top: '0' }, featPause)
			.animate({top: '-=272px' }, featAnimation).animate({top: '-=0px' }, featPause)
			.animate({top: '-=272px' }, featAnimation).animate({top: '-=0px' }, featPause)
			.animate({top: '-=272px' }, featAnimation).animate({top: '-=0px' }, featPause)
			.animate({top: '-=272px' }, featAnimation).animate({top: '-=0px' }, featPause)
			.animate({top: '-=272px' }, featAnimation).animate({top: '-=0px' }, featPause)
			.animate({top: '-=272px' }, featAnimation).animate({top: '-=0px' }, featPause)
			.animate({top: '-=272px' }, featAnimation).animate({top: '-=0px' }, featPause)
			.animate({top: '-=272px'}, featAnimation).animate({top: '0px' }, 0, function(){
				setTimeout(featuredListingAnimation, 0);
			});
	}
	
	featuredListingAnimation();	

	
	
	
	//fixed contact sidebar
	
  var contactSideBarWrapperHt = $('#content').height() + 'px';
  $('#contactsidebar-wrapper').css('height', contactSideBarWrapperHt);
  

	  var msie6 = $.browser == 'msie' && $.browser.version < 7;
	  var windowHeight = $(window).height() > $('#contactsidebar').outerHeight(); 
	  if (!msie6 && windowHeight) {
		var top = $('#contactsidebar').offset().top - 10;
			 //- parseFloat($('#contactsidebar').css('margin-top').replace(/auto/, 0);
		$(window).scroll(function (event) {
		  // what the y position of the scroll is
		  var y = $(this).scrollTop();
		  
		  // whether that's below the form
		  if (y >= top) {
			// if so, ad the fixed class
			$('#contactsidebar').addClass('fixed');
		  } else {
			// otherwise remove it
			$('#contactsidebar').removeClass('fixed');
		  }
		});

		var bottom = $('body').height() - $('#contactsidebar').outerHeight() - $('#footer').outerHeight();
		$(window).scroll(function (event) {
		  // what the y position of the scroll is
		  var z = $(this).scrollTop();
			  
		  // whether that's below the form
		 if (z >= bottom) {
			// if so, ad the fixed class
			$('#contactsidebar').removeClass('fixed').addClass('fixedbottom');
		  } else {
			// otherwise remove it
			$('#contactsidebar').removeClass('fixedbottom');
		  }
		});
	  }

  

  
});	
