$(document).ready( function(){
	// Execute functions that were added from within the template (sometimes we just need to)
	if ( typeof(onLoadFunctions) != 'undefined' && onLoadFunctions.length){
		for (var i=0; i< onLoadFunctions.length; i++){
			onLoadFunctions[i]();	
		}
	}
});

var link;
function initiate_geolocation(supertypeId) {
    link = supertypeId;
    navigator.geolocation.getCurrentPosition(handle_geolocation_query,handle_errors);
}

function handle_errors(error)
{
    switch(error.code)
    {
        case error.PERMISSION_DENIED: alert("user did not share geolocation data");
        break;

        case error.POSITION_UNAVAILABLE: alert("could not detect current position");
        break;

        case error.TIMEOUT: alert("retrieving position timed out");
        break;

        default: alert("unknown error");
        break;
    }
}

function handle_geolocation_query(position){
    window.location.href = '?view=type&id=-1&supertypeId='+link+'&lat='+position.coords.latitude+'&lng='+position.coords.longitude;
}

