$(document).ready(function(){
	//Initialize Google Maps
	if (GBrowserIsCompatible()) {
		showAddress();
	}
	
	
	//Cycle images
	$('#view-listing_image') 
	.cycle({ 
	    fx:     'fade', 
	    timeout: 5000, 
	    pager:  '#view-listing_image_thumbnails'
	});


	
	$('#email_listing').fancybox({
		'scrolling'		: 'no',
		'titleShow'		: false,
		'onClosed'		: function() {
		    $("#email_error").hide();
		}
	});


	$("#email_form").bind("submit", function() {
	
		if ($("#full_name").val().length < 1 || $("#from_email").val().length < 1 || $("#to_name").val().length < 1 || $("#to_email").val().length < 1) {
		    $("#email_error").show();
		    $.fancybox.resize();
		    return false;
		}
	
		$.fancybox.showActivity();
	
		$.ajax({
			type		: "POST",
			cache	: false,
			url		: "http://www.joebuggie.com/view-listing/email/id/" + listingID,
			data		: $(this).serializeArray(),
			success: function(data) {
				$.fancybox(data);
			}
		});
	
		return false;
	});




	$("a[rel=image_group]").fancybox({
		'transitionIn'		: 'fade',
		'transitionOut'		: 'fade',
		'autoScale'			: true,
		'titleShow'			: false,
		'showCloseButton'	: true,
		'showNavArrows'		: true
	});

	
	
});



function showAddress() {
var latlng = new google.maps.LatLng(lat, lng);
var marker = new GMarker(latlng,{draggable: false});
var map = new GMap2(document.getElementById("view-listing_map"));

map.setMapType(G_HYBRID_MAP);
map.setUIToDefault();
map.setCenter(latlng);
map.setZoom(14);
map.addOverlay(marker);
}


function gotoImage(id){
	$('#view-listing_image').cycle(id); 
}


