	var format = 'strip'; // strip or fullpage 
	var tag = 'daily';
	var imagePath = 'http://slowmobile.com/files/';
	var numPostsToDisplay = 3;
	var postCount = 0;
	// Make -1 to turn off jquery.expander
	var tumblrURL = "http://slowmobile.tumblr.com/api/read/json?tagged="+tag+"&callback=?";
	var postMaxDescriptionLength = 100;
	var tumblr_api_read = null;
    var pretty_tag = tag.charAt(0).toUpperCase() + tag.slice(1);
	var FullBlog = "";
		
	$(document).ready(function() {	
 		reloadTumblr();
  	});		
  
  function reloadTumblr(){  	
  	$("#tumblrStrip").empty();
  	$("#tumblrStrip").append("<div class='loading_posts'><img class='icon' src='" + imagePath + "loading_blog.gif'/> loading "+tag+" posts... </div>");
  
  	$.ajax({
		  url: tumblrURL,
		  dataType: 'script',
		  timeout: 10000,
      success:function(){ 
      	$("#tumblrStrip").empty();
      	if ((tumblr_api_read == undefined) || (tumblr_api_read == null)) {
      		$("#tumblrStrip").append("<div class='title' href='#'>unable to load "+tag+" Feed...</div>");
      		$("#tumblrStrip").append("<div ><a href=\"#\" onclick=\"javascript:reloadTumblr();\">[retry]</a></div>");    			

    		} else {
    	
//			$("#tumblrStrip").append("<div><a href=\"#\" style=\"float:right\" onclick=\"javascript:reloadTumblr();\">[refresh]</a></div>");

    			postCount = 0;
	        $.each(tumblr_api_read.posts.slice(0, 10), function(i,post){
						if (postCount >= numPostsToDisplay) {
							return;
						}    			
	    			parseTumblrJSON(post);
	    			postCount++;
	  			});
	
	    		// Apply Expander
	    		if (postMaxDescriptionLength > -1) {
					  $('div.expandable').expander({
					    slicePoint:       postMaxDescriptionLength,  // default is 100
					    expandText:         '[more]',
					    userCollapseText: '[^]'
					  });					    			
	    		}
    		}
      },
      error:function (xhr, statusTxt, errorTxt){
      		$("#tumblrStrip").append("<a class='title' href='#'>"+tag+" Feed Parse Error</a>");
      		$("#tumblrStrip").append("<div >" + errorTxt + "<br/>" + xhr.responseText + "</div>");
      } 					      
		});  	

	  $('.timeago').timeago();

  }

		
	function parseTumblrJSON(post) {
		
		//alert(post.type);
				
		var date = 'see more...'; // post["date"]
		var blogURL = "/daily";
		var thisBlogTile = "<div class='blog_tile "+post.type+"'>";
										

    switch(post.type)
    {		    	
    	case "regular":
    	{
			if (post["regular-title"] != null ) { var post_title = post["regular-title"]; } else { var post_title = ''; } 
			var thisBlogTile = thisBlogTile +  "<div class='title'><a class='title' href='" + blogURL + "'>" + post_title + "</a></div>";
			var thisBlogTile = thisBlogTile +  "<div class=' expandable'>" + post["regular-body"] + "</div><a class='permalink' href='" + blogURL + "'>&rarr; <span class='timeago' title='"+ date +"'>"+ date +"</span></a></div><!-- end of this_post -->";
			break;
    	}
    	case "link":
    	{
    		var thisBlogTile = thisBlogTile +  "<a class='title' href='" + post["link-url"] + "'>" + post["link-text"] + "</a>";
    		var thisBlogTile = thisBlogTile +  "<div class=' expandable'>" + post["link-description"] + "</div><a class='permalink' href='" + blogURL + "'>&rarr; <span class='timeago' title='"+ date +"'>"+ date +"</span></a></div><!-- end of this_post -->";
    		break;
    	}		    	
    	case "quote":
    	{
    		var thisBlogTile = thisBlogTile +  "<div class=' quote'>" + 
    			"<div class=' expandable'>" + post["quote-text"] + "</div>" +
    			"<div class='quotesrc'>" + post["quote-source"] + "</div>" +
    			"</div></div>";
    		break;
    	}		    	
    	case "photo":
    	{

			if (format == 'fullpage') { imageSize = '500'; }
			if (format == 'strip') { imageSize = '250'; }
			
    
		// valid values are: photo-url-[75, 100, 250, 400, 500, 1280]
    		var thisBlogTile = thisBlogTile +  "<div>" + 
    			"<a class='title' href='" + blogURL + "'>" +
    			"<img src='" + post["photo-url-" + imageSize + ""] + "'/></a><br/>" + 
    			post["photo-caption"] + 
    			"</div><a class='permalink' href='" + blogURL + "'>&rarr; <span class='timeago' title='"+ date +"'>"+ date +"</span></a></div><!-- end of this_post -->";

			break;
    	}
    	case "conversation":
    	{
    		var html = '';

			var thisBlogTile = thisBlogTile +  "<a class='title' href='" + blogURL + "'>" + post["conversation-title"] + "</a>";

				for(var i = 0; i < post["conversation"].length; i++) {
					var conv = post["conversation"][i];						
					html += "<div class='convlabel'>" + conv.label + "</div>";
					html += "<div class='convtext expandable'>" + conv.phrase + "</div>";
				}

				/*    		
				$(this).find("line").each(function(){
					html += "<div class='convlabel'>" + $(this).attr("label") + "</div>";
					html += "<div class='convtext'>" + $(this).text() + "</div>";
				});*/
    				    		
    		var thisBlogTile = thisBlogTile + "<div>" + html + "</div><a class='permalink' href='" + blogURL + "'>&rarr; <span class='timeago' title='"+ date +"'>"+ date +"</span></a></div><!-- end of this_post -->";
    		break;
    	}
    	case "audio":
    	{
	   		var thisBlogTile = thisBlogTile +  "<a class='title' href='" + blogURL + "'>" + post["audio-caption"] + "</a>";
    		var thisBlogTile = thisBlogTile +  "<div >" + post["audio-player"] + "</div><a class='permalink' href='" + blogURL + "'>&rarr; <span class='timeago' title='"+ date +"'>"+ date +"</span></a></div><!-- end of this_post -->";
    		break;
    	}
    	case "video":
    	{
    		var thisBlogTile = thisBlogTile +  "<div >" + 
    			post["video-player"] + 
    		"</div><a class='permalink' href='" + blogURL + "'>&rarr; <span class='timeago' title='"+ date +"'>"+ date +"</span></a></div><!-- end of this_post -->";
    		break;
    	}		    	

    	default:
   		break;
    
}

		// alert(thisBlogTile);

	FullBlog += thisBlogTile;

    $("#tumblrStrip").html(FullBlog);

}

function flashVersion(){if(navigator.plugins&&navigator.plugins.length>0){var a=navigator.mimeTypes;if(a&&a["application/x-shockwave-flash"]&&a["application/x-shockwave-flash"].enabledPlugin&&a["application/x-shockwave-flash"].enabledPlugin.description){return parseInt(a["application/x-shockwave-flash"].enabledPlugin.description.split(" ")[2].split(".")[0],10)}}else{if(navigator.appVersion.indexOf("Mac")==-1&&window.execScript){try{var c=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");var b=c.GetVariable("$version");return b.split(",")[0].split(" ")[1]}catch(d){}return 0}}}function replaceIfFlash(b,a,c){if(flashVersion()>=b){document.getElementById(a).innerHTML=c}}function renderVideo(c,g,e,a,b){var d=navigator.userAgent.toLowerCase();var f=(d.indexOf("iphone")!=-1);if(f){document.getElementById(c).innerHTML='<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="'+e+'" height="'+a+'" codebase="http://www.apple.com/qtactivex/qtplugin.cab"><param name="src" value="'+g+'"><param name="qtsrc" value="'+g+'"><param name="autoplay" value="false"><embed src="'+g+'" qtsrc="'+g+'" width="'+e+'" height="'+a+'" pluginspage="http://www.apple.com/quicktime/"></embed></object>'}else{replaceIfFlash(10,c,'<embed type="application/x-shockwave-flash" src="http://assets.tumblr.com/swf/video_player.swf?22" bgcolor="#000000" quality="high" class="video_player" allowfullscreen="true" height="'+a+'" width="'+e+'" flashvars="file='+encodeURIComponent(g)+(b?"&amp;"+b:"")+'"></embed>')}};
