$(document).ready(function(){
	$('#primaryNav').find("a[href$='"+window.location.href.split('/').pop()+"']").addClass("selected");
	
	
	setTimeout(function(){
		$('#retailNav').bind({
			mouseenter: function() {
				$('#retailFull:not(:animated)').fadeIn('slow');
				$('#residentialNav:not(:animated)').fadeOut('slow');
			},
			mouseleave: function() {
				$('#retailFull').fadeOut('slow');
				$('#residentialNav').fadeIn('slow');
			}
		});
		$('#residentialNav').bind({
			mouseenter: function() {
				$('#retailHalf:not(:animated)').fadeOut('slow');
				$('#retailNav:not(:animated)').fadeOut('slow');
				$('#residentialFull p').html('Click to enter residential');
			},
			mouseleave: function() {
				$('#retailHalf').fadeIn('slow');
				$('#retailNav').fadeIn('slow');
				$('#residentialFull p').html('Residential');
			}
		});
	},1000);
	
	$('#locationSwitch').toggle(function() {
			$('#locationMap:not(:animated)').fadeOut('slow');
			$('#locationDescription:not(:animated)').fadeOut('slow');
			$('#locationSwitch').html('Click to view illustrated map');
			$('#parkwayMarker:not(:animated)').fadeIn('slow').delay(2000).fadeOut(2000);	
		}, function() {
			$('#parkwayMarker:not(:animated)').hide();
			$('#locationMap:not(:animated)').fadeIn('slow');
			$('#locationDescription:not(:animated)').fadeIn('slow');
			$('#locationSwitch').html('Click to view Google map');
	});
	
	$("#visionpanes").scrollable({ circular: true, mousewheel: true }).navigator({
		navi: "#visiontabs",
		naviItem: 'a',
		activeClass: 'current',
		history: true
	});
	
	$(".gallerynav").scrollable();
	$(".galleryitems a").click(function(e) {
	 	e.preventDefault();
		if ($(this).hasClass("active")) { return; }
		var url = $(this).attr("href");
		var wrap = $(".gallerypanes").fadeTo("fast", 0.5);
		var img = new Image();
		img.onload = function() {
			wrap.fadeTo("medium", 1);
			wrap.find("img").attr("src", url);
		};
		img.src = url;
		$(".galleryitems a").removeClass("active");
		$(this).addClass("active");
	}).filter(":first").click();
	
	$(".pdf").tooltip({ 
		effect: 'slide',
		position: 'top left',
		relative: 'true',
		opacity: 0.8
	});
	
	$("#partnerLogos a").tooltip({ 
		effect: 'slide',
		offset: [-110, 0],
		relative: 'true',
		opacity: 1
	});
	
	$("#ajax-contact-form").submit(function() {
        $('#load').append('<center><img src="../images/ajax-loader.gif" alt="Currently Loading" id="loading" /></center>');

        var fem = $(this).serialize(),
			note = $('#note');
	
        $.ajax({
            type: "POST",
            url: "../retail/contact.php",
            data: fem,
            success: function(msg) {
				if ( note.height() ) {			
					note.slideUp(1000, function() { $(this).hide(); });
				} 
				else note.hide();

				$('#loading').fadeOut(300, function() {
					$(this).remove();

					// Message Sent? Show the 'Thank You' message and hide the form
					result = (msg === 'OK') ? '<div class="success">Your message has been sent. Thank you!</div>' : msg;

					var i = setInterval(function() {
						if ( !note.is(':visible') ) {
							note.html(result).slideDown(1000);
							clearInterval(i);
						}
					}, 40);    
				}); // end loading image fadeOut
            }
        });

        return false;
    });
    
	if ($(".simple_overlay").length > 0) {
		function beforeLoad(evt, callback) {
			var id = $(this.getTrigger()).attr("data-id");
			$.get("overlay.html", {apt:id}, function(response) {
				$(".simple_overlay div").html(response);
			});
			
			if (callback)
				callback();
		};
		
	    $('a.flatTrigger[rel].available, a.flatTrigger[rel].offer')
			.overlay({
				fixed: false,
		    	mask: '#4891dc',
				onBeforeLoad: beforeLoad,
				onLoad: function(evt) {
					$(".summary-bar").css("background", "transparent");
				}
		    });
	}
	
	if ($('.retailItems').quovolver && $('.retailItems').length > 0)
		$('.retailItems').quovolver();
});
