addEvent(window, 'load', generalSetup);
			
function generalSetup(){
	new google.translate.TranslateElement({pageLanguage: 'en'}, 'google_translate_element');
}

function searchBanners(){
	//setup rental/sale banner links
	$('#saleslink, #rentallink').attr('href', '#search').bind('click', function(){
		$('#salesbanner, #rentalbanner').toggle();
	});
}

function propertyBrowse(){
	//remove order by button
	$('#orderby-button').hide();
	
	$('#order').bind('change', function(){
		$('#orderby-form').submit();
	});	
}

function propertySetup(lat, lon, acc){
	//show the print button
	$('.print').removeClass('hidden');
	$('.printlink').bind('click', function(){
		window.print();
	});
		
	//setup the correct links for the thumbnails
	$('.thumbs').each(function(i){
		this.href = '#viewthumb';	
	}).bind('click', function(e){
		var data = this.id.substr(6).split('_');
		$('#mainimage').attr('src', '/includes/properties/'+data[0]+'/'+data[1]+'_l.jpg');		
		$('#mainimagelink').attr('href', '/properties/viewimage/'+data[1]+'/');
		enableLightbox();
	});
	
	enableLightbox();
	
	setupMap(lat, lon, acc);
}

function enableLightbox(){
	$('#mainimagelink').attr('href', '/includes/properties/'+$('#mainimage').attr('src').substr(21).split('_')[0]+'.jpg').attr('title', '');
	$('#mainimagelink').lightBox({imageLoading: '/includes/images/lightbox/loader.gif',imageBtnClose: '/includes/images/lightbox/lightbox-btn-close.gif',imageBtnPrev: '/includes/images/lightbox/lightbox-btn-prev.gif',imageBtnNext: '/includes/images/lightbox/lightbox-btn-next.gif'});
}

function setupMap(lat, lon, acc){
	if (GBrowserIsCompatible()) {
		if(lat && lon){
			
			var map = new GMap2(document.getElementById("map"));
			map.setCenter(new GLatLng(lat, lon), 14);

			if(acc>5){
				map.addOverlay(new GMarker(new GLatLng(lat, lon)));
				map.setCenter(new GLatLng(lat, lon), 15);
			}
			map.setUIToDefault();
		}
	}
}
