function runOnLoad(f) {
    if (runOnLoad.loaded) f();    // If already loaded, just invoke f() now.
    else runOnLoad.funcs.push(f); // Otherwise, store it for later
}

runOnLoad.funcs = []; // The array of functions to call when the document loads
runOnLoad.loaded = false; // The functions have not been run yet.

// Run all registered functions in the order in which they were registered.
// It is safe to call runOnLoad.run() more than once: invocations after the
// first do nothing. It is safe for an initialization function to call
// runOnLoad() to register another function.
runOnLoad.run = function() {
    if (runOnLoad.loaded) return;  // If we've already run, do nothing

    for(var i = 0; i < runOnLoad.funcs.length; i++) {
        try { runOnLoad.funcs[i](); }
        catch(e) { /* An exception in one function shouldn't stop the rest */ }
    }
    
    runOnLoad.loaded = true; // Remember that we've already run once.
    delete runOnLoad.funcs;  // But don't remember the functions themselves.
    delete runOnLoad.run;    // And forget about this function too!
};

// Register runOnLoad.run() as the onload event handler for the window
if (window.addEventListener)
    window.addEventListener("load", runOnLoad.run, false);
else if (window.attachEvent) window.attachEvent("onload", runOnLoad.run);
else window.onload = runOnLoad.run;


var m_Map;
$(document).ready(function(){
	init_map();
	init_sidebar_contact();
	runOnLoad(init_viewer_photo);
});

//init_viewer_photo();

function init_viewer_photo(){
	$('div.slideviewer').slideView({
		height:198
	})
}

function init_sidebar_contact(){
	// gestion des lien plus/moins d'info
	$('.moins').hide();//initialisation
	$('.remarques_full').hide();//initialisation
	$('.box_courriel').hide();
	$('.show').slideToggle("slow");
	
	$('.plus').click(function(){//plus d'info
		$(this).hide();
		$('.moins').show();
		
		$('.remarques_preview').hide();
		$('.remarques_full').show();
		//$('.result-desc .hide').slideToggle("slow");
		
		return false;
	})
	$('.moins').click(function(){//moins d'info
		$(this).hide();
		$('.plus').show();
		
		
		$('.remarques_full').hide();
		$('.remarques_preview').show();
		//$('.result-desc .hide').slideToggle("slow");
		
		return false;
	})
	$('.courriel').click(function(){
		$('.box_courriel').slideToggle("slow");
		return false;
	});
}

function init_map(){
	longitude = $('#myLongitude').attr('rel');
	latitude  = $('#myLatitude').attr('rel');
	
	if(!GBrowserIsCompatible){
		return;
	}
	
	//load la mini map
	m_Map = new GMap2(document.getElementById('map'));
	m_Map.addControl(new GMapTypeControl());
	m_Map.addControl(new GSmallMapControl());
	
	//positionne la map sur l'habitation  
	m_Map.setCenter(new GLatLng(longitude, latitude), 15);
	m_Map.continuousZoomEnabled()
	
	var point = new GLatLng(longitude,latitude);
  	m_Map.addOverlay(new GMarker(point));
}
