$(document).ready(function(){
	/*$("#uploadlink").click(function(){
		if ($(this).children("span").eq(0).attr('id') != null) {
			message = "?message="+$(this).children("span").eq(0).attr("id").substring(4);
		}
		else {
			message = ""
		}
		do_overlay();
		topic_href = $(this).attr("href")
		//$.get("/forum/upload/"+topic_id+".ajax",null,function(data){
		$("#litbox").html('	\n\
<div id="litboxinner">\n\
	<div id="litboxheader">\n\
		<h1>Upload a File</h1>\n\
		<a id="litboxclose"><img src="/include/images/button-x-close.png" alt="X Icon" title="Close this Window" /></a>\n\
	</div>\n\
	<iframe src="'+topic_href+'.ajax'+message+'" width="100%" height="300"></iframe>\n\
</div>').show();
		$("#litboxclose").click(function(){
			close_overlay();
			$.get("/forum/get_session_uploads",function(data){
				$("#attachments").remove();
				$("#thumbnails legend").after(data);
				add_insert_links();
			})
		})
		//})
		return false;
	})*/
	add_insert_links();
	//upload_progress_bar();
})

function add_insert_links() {
	$("#attachments li button.add").unbind().click(function(){
		if (typeof $("#message_body_original").attr("value") != "undefined") {
			newvalue = $("#message_body_original").attr("value")
		}
		else {
			newvalue = ""
		}
		if ($("input#message_disable_textile").attr("checked") == true) {
		  newvalue += "[img]"+$(this).parent().find("a.filename").eq(0).attr("href")+"[/img]"
		}
		else {
		  newvalue += "!"+$(this).parent().find("a.filename").eq(0).attr("href")+"!"
		}
		$("#message_body_original").attr("value",newvalue);
		$("input#message_thumbnail_none").attr("checked","checked");
		$.scrollTo("#reply",200)
		return false;
	})
}

function upload_progress_bar() {
  $("#GO_UPLOAD").click(function(){
    gotoattachment = true
  })
}

/*function upload_progress_bar() {
  $("#GO_UPLOAD").click(function(){
    var d = document.getElementById('uploadingiframe').contentWindow.document;
    formhtml = $(this).parents("form").eq(0).parent().html();
    
    var body = $('<body></body>')
    var form = $('<form method="POST" action="/test"><input id="attachment_uploaded_data" name="attachment[uploaded_data]" size="30" type="file"></form>')
    //var file = $("#attachment_uploaded_data")
   // file.appendTo(form);
    
    var oldElement = $("#attachment_uploaded_data")
		var newElement = $(oldElement).clone();
		$(oldElement).attr('id', 'fileIddsfsdf');
		$(oldElement).before(newElement);
		$(oldElement).appendTo(form);
	  $(form).appendTo(body)
    
    d.open();
    //weird - safari won't load scripts without this lines... 
    d.write('<html><head></head><body>'+form.html()+'</body></html>');
    d.close();
    
    var b = d.body;
    var s = d.createElement('script');
    s.src = "/include/javascripts/jquery.js"
    // must be sure that jquery is loaded 
    s.onload = function() {
      var s1 = d.createElement('script');
      s1.src = "/include/javascripts/functions.js"
      b.appendChild(s1);
      var s2 = d.createElement('script');
      s2.src = "/include/javascripts/upload_popup.js"
      b.appendChild(s2);
    }
    b.appendChild(s);
    //alert (s);
    
    //formhtml = $(this).parents("form").eq(0).parent().html();
    
    //window.uploadingiframe.jQuery("#attachment_uploaded_data").attr("value",);
		return false;
  })
}*/