
 // ----------------------------------------------------------------------------------------------------------------
 // Globale Variablen
 // ----------------------------------------------------------------------------------------------------------------
 
    var ls_DEBUG = "an";
    var ls_DIV =   "lifestream";
    var ls_MENU =  "menuLifestream";
    
 // ----------------------------------------------------------------------------------------------------------------
 // Document Ready
 // ----------------------------------------------------------------------------------------------------------------
 
    $(document).ready(function()
    {
    // Lifestream laden
       lifstreamLaden(ls_DIV,ls_MENU);
    
    // Yahoo-Link aktualisieren
       lifstreamYahoo(ls_MENU);
    
    // Document Ready Ende
    });

 // ----------------------------------------------------------------------------------------------------------------
 // Lifestream laden
 // ----------------------------------------------------------------------------------------------------------------
    
    function lifstreamLaden(div,menu)
    {
    // Content resetten
       var content = "";
       
    // Pipe-Variable einlesen
       var pipe = $("#"+menu).attr("pipe");
       
    // Parameter einlesen
       var params = $("#"+menu).attr("params");
    // var seiten = $(".seiten");
    // $.each(seiten, function() { var params = params+""; });
  
    // Zufallszahl für Ajax-Request
       var random = Math.random();
       var random = random * 100;
 
    // JSON-Request
       $.getJSON("webservice/pipes.php?pipe="+pipe+"&params="+params+"&random="+random,function(json)
       {
          if(json.count > 0)
          {
          // Item-Feed rendern
             content = output_feed_items(json);
       
          // Posts-Frontend laden
             $.include("http://blog.sefzig.net/javascript-in-posts.js");

          // Regex for YouTube-videos: Onclick nachträglich setzen
             youtubeRegexReady("lifstreamLaden()");
          }
          else
          {
          // Fehlermeldung
             content = "Fehler beim Laden der Feeds.";
          }
          
       // Antwort einsetzen
          $("#"+div).html(content);
          
       // Anzuzeigende Inhalte einlesen
          var anzeige = $("#"+menu).attr("anzeige");
       
       // Anzuzeigende Inhalte anzeigen
          $(anzeige).css("display","block");
       });
    }
       
 // ----------------------------------------------------------------------------------------------------------------
 // Titel rendern und Items im Loop ausgeben
 // ----------------------------------------------------------------------------------------------------------------
 
    var itemList = "";
       
    function output_feed_items(json)
    {
    // Menu-Liste leeren
       $("#ytVideosMenu").empty();
             
    // Item und Item-Details rendern lassen
       for (k=0;k<json.count;k++)
       {
          itemList += make_feed_item(json.value.items[k], k);
       }
    
    // Header und Item-Liste ausgeben
       return itemList;
    }

 // ----------------------------------------------------------------------------------------------------------------
 // Item rendern
 // ----------------------------------------------------------------------------------------------------------------
 
    function make_feed_item(item, item_id)
    {
    // Daten zweistellig machen
       if (item.monat   < 10) { item.monat   = "0"+item.monat;   }
       if (item.tag     < 10) { item.tag     = "0"+item.tag;     }
       if (item.stunde  < 10) { item.stunde  = "0"+item.stunde;  }
       if (item.minute  < 10) { item.minute  = "0"+item.minute;  }
       if (item.sekunde < 10) { item.sekunde = "0"+item.sekunde; }
    
    // Datum zusammensetzen
       var zeitDatum =   item.tag + '.' + item.monat + '.' + item.jahr;
       var zeitUhrzeit = item.stunde + ':' + item.minute;
    // var zeitString =  zeitDatum;
       var zeitString =  zeitDatum + ' um ' + zeitUhrzeit;
       
    // ISO8601: 2008-01-28T20:24:17Z
       var zeitPretty = item.jahr+"-"+item.monat+"-"+item.tag+"T"+item.stunde+":"+item.minute+":"+item.sekunde+"Z";

    // Helper: prettyDate('2008-01-28T20:24:17Z')
       var zeitPretty = prettyDate(zeitPretty);

    // Quelle zur Fallunterscheidung
       var projekt = item.projekt;

    // alert(' onmouseover="hover_feed_item(' + "'lifeitem" + item_id + "','an'" + ');" onmouseout="hover_feed_item(' + "'lifeitem" + item_id + "','aus'" + ');"');
    
    // Spezial: Mister Wong
       if (projekt == "misterwong")
       {
       // HTML vorbereiten
          misterwongTags = "";
          
       // Tags-Array anlegen
          var misterwongTagsArray = item.tags.split(' '); 
          
       // Array alphabetisch sortieren
          var misterwongTagsArray = misterwongTagsArray.sort();
          
       // Menge der Tags
          var misterwongNum =  misterwongTagsArray.length - 1;

       // Array anlegen
          for (var i = 0; i <= misterwongNum; i++)
          {             
          // Inhalte-Array in Inhalte splitten
             var misterwongTag = misterwongTagsArray[i];
             
          // HTML ergänzen
             misterwongTags = misterwongTags+', <a href="http://www.misterwong.de/user/sefzig/' + misterwongTag + '/" target="_blank">' + misterwongTag + '</a>';
          }
          
       // Erstes ', ' entfernen
          var misterwongTags = misterwongTags.replace(", ", "");

       // Thumbnail-HTML
          var misterwongThumbnail = '<img src="http://www.iwebtool2.com/img/?r=http://lifestream.sefzig.net&domain=' + item.link + '" width="202" height="152" border="0" /><br /><br />';
       }

    // Spezial: Sefzig.net geöffnet zeigen
       if (projekt == "blogsefzignet")
       {
       // HTML vorbereiten
          var item_display = ' style="display: block"';
       }
       else
       {
       // Variable leer setzen
          var item_display = "";
       }

    // Spezial: Meine Artikel in Trendwork öffnen
       if (projekt == "trendwork")
       {
       // Spezial: Meine Artikel in Trendwork öffnen
          if (item.autor == "Andreas Sefzig")
          {
          // HTML vorbereiten
             var item_display = ' style="display: block"';
          }
       }

    // Spezial: Youtube
       if (projekt == "youtubeFavoriten")
       {
       // Youtube-ID ermitteln
          var ytId1 = item.link;
          var ytId2 = ytId1.split("=");
          var ytId3 = ytId2[1];
          var ytId4 = ytId3.split("&");
          var ytId =  ytId4[0];
       
       // Titel säubern
          item.titel = item.titel.replace(/\"/g, "");
          item.titel = item.titel.replace(/\'/g, "");
          
          var titelKurz = item.titel;
          var titelKurz = titelKurz.replace(/\s\(.*?\)/g, "")
          var titelKurz = titelKurz.replace(/\s\[.*?\]/g, "")
          var titelKurz = titelKurz.replace(/\(.*?\)\s/g, "")
          var titelKurz = titelKurz.replace(/\[.*?\]\s/g, "")
          
       // Erster-Attribut lesen
          var zahler = $("#ytLayer").attr("zahler");
          var zahler = parseInt(zahler);
          
       // Stringlängen-Attribut für Menü lesen
          var lange = $("#ytVideosMenu").attr("lange");
          var lange = parseInt(lange);
          
       // Zeilenumbruch setzen
          if ((zahler) && (zahler != ""))
          {
             var linebreak = "<br />";
             
             var zahler = zahler - (-1);
             
          // Aufruf speichern
             $("#ytLayer").attr("zahler",zahler);
          }
          else
          {
             var linebreak = "";
             
             var zahler = 1;
             
          // Ersten Aufruf speichern
             $("#ytLayer").attr("zahler","1");
          }
          
       // Link-HTML rendern
          var ytLink = linebreak+'<a class="ytLink" rel="'+ytId+'" href="javascript:void(0)" onclick="loadNewVideo(this.rel, \'0\', \''+titelKurz+'\'); return false;" title="'+item.titel+'">'+item.titel+'</a>';
          
       // Menü-Link-HTML rendern
          var ytLinkMenu = linebreak+'<a class="ytLink" rel="'+ytId+'" href="javascript:void(0)" onclick="ytOpen(this.rel, \'0\', \''+titelKurz+'\'); return false;" title="'+item.titel.replace('"',"'")+'"><img src="http://i1.ytimg.com/vi/'+ytId+'/default.jpg" width="11" height="11" border="0" \> '+constrain(titelKurz,lange,"&hellip;")+'</a>';
          
       // Thumbnail rendern
          var ytThumbnail = '<img id="'+ytId+'Thumb" src="http://i1.ytimg.com/vi/'+ytId+'/default.jpg" width="200" height="150" border="0" style="display: none; padding-bottom: 25px; background: #f6f6f6; border: #666666 1px solid; cursor: pointer;" \>';
          
       // Flash-Player rendern
          var ytFlash = '<object id="'+ytId+'Flash" width="202" height="177"><param name="movie" value="http://www.youtube.com/v/' + ytId + '&hl=de&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><param name="bgcolor" value="#f6f6f6"></param><embed src="http://www.youtube.com/v/' + ytId + '&hl=de&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="202" height="177"></embed></object>';
          
          var erster = $("#ytLayer").attr("erster");
          
       // Links anhängen
          $("#ytVideos").append(ytLink);
          
       // Erster-Attribut lesen
          var videos = $("#ytVideosMenu").attr("videos");
          var videos = parseInt(videos);
          
       // In Menü nur X Videos
          if (zahler <= videos)
          {
          // Links anhängen
             $("#ytVideosMenu").append(ytLinkMenu);
          }
       }
       
    // Spezial: Head-Titel formatieren
       if (projekt == "sprueche")
       {
          var headTitle = '<i>"'+item.title+'"</i>';
       }
       else
       {
          var headTitle = item.title;
       }

       var projekte = new Array();

    // Antwort Anfang
       var antwort = ''; 
       var antwort = antwort + '<div class="lifeitem ' + projekt + '" id="lifeitem' + item_id + '" projekt="' + projekt + '" onmouseover="hover_feed_item(' + "'lifeitem" + item_id + "','an'" + ');" onmouseout="hover_feed_item(' + "'lifeitem" + item_id + "','aus'" + ');">';
       var antwort = antwort + '  <h3 class="lifeitemTitle">';
       var antwort = antwort + '    <img class="lifeitemTitleImg" id="lifeitemTitleImg' + item_id + '" src="img/icon_' + item.projekt + '.png" alt="' + projektMap(projekt) + '" title="' + projektMap(projekt) + '" style="cursor: help;" onclick="toggle_feed_desc(\'' + item_id + '\'); return false;">';
       var antwort = antwort + '    <a href="#" class="lifeitemSwitch" onclick="toggle_feed_desc(\'' + item_id + '\'); return false;">' + headTitle + '</a>';
       var antwort = antwort + '  </h3>';
       var antwort = antwort + '  <div class="lifeitemDetail" id="lifeitemDetail' + item_id + '"' + item_display + '>';
       
            if (projekt == "facebook")              { var antwort = antwort + '    <i><a href="http://www.facebook.com/sefzig" target="_blank">' + item.autor + '</a> <a title="Am ' + zeitString + '" style="text-decoration: none; cursor: help;">' + zeitPretty + '</a></i><br /><br /><div class="inhalt">' + item.beschreibung + '</div><br /><br />Permalink: <a href="' + item.link + '" target="_blank">' + item.link + '</a><br />'; }
       else if (projekt == "facebookFreunde")       { var antwort = antwort + '    <i>Von <a href="http://www.facebook.com/sefzig" target="_blank">' + item.autor + '</a>s\'s Freunden: ' + item.autor + ' <a title="Am ' + zeitString + '" style="text-decoration: none; cursor: help;">' + zeitPretty + '</a></i><br /><br /><div class="inhalt">' + item.beschreibung + '</div><br />'; }
       else if (projekt == "facebookNotifications") { var antwort = antwort + '    <i>In <a href="http://www.facebook.com/sefzig" target="_blank">Andreas Sefzig</a>\'s Netzwerk <a title="Am ' + zeitString + '" style="text-decoration: none; cursor: help;">' + zeitPretty + '</a>:</i><br /><br /><div class="inhalt">' + item.beschreibung + '</div><br />'; }
       else if (projekt == "facebookLinks")         { var antwort = antwort + '    <i><a href="http://www.facebook.com/sefzig" target="_blank">' + item.autor + '</a> hat <a title="Am ' + zeitString + '" style="text-decoration: none; cursor: help;">' + zeitPretty + '</a> einen <a href="' + item.link + '" target="_blank">Link</a> in <a href="http://www.facebook.com/sefzig" target="_blank">Facebook</a> gepostet:</i><br /><br /><div class="inhalt">' + item.beschreibung + '</div><br />Permalink: <a href="' + item.link + '" target="_blank">' + item.link + '</a><br />'; }
    // else if (projekt == "youtubeFavoriten")       { var antwort = antwort + '    <i><a href="http://www.youtube.com/aharef" target="_blank">Andreas Sefzig</a> hat am ' + zeitString + ' ein <a href="' + item.link + '" target="_blank">Video</a> in <a href="http://www.youtube.com/aharef">Youtube</a> als Favoriten gespeichert:</i><br /><br /><div class="inhalt"><object width="200" height="150"><param name="movie" value="http://www.youtube.com/v/' + item.beschreibung + '&hl=de&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' + item.beschreibung + '&hl=de&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="200" height="150"></embed></object></div><br />Permalink: <a href="' + item.link + '" target="_blank">' + item.link + '</a><br /><br />'; }
       else if (projekt == "youtubeFavoriten")      { var antwort = antwort + '    <i><a href="http://www.youtube.com/aharef" target="_blank">Andreas Sefzig</a> hat <a title="Am ' + zeitString + '" style="text-decoration: none; cursor: help;">' + zeitPretty + '</a> ein <a href="' + item.link + '" target="_blank">Video</a> in <a href="http://www.youtube.com/aharef">Youtube</a> als Favoriten gespeichert:</i><br /><br /><div class="inhalt">'+ytFlash+''+ytThumbnail+'<br /><br /><a class="ytLink" rel="'+ytId+'" href="javascript:void(0)" onclick="ytOpen(\''+ytId+'\'); ytHide(\''+ytId+'\');">Im Favoriten-Player abspielen</a></div><br />Permalink: <a href="' + item.link + '" target="_blank">' + item.link + '</a><br />'; }
       else if (projekt == "twitter")               { var antwort = antwort + '    <i><a href="http://twitter.com/sefzig" target="_blank">Andreas Sefzig</a> twitterte <a title="Am ' + zeitString + '" style="text-decoration: none; cursor: help;">' + zeitPretty + '</a>:</i><br /><br /><div class="inhalt">' + item.titel + '</div><br />Permalink: <a href="' + item.link + '" target="_blank" title="&Ouml;ffnet Twitter in einem neuen Fenster">' + item.link + '</a><br />'; }
       else if (projekt == "misterwong")            { var antwort = antwort + '    <i><a href="http://www.mister-wong.de/user/' + item.autor + '/" target="_blank">Andreas Sefzig</a> speicherte <a title="Am ' + zeitString + '" style="text-decoration: none; cursor: help;">' + zeitPretty + '</a> diesen <a href="' + item.link + '" target="_blank">Link</a> auf <a href="http://www.mister-wong.de/user/sefzig/">Mister Wong</a>:</i><br /><br /><div class="inhalt">Link: <a href="' + item.link + '" target="_blank">' + item.link + '</a><br /><br />' + misterwongThumbnail + 'Tags: ' + misterwongTags + '</div><br />'; }
       else if (projekt == "trendwork")             { var antwort = antwort + '    <i><a href="http://trendwork.kmf.de/" target="_blank">' + item.autor + '</a> schrieb <a title="Am ' + zeitString + '" style="text-decoration: none; cursor: help;">' + zeitPretty + '</a> diesen Post:</i><br /><br /><div class="inhalt">' + item.beschreibung + '</div><br />Permalink: <a href="' + item.link + '" target="_blank">' + item.link + '</a><br />'; }
       else if (projekt == "web20lexikon")          { var antwort = antwort + '    <i><a href="http://trendwork.kmf.de/web20-lexikon/?content=fachbegriffe&format=page" target="_blank">' + item.autor + '</a> schrieb diesen Fachbegriff <a title="Am ' + zeitString + '" style="text-decoration: none; cursor: help;">' + zeitPretty + '</a>:</i><br /><br /><div class="inhalt">' + item.beschreibung + '</div><br />Permalink: <a href="' + item.link + '" target="_blank">' + item.link + '</a><br />'; }
    // else if (projekt == "blogsefzignet")          { var antwort = antwort + '    <i><a href="http://blog.sefzig.net/" target="_blank">' + item.autor + '</a> schrieb diesen Post am ' + zeitString + ':</i><br /><br /><div class="inhalt">' + item.beschreibung + '</div><br />Permalink: <a href="' + item.link + '" target="_blank">' + item.link + '</a><br />'; }
    // else if (projekt == "blogsefzignet")          { var antwort = antwort + '    ' + item.beschreibung + '<br /><br /><i>Auszug aus dem Blogpost <a href="' + item.link + '" target="_blank">' + item.titel + '</a> vom ' + zeitString + '</i>'; }
    // else if (projekt == "blogsefzignet")         { var antwort = antwort + '    <i><a href="http://blog.sefzig.net/" target="_blank">' + item.autor + '</a> schrieb <a title="Am ' + zeitString + '" style="text-decoration: none; cursor: help;">' + zeitPretty + '</a> diesen <a href="' + item.link + '" target="_blank">Post</a>:</i><br /><br /><div class="inhalt">' + item.beschreibungHtml + '</div><br /><i>Permalink: <a href="' + item.link + '" target="_blank">' + item.link + '</a></i><br />'; }
       else if (projekt == "blogsefzignet")         { var antwort = antwort + '    <i><a href="http://blog.sefzig.net/" target="_blank">' + item.autor + '</a> schrieb <a title="Am ' + zeitString + '" style="text-decoration: none; cursor: help;">' + zeitPretty + '</a> diesen <a href="' + item.link + '" target="_blank">Post</a>:</i><br /><br /><div class="inhalt">' + item.beschreibung + '</div><br /><i>Permalink: <a href="' + item.link + '" target="_blank">' + item.link + '</a></i><br />'; }
       else if (projekt == "sprueche")              { var antwort = antwort + '       <a href="http://blog.sefzig.net/?cat=13" target="_blank">' + item.autor + '</a> sagte <a href="' + item.link + '" target="_blank">dies</a> <a title="Am ' + zeitString + '" style="text-decoration: none; cursor: help;">' + zeitPretty + '</a>.<br />'; }
       else if (projekt == "zeitgeist")             { var antwort = antwort + '    <i><a href="http://zeitgeist.sefzig.net/" target="_blank">' + item.autor + '</a> schrieb <a title="Am ' + zeitString + '" style="text-decoration: none; cursor: help;">' + zeitPretty + '</a> diesen Post:</i><br /><br /><div class="inhalt">' + item.beschreibung + '</div><br /><br />Permalink: <a href="' + item.link + '" target="_blank">' + item.link + '</a><br />'; }
       else if (projekt == "ajaxoffice")            { var antwort = antwort + '    <i><a href="http://sefzig.se.funpic.de/ajaxoffice/" target="_blank">' + item.autor + '</a> schrieb <a title="Am ' + zeitString + '" style="text-decoration: none; cursor: help;">' + zeitPretty + '</a> diesen Post:</i><br /><br /><div class="inhalt">' + item.beschreibung + '</div><br />Permalink: <a href="' + item.link + '" target="_blank">' + item.link + '</a><br />'; }
       else if (projekt == "fytch")                 { var antwort = antwort + '    <i><a href="http://fytch.com/fytcher/' + item.autor + '" target="_blank">Andreas Sefzig kommentierte <a title="Am ' + zeitString + '" style="text-decoration: none; cursor: help;">' + zeitPretty + '</a>:</i><br /><br /><div class="inhalt">' + item.beschreibung + '</div><br />Permalink: <a href="' + item.link + '" target="_blank">' + item.link + '</a><br />'; }
       else                                         { var antwort = antwort + '    <i>Unbekannte Quelle - ' + item.autor + ' schrieb <a title="Am ' + zeitString + '" style="text-decoration: none; cursor: help;">' + zeitPretty + '</a>:</i><br /><br /><div class="inhalt">' + item.beschreibung + '</div><br /><br />Permalink: <a href="' + item.link + '" target="_blank">' + item.link + '</a><br />'; }
       
    // Antwort Ende
       var antwort = antwort + '  </div>';
       var antwort = antwort + '</div>';
       
    // Javascript-Frontend Sefzig.net laden
       $.include("http://blog.sefzig.net/javascript-in-posts.js");
          
    // Antwort ausgeben
       return antwort;
    }

 // ----------------------------------------------------------------------------------------------------------------
 // Item-Details togglen
 // ----------------------------------------------------------------------------------------------------------------
 
    function toggle_feed_desc(item)
    {
       var status = $("#lifeitemDetail"+item).css("display");
    // alert(item+", "+status);
    
       if (status == "block")
       {
          $("#lifeitemDetail"+item).slideUp();
          
       // Performance...
       // $("#lifeitemDetail"+item).css("display","none");
       }
       else
       { 
          $("#lifeitemDetail"+item).slideDown();
          
       // Performance...
       // $("#lifeitemDetail"+item).css("display","block");
       }
          
    // Funktion beenden
       return false;
    }
      
 // ----------------------------------------------------------------------------------------------------------------
 // Item-Mouseover
 // ----------------------------------------------------------------------------------------------------------------

    function hover_feed_item(element,schalter)
    {
       if (schalter == "an")
       {
          $("#"+element).css("background","#f6f6f6");
       }
       else if (schalter == "aus")
       {
          $("#"+element).css("background","#ffffff");
       }
       else 
       {
          var status = $("#"+element).css("background");
       
          if (status == "#ffffff")
          {
             $("#"+element).css("background","#f6f6f6");
          }
          else
          {
             $("#"+element).css("background","#ffffff");
          }
       }
          
    // Funktion beenden
       return false;
    }
     
 // ----------------------------------------------------------------------------------------------------------------
 // Lifestream Yahoo!
 // ----------------------------------------------------------------------------------------------------------------
    
    function lifstreamYahoo(div)
    {
    // Pipe auslesen
       var pipe = $("#"+div).attr("pipe");
    
    // Link zusammensetzen
       var yahooHref = "http://pipes.yahoo.com/pipes/pipe.info?_id="+pipe;
    
    // Link aktualisieren
       $(".yahoo").attr("href",yahooHref).attr("target","_blank");
    }
         
 // ----------------------------------------------------------------------------------------------------------------
 // Im Lifestream suchen
 // ----------------------------------------------------------------------------------------------------------------
    
    function such(query)
    {
       $("#lifestream").children().filter(".lifeitem:visible").not(":contains('"+query+"')").css("display","none");
          
    // Funktion beenden
       return false;
    }
    
 // ----------------------------------------------------------------------------------------------------------------
 // Helper: String kürzen
 // ----------------------------------------------------------------------------------------------------------------
    
    function constrain(str,n,hellip)
    { 
       if(str.length > n)
       {  
          var s = str.substr(0, n);
          var words = s.split(' '); 
          words[words.length - 1] = '';
          str = words.join(' ') + '' + hellip;
       }
       
       return str;
    }

 // ----------------------------------------------------------------------------------------------------------------
 // Helper: Pretty Date
 // ----------------------------------------------------------------------------------------------------------------
    var datum = "2008-01-28T20:24:17Z"; // ISO8601!
 // ----------------------------------------------------------------------------------------------------------------
 // http://www.zachleat.com/web/2008/03/23/yet-another-pretty-date-javascript/
 // ----------------------------------------------------------------------------------------------------------------
 // Copyright (c) 2008 Dean Landolt (deanlandolt.com)
 // Re-write by Zach Leatherman (zachleat.com)
 // Adopted from the John Resig's pretty.js
 // at http://ejohn.org/blog/javascript-pretty-date
 // and henrah's proposed modification
 // at http://ejohn.org/blog/javascript-pretty-date/#comment-297458
 // Licensed under the MIT license.
 // ----------------------------------------------------------------------------------------------------------------
    
    function prettyDate(datum)
    {
	     var time_formats = 
	     [
          [60,         ' kurzem'],
          [90,         ' 1 Minute'],           // 60*1.5
          [3600,       ' Minuten',  60],       // 60*60, 60
          [5400,       ' 1 Stunde'],           // 60*60*1.5
          [86400,      ' Stunden',  3600],     // 60*60*24, 60*60
          [129600,     ' 1 Tag'],              // 60*60*24*1.5
          [604800,     ' Tagen',    86400],    // 60*60*24*7, 60*60*24
          [907200,     ' 1 Woche'],            // 60*60*24*7*1.5
          [2628000,    ' Wochen',   604800],   // 60*60*24*(365/12), 60*60*24*7
          [3942000,    ' 1 Monat'],            // 60*60*24*(365/12)*1.5
          [31536000,   ' Monaten',  2628000],  // 60*60*24*365, 60*60*24*(365/12)
          [47304000,   ' 1 Jahr'],             // 60*60*24*365*1.5
          [3153600000, ' Jahren',   31536000], // 60*60*24*365*100, 60*60*24*365
          [4730400000, ' 1 Jahrhundert'],      // 60*60*24*365*100*1.5
	     ];

	     var time = ('' + datum).replace(/-/g,"/").replace(/[TZ]/g," "),
	     dt = new Date,
	     seconds = ((dt - new Date(time) + (dt.getTimezoneOffset() * 60000)) / 1000),
	     token = ' vor ',
	     i = 0,
	     format;

	     if (seconds < 0)
	     {
			    seconds = Math.abs(seconds);
			    token = ' in';
	     }

	     while (format = time_formats[i++])
	     {
	        if (seconds < format[0])
	        {
             if (format.length == 2)
             {
             // Conditional so we don't return Just Now Ago
                var antwort = (i > 1 ? token : '') + format[1]; 
             }
             else
             {
                var antwort = (i > 1 ? token : '') + Math.round(seconds / format[2]) + ' ' + format[1];
             }
             
          // vor 1 Tag -> gestern
             if (antwort == " vor 1 Tag")
             {
                var antwort = " gestern";
             }
             
          // Antworten
             return antwort; 
          }
       }

    // Overflow for centuries
       if(seconds > 4730400000)
       {
          return Math.round(seconds / 4730400000) + ' Centuries' + token;
       }
       
       alert(datum);
       return datum;
    };

 // ----------------------------------------------------------------------------------------------------------------
 // Helper: URL decodieren
 // ----------------------------------------------------------------------------------------------------------------
 // Decodes URL-encoded string  
 // version: 907.503
 // discuss at: http://phpjs.org/functions/urldecode
 // original by: Philip Peterson
 // improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
 // input    by: AJ
 // improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
 // improved by: Brett Zamir (http://brett-zamir.me)
 // input    by: travc
 // input    by: Brett Zamir (http://brett-zamir.me)
 // bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
 // improved by: Lars Fischer
 // input    by: Ratheous
 // improved by: @Shamun Toha
 // note     by: - Shamun: decodeURIComponent failed on many characters
 // ----------------------------------------------------------------------------------------------------------------
 // note      1: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
 // ----------------------------------------------------------------------------------------------------------------
 // example   1: urldecode('Kevin+van+Zonneveld%21');
 // returns   1: 'Kevin van Zonneveld!'
 // ----------------------------------------------------------------------------------------------------------------
 // example   2: urldecode('http%3A%2F%2Fkevin.vanzonneveld.net%2F');
 // returns   2: 'http://kevin.vanzonneveld.net/'
 // ----------------------------------------------------------------------------------------------------------------
 // example   3: urldecode('http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a');
 // returns   3: 'http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a'
 // ----------------------------------------------------------------------------------------------------------------
 // example   4: urldecode("%3Ctr%3E%3Ctd%3Einfo%40jquery.com%20space%20%E9%3C%2Ftd%3E%3C%2Ftr%3E");
 // returns   4: <tr><td>info@jquery.com Space e</td></tr>
 // ----------------------------------------------------------------------------------------------------------------

    function urldecode(str)
    {
       var hash_map = {}, ret = str.toString(), unicodeStr='', hexEscStr='';
    
       var replacer = function(search, replace, str)
       {
          var tmp_arr = [];
          tmp_arr = str.split(search);
          return tmp_arr.join(replace);
       };
       
    // The hash_map is identical to the one in urlencode.
       hash_map["'"]   = '%27';
       hash_map['(']   = '%28';
       hash_map[')']   = '%29';
       hash_map['*']   = '%2A';
       hash_map['~']   = '%7E';
       hash_map['!']   = '%21';
       hash_map['%20'] = '+';
       hash_map['\u00DC'] = '%DC';
       hash_map['\u00FC'] = '%FC';
       hash_map['\u00C4'] = '%D4';
       hash_map['\u00E4'] = '%E4';
       hash_map['\u00D6'] = '%D6';
       hash_map['\u00F6'] = '%F6';
       hash_map['\u00DF'] = '%DF';
       hash_map['\u20AC'] = '%80';
       hash_map['\u0081'] = '%81';
       hash_map['\u201A'] = '%82';
       hash_map['\u0192'] = '%83';
       hash_map['\u201E'] = '%84';
       hash_map['\u2026'] = '%85';
       hash_map['\u2020'] = '%86';
       hash_map['\u2021'] = '%87';
       hash_map['\u02C6'] = '%88';
       hash_map['\u2030'] = '%89';
       hash_map['\u0160'] = '%8A';
       hash_map['\u2039'] = '%8B';
       hash_map['\u0152'] = '%8C';
       hash_map['\u008D'] = '%8D';
       hash_map['\u017D'] = '%8E';
       hash_map['\u008F'] = '%8F';
       hash_map['\u0090'] = '%90';
       hash_map['\u2018'] = '%91';
       hash_map['\u2019'] = '%92';
       hash_map['\u201C'] = '%93';
       hash_map['\u201D'] = '%94';
       hash_map['\u2022'] = '%95';
       hash_map['\u2013'] = '%96';
       hash_map['\u2014'] = '%97';
       hash_map['\u02DC'] = '%98';
       hash_map['\u2122'] = '%99';
       hash_map['\u0161'] = '%9A';
       hash_map['\u203A'] = '%9B';
       hash_map['\u0153'] = '%9C';
       hash_map['\u009D'] = '%9D';
       hash_map['\u017E'] = '%9E';
       hash_map['\u0178'] = '%9F';
   
    // on decodeURIComponent failure.
       hash_map['<']      = '%3C';
       hash_map['>']      = '%3E';
       hash_map['/']      = '%2F';
       hash_map['@']      = '%40'; 
       hash_map['e']      = '%E9';     
       hash_map[' ']      = '%20';
         
       for (unicodeStr in hash_map)
       {
       // Switch order when decoding
          hexEscStr = hash_map[unicodeStr];
          
       // Custom replace. No regexing
          ret = replacer(hexEscStr, unicodeStr, ret); 
       }    
    
    // End with decodeURIComponent, which most resembles PHP's encoding functions
       ret = decodeURIComponent(ret);
 
    // Antworten
       return ret;
    }
 