// ==UserScript==
// @name            TumblrAddAsLinks
// @namespace       http://proto.jp
// @description     TumblrAddAsLinks
// @include         http://www.tumblr.com/reblog/*
// @exclude         http://mail.google.com/*
// @version			0.1.1
// ==/UserScript==

(function(){
	
	if(parent.document != document){return;};

	var defUrl = document.location.toString();	
	var asTypes = ["photo","audio","chat","link","text","quote","video"];
	var asLinks = document.getElementById("the_as_links");
	
	
	if(defUrl.indexOf("/photo?") != -1)
	{
		var one = document.getElementById("post_one_is_rich_text");
		one.value = 1;
		
		var f = document.getElementById("edit_post");
		var d = document.createElement("div");
		d.innerHTML
		='<div id="photo_url" style=""><h2>Photo URL</h2>'
		+'<input id="photo_src" class="text_field wide" type="text" name="post[one]"/></div>'
		+'<input type="hidden" value="10485760" name="MAX_FILE_SIZE"/>'
		+'<input type="hidden" value="photo" name="post[type]"/>'
		f.appendChild(d);
		//+f.innerHTML;//post[one]//photo_src
	}
	
	
	
	
	for (var i = 0, l = asTypes.length; i < l; i++) 
	{
		defUrl = defUrl.replace("/"+asTypes[i],"");
	}
		
	var asLinksA = asLinks.getElementsByTagName("a");
	var xClose = asLinksA[asLinksA.length-1];
	
	asLinks.innerHTML = "";
	asLinks.appendChild(xClose);
	
	var div = document.createElement("div");
		
	for(var i=0,l=asTypes.length; i<l; i++)
	{		
		var a = document.createElement("a");
		var s = document.createElement("STRONG");
		s.appendChild(document.createTextNode(asTypes[i]))
		a.appendChild(document.createTextNode("as a "));
		a.appendChild(s);
		a.href = defUrl.replace("?","/"+asTypes[i]+"?");
		
		if(i<2){a.style.opacity=0.38; asLinks.appendChild(a);}else{div.appendChild(a);}
	}
	
	div.style.margin = "8px 0 0 0";
	
	asLinks.appendChild(div);
	
})();