﻿function NieuwsBericht(item) {

    this.type = item.type;
    this.titel = "";
    this.bericht = "";
    this.foto = "";
    this.video = "";
    this.dag = "";
    this.maand = "";
    this.link = "";

    //DAG & MAAND AANMAKEN
    var datum = item.created_time.split("T");
    var dagsplit = datum[0].split("-");
    this.dag = dagsplit[2];
    switch (dagsplit[1]) {
        case "01":
            this.maand = "Jan";
            break;
        case "02":
            this.maand = "Feb";
            break;
        case "03":
            this.maand = "Maa";
            break;
        case "04":
            this.maand = "Apr";
            break;
        case "05":
            this.maand = "Mei";
            break;
        case "06":
            this.maand = "Jun";
            break;
        case "07":
            this.maand = "Jul";
            break;
        case "08":
            this.maand = "Aug";
            break;
        case "09":
            this.maand = "Sep";
            break;
        case "10":
            this.maand = "Okt";
            break;
        case "11":
            this.maand = "Nov";
            break;
        case "12":
            this.maand = "Dec";
            break;
            }

    //CONTROLE VAN BERICHTTYPE & naar gelang het type : aanpassen!
    if (this.type == "photo") {
        this.titel = "Nieuwe foto's online";
        this.foto = item.picture;
        this.link = item.link;
    } else if (this.type == "video") {
        this.titel = "Nieuwe video's online";
        this.foto = item.picture;
        this.link = item.source;
    } else if (this.type == "status") {
        this.titel = "Nieuwe update";
    } else if (this.type == "link") {
        this.titel = "Een link werd gepost";
        this.link = item.link;
        this.name = item.name;
    }

    //CONTROLE VAN MESSAGE
    if (item.message != undefined) {
        this.bericht = item.message;
    } else {
		this.bericht = "Foto/video/link zonder bijschrift";
	}

    this.geefBerichtDiv = function () {
        var string = '<div class="nieuwsbericht"><div class="berichtHeader">';
        //Datum toevoegen aan de DIV
        string += '<div class="datum"><p>' + this.dag + "</p><strong>" + this.maand + "</strong></div>";
        //Titel toevoegen aan de DIV
        string += '<div class="titel">' + this.titel + "</div></div>";
        //Body toevoegen
        if (this.type == "photo" || this.type == "video") {
			if(this.foto == undefined){
				string += '<div class="bericht"><a href="' + this.link + '">' + this.link + '</a><p class:"link">'+ this.bericht +'</p></div></div>';
			} else {
				string += '<div class="bericht"><a href="' + this.link + '"><img src="' + this.foto + '"/></a><p class="foto">' + this.bericht + '</p></div></div>';
			}
            
        } else if (this.type == "status") {
            string += '<div class="bericht"><p class="status">' + this.bericht + '</p></div></div>';
        } else if (this.type == "link") {
            string += '<div class="bericht"><a href="' + this.link + '">' + this.name + '</a><p class:"link">'+ this.bericht +'</p></div></div>';
        }
        return string;
    }
}
