
var JSONTumblrator = function( json, divid )
{
  /* declared reference variable */
  var $t = this;
  
  /* internal vars */
  $t.json = json;
  $t.div = divid;
  $t.posts = null;
  
  /* shortcut for getElementById */
  $t.$ = function( i, doc )
  {
    doc = doc === undefined ? document : doc;
    return doc.getElementById( i );
  };
  
  /* shortcut for createElement, with an added param to set an id attribute */
  $t._$ = function( i, id )
  {
    var e = document.createElement( i );
    
    if ( id !== undefined ) { e.setAttribute( "id", id ); }
    
    return e;
  };

  /* methods */
  $t._createposts = function( )
  {
    var d, i, post, pd;
    
    $t.posts = $t.json.posts;
    
    d = $t._$( "div", "tumblr-posts" );
    
    for( i = 0; i < $t.posts.length; i++ )
    {
      post = $t.posts[ i ];
      pd = $t._$( "div" );
      pd.setAttribute( "class", "tumblr-post" );
      
      switch( post.type )
      {
        case "video":
          pd.setAttribute( "class", "tumblr-post video-post" );
          pd.innerHTML += post["video-player"] + post["video-caption"];
                    
        break;
      }
      d.appendChild( pd );
    }
    $t.$($t.div).appendChild( d );
  };
  
  $t._createposts( );
  
}
