$(document).ready(function(){
    
	//If the container exists
	if($(".teaser").length){
		//Loop through each image, including the index of the object(i)
		$(".teaser").each(function(i){
			//Since 0 based add one, for every 3rd object remainder will equal 0
			var remainder = (i) % 3;
			//Add a class of last when the remainder is 0
			if(remainder === 0){
				$(this).addClass("clear");
			}
		});
	}
	
	$('#Quick_Jump').change(function(){
		location.href = $(this).val();
	})
	
	//Close button:
	$(".close").click(
		function () {
			$(this).parent().fadeTo(400, 0, function () { // Links with the class "close" will close parent
				$(this).slideUp(600);
			});
			return false;
		}
	);
	
	//show the required dropdowns on listing form
	$('#ListingCategoryId').change(function(){
		$('#listing-details').attr('class', 'category-' + $(this).val());
	})
	
	//copy details over from previous listing
	$('#copy_details').click(
		function(){
		   	$('#ListingName').val($('#listingNameVal').text());
			$('#ListingAddress1').val($('#listingAddress1Val').text());
			$('#ListingAddress2').val($('#listingAddress2Val').text());
			$('#ListingAddress3').val($('#listingAddress3Val').text());
			$('#ListingPostcode').val($('#listingPostcodeVal').text());
			$('#ListingLandline').val( $('#listingLandline').text());
		  	$('#ListingMobile1').val( $('#listingMobile1Val').text());
			$('#ListingMobile2').val($('#listingMobile2Val').text());
			$('#ListingFax').val($('#listingFaxVal').text());
		    $('#ListingEmail').val($('#listingEmailVal').text());
			$('#ListingWebsite').val($('#listingWebsiteVal').text());
		   	$('#ListingContactName1').val($('#listingContactName1Val').text());
			$('#ListingContactName2').val($('#listingContactName2Val').text());
			$('#ListingDescription').val($('#listing-description').text());
			
		} 
	)
	
	$('#bottom-ads').cycle({timeout:  11000});
	$('#header-ads').cycle({timeout:  11000});
	$('#sidebar-ads').cycle({timeout:  11000});
	
	//scrolling to top button
	$('#backtotop').click(function(){
		$.scrollTo( '#container', 800 );
	});
	
	//the navigation fade effect
	//display the hover div
	/*
	var hoverColour = "#E6E6E6";
	
	$("#top-navigation ul li").show("fast", function() {
		//append the background div
		$(this).append("<div></div>");
		//on link hover
		$(this).children("a").hover(function(){
			//store initial link colour
			if ($(this).attr("rel") == "") {
				$(this).attr("rel", $(this).css("color"));
			}
			//fade in the background
			$(this).parent().children("div")
				.stop()
				.css({"display": "none", "opacity": "1"})
				.fadeIn("fast");
			//fade the colour
			$(this)	.stop()
				.css({"color": $(this).attr("rel")})
				.animate({"color": hoverColour}, 350);
		},function(){
			//fade out the background
			$(this).parent().children("div")
				.stop()
				.fadeOut("slow");
			//fade the colour
			$(this)	.stop()
				.animate({"color": $(this).attr("rel")}, 250);
		});
	});	
	*/
	
});
  
  
  
