// JavaScript Document
$(window).load(function(){			
	var hoverConfig = {
		over: stateIn, // function = onMouseOver callback (REQUIRED)    
	 	sensitivity: 1, // number = sensitivity threshold (must be 1 or higher) 
    out: stateOut // function = onMouseOut callback (REQUIRED)    
	};
	
	$('#mapArea img').animate({opacity:0},1, function(){
		$('#mapArea img').show();																									
	});
	
	$('#mapArea img').hoverIntent(hoverConfig)
	
	$('#mapArea img').click(function(){
		id = $(this).attr('title');
		window.location.href = '/properties/'+id;		
	});
	
	function stateIn(){
		$('#stateText').html($(this).attr('title'));
		$(this).animate({opacity:1},400);
	}
	
	function stateOut(){
		$('#stateText').html('');
		$(this).animate({opacity:0},100);
	}
	
	
	
	// Homepage banner slide and control buttons
	// 23/01/11 by Steven Thompson
	
	$('#bgs li').not(':first').animate({opacity:0},1, function(){
		$('#bgs li').not(':first').show();
	});
	setTimeout("bannerAnimation();",5000);
	$('#buttons li').click(function(){
		if(timer){
			clearTimeout(timer);
		}
		bannerAnimation($(this).index());						
	});
});

function bannerAnimation(selectedIndex){
	var currentIndex = $('#bgs li.on').index()+1;
	var nextSlide = $('#bgs li.on').next();
	var currentZIndex = $('#bgs li.on').css('z-index');
	if(nextSlide.length <= 0){
		nextSlide = $('#bgs li:first').css('z-index', 3);
	} else {
		$('#bgs li:first').css('z-index', 2);
	}
	if(selectedIndex >= 0){ // Manual slide
		nextSlide = $('#bgs li:eq('+selectedIndex+')');
		$('#buttons li.on').removeClass('on');
		$(this).addClass('on');
	} 
	nextSlide.css('z-index',3);	
	// Auto slide
	nextSlide.animate({
		opacity:1
	}
	,{
		duration: 2000, 
		complete: function(){
			$('#bgs li.on').removeClass('on').animate({opacity:0},500);
			nextSlide.addClass('on');
			$('#buttons li.on').removeClass('on').css('z-index', 2);
			$('#buttons li:eq('+$('#bgs li.on').index()+')').addClass('on');
			if(selectedIndex >= 0){
				
			} else {
				timer = window.setTimeout("bannerAnimation(-1);",5000);
			}
		}
	});
}
