$(function () {
    $("#dialog:ui-dialog").dialog("destroy");
    $("#dialog-modal").dialog({
        autoOpen: false,
        height: 400,
        width: 550,
        modal: true
    });

    $("#dialog-modal").dialog({
        open: function (event, ui) {
            
        }
    });

    $("[id^=infolink_]").each(function () {
        var id = $(this).attr("id").substring(9, $(this).attr("id").length);
        var hiddenInfoId = "#infohidden_" + id;
        $(this).click(function () {
            var hf_input = $(hiddenInfoId).val();
            var jsonInfo = "";
	
            if (hf_input != undefined) {
		var now = new Date();

                jsonInfo = jQuery.parseJSON(hf_input.replace(/&quot;/g, '"'));
		var b_date = jsonInfo.gebdatum.substring(0,10);
		var b_year = b_date.substring(0,4);
		var b_month = b_date.substring(5,7);
		var b_day = b_date.substring(8,10);
		
		var s_date = jsonInfo.startjaar.substring(0,10);
		var s_year = s_date.substring(0,4);
		var s_month = s_date.substring(5,7);
		var s_day = s_date.substring(8,10);

                $("#d_name").text(jsonInfo.name);
                $("#d_age").text(GetAge(b_year, b_month, b_day));
                $("#d_occupacion").text(jsonInfo.beroep);
                $("#d_startyear").text(GaatXJaarMetStib(parseInt(now.getFullYear() - s_year),jsonInfo.startjaarextrainfo));
		$("#d_startyearextrainfo").text(jsonInfo.startjaarextrainfo);
                $("#d_info").text(jsonInfo.info);
		$("#leiderImg").attr("src", jsonInfo.foto);

                //var modalTitle = "Oudste kamp " + jsonInfo.name;
                //$("#dialog-modal").attr("title", "your new title"); ;

                $("#dialog-modal").dialog("open");

            }
        });
    });

});

function GaatXJaarMetStib(ammountOfYears, extraInfo)
{
 if(parseInt(ammountOfYears) == 0)
{
return "Dit is mijn eerste jaar, "+extraInfo;
}else{
return "Ik ga al " +ammountOfYears+ " jaar mee met Stib, "+extraInfo;
}
}

function GetAge(year, month, day)
{
var bday=parseInt(day);
var bmo=parseInt((month-1));
var byr=parseInt(year);
var byr;
var age;
var now = new Date();
tday=now.getDate();
tmo=(now.getMonth());
tyr=(now.getFullYear());
{
if((tmo > bmo)||(tmo==bmo & tday>=bday))
{age=byr}

else
{age=byr+1}
return (tyr-age);
}}
