(function($){ 
	$(function(){
		if( $('#home-testimonials').length ) {
			setInterval(function() {
				var active = $('#home-testimonials .active');
				var next = active.next();
				
				if( next.length == 0 )
					next = $('#home-testimonials .testimonial').eq(0);
				
				active.removeClass('active').stop(true,true).fadeOut(500);
				next.addClass('active').stop(true,true).fadeIn(500);
				
			}, 4000);
		}
		
		$('#home-properties-holder .property_div:first-child').show().addClass('active');
		var numprop = $('#home-properties-holder .property_div').length;
		if(numprop) {
			for( i=1; i <= numprop; i++){
				$('#fpagination').append('<a href="#" rel="'+ (i-1) +'">'+i+'</a>');
				$('#fpagination a:first-child').addClass('active');
			}
			setInterval(function() {
				var ac = $('#home-properties-holder .property_div.active');
				var current = $('#home-properties-holder .property_div').index(ac);
				var target = current+1;
				if(target == numprop) {
					target = 0;
				}
				changeprop(target);
			}, 8000);
			$('#fpagination a').click(function(e) {
				changeprop($(this).attr('rel'));
				e.preventDefault();
			});
		}
		
		function changeprop(target) {
			$('#home-properties-holder .property_div.active').stop(true,true).fadeOut(600).removeClass('active');
			$('#home-properties-holder .property_div').eq(target).stop(true,true).fadeIn(600).addClass('active');
			
			$('#fpagination a.active').removeClass('active');
			$('#fpagination a').eq(target).addClass('active');
		}
	
	});
})(jQuery);

