$(document).ready(function(){
        var loc = String(window.location);
        loc = loc.split("/");

	var urlId = 1825;

	if(loc[loc.length-2] == 8){
       		 urlId = 1265;
        }
        else if(loc[loc.length-2] == 7){
                 urlId = 1366;
        }
        else if(loc[loc.length-2] == 6){
		urlId = 1367;
	}
	else if(loc[loc.length-2] == 4){   
		urlId = 1369;
        }

	if($("#groupDetailSelect").length > 0){
         $("#groupDetailSelect").change(function(){ 
		if($(this).attr("value") != "-1"){
                	window.location = 'http://www.peer.be/nl/' + urlId + '/associations-cats/' + loc[loc.length-2] + '/' + $("#innerContentWrapper h1:eq(0)").html().toLowerCase() + ".html?id=" + $(this).attr("value");
        	} 
	});
		 
		 if($("#catsDetailSelect").length > 0){
			 
			 if($('#catsDetailSelect option:selected').length > 0 && $('#catsDetailSelect option:selected').html() != "Selecteer een categorie"){
				 openList($('#catsDetailSelect option:selected').attr('value'));
			 }

			$("#catsDetailSelect").change(function(){
					$("#description").html('');
					openList($(this).attr("value"));
			});  
		 }
	}
});  

function openList( loc ){
	var loc2 = String(window.location);
        loc2 = loc2.split("/"); 


	var urlId = 1825;

        if(loc2[loc2.length-2] == 8){
                 urlId = 1265;
        }
        else if(loc2[loc2.length-2] == 7){
                 urlId = 1366;
        }
        else if(loc2[loc2.length-2] == 6){
                urlId = 1367;
        }
        else if(loc2[loc2.length-2] == 4){
                urlId = 1369;
        }

	$.ajax({data:{id:loc},dataType:'json',type:'POST',url: '/__datasource__/associations',success: function (data){
					$("#innerContentWrapper label:eq(1)").hide();
					$("#groupDetailSelect").hide();
					var list = "<ol>";
					for(var i = 0;i<data.length;i++){
						list += '<li><a href="http://www.peer.be/nl/' + urlId + '/associations-cats/' + loc2[loc2.length-2] + '/' + $("#innerContentWrapper h1:eq(0)").html().toLowerCase() + '.html?id=' +  data[i].id + '">' + data[i].name + "</a></li>";
					}
					list += "</ol>";
					if(data.length == 0)
					{
							list += "Er is nog geen vereniging voor deze categorie.";
					}
					$("#description").html(list);
			}
	});  
}  

function setIcon(latitude,longitude,map) {
        var coordinates = new google.maps.LatLng(latitude,longitude);
        var marker = new google.maps.Marker({
                map: map,
                position: coordinates
        });
        map.setCenter(new GLatLn(latitude, longitude),12);
}

