var isAnimating = false;
var map;

$(document).ready(function() {
	$('select.custom').dropdown();
	$('select.radius_dd').dropdown();
	$('select.sort_dd').dropdown({ width: 130, klass: 'sort_dd', change: function() {
		$(".available_spaces_blocks").load("http://www.hillmgt.com/ajax/property-spaces/", { property: $("#sort_dropdown").attr("name"), sort: $("#sort_dropdown").val() });
	}});
	
	$('.feature_nav li a').click(function() { 
		$("#home_features .feature_wrapper").hide();
		$(".feature_nav a").removeClass("selected");
		$(this).addClass("selected");
		$("#home_features ." + $(this).attr("href").substr(1)).show();
		Cufon.replace('.feature_nav li a');
		return false;
	});
	
	
	$('.thumbnails li').hover(function() {
		$(this).addClass('hover').find('img');
	}, function() {
		$(this).removeClass('hover').find('img');
	});
	$('.thumbnails li a').click(function(){
		$('.thumbnails li').removeClass('selected');
		$(this).parent('li').addClass('selected').find('img');
		swapPhoto($(this));
		return false;
	});
	
	$("select.topic_dd").dropdown({ change: faqChange });
	$("#ts_dd").dropdown({ change: function(ui){
		v = $("#ts_dd").val();
		if (v)
			window.location = "http://www.hillmgt.com/" + v;
	} });
	
	$('.carousel').carousel({ horizontal: false, controls: true });
	
	$('.floor_plan').lightbox();
	
	$('.scrollbar').scrollbar();
	
	//png fix
	if(typeof document.body.style.maxHeight === "undefined") { //only if ie6
        DD_belatedPNG.fix('.fix_png, a, blockquote, .image_viewer_caption');
	}
});

function faqChange(event, ui) {
	document.location.href = faq_page + "category/" + $("#faq_cat").val() + "/";
}


function swapPhoto(photo) {
	if(isAnimating == true) {
		return false;
	}
	isAnimating = true;
	
	$('.image_viewer_large').animate({opacity: 0}, function() {
		$('.image_viewer_large').html('');
		$(".image_viewer_caption").html(photo.attr("title"));
		var newImg = new Image();
		$(newImg).load(function(){
			$('.image_viewer_large').append(this);
			$('.image_viewer_large').animate({opacity: 1});
			isAnimating = false;
		}).attr('src', photo.attr("href"));
	});
}



//global map vars
var gmarkers = [];
var htmls = [];
var activeMarker;

function markerClick(index) {					
	gmarkers[index-1].openExtInfoWindow(map, "map_bubble", htmls[index-1], {beakOffset: 29});					
	activeMarker = gmarkers[index-1];
}
