// older functions
function htmlformatting( data ) {
	var data = data.replace(/images\//g,"http://wwiaircombat.com/images/");
	data = data.replace(/videos\//g,"http://wwiaircombat.com/videos/");
	data = data.replace(/files\//g,"http://wwiaircombat.com/files/");
	data = data.replace(/\n/g, "<br>");
	return data;
}

function video ( url, videoid ) {
	document.getElementById("video").innerHTML = document.getElementById(url).innerHTML;
	document.getElementById("video").style.diplay = "inline";	
}

function show_preview() {
	var data = document.getElementById("ajax_text").value;
	data = htmlformatting( data );
	document.getElementById("ajax_span").innerHTML = data;
	document.getElementById("ajax_text_for_post").value = data;	
}

//newer jquery functions
var wwiaircombat = function () {
	var post_id, name, email, hide_email, comment, output, commentBox = null;
	
	$(document).ready(function() {
		$("ul.videos li a").each(function() {
			$(this).click(function(e){
				e.preventDefault();
				if ($(this).attr("title") === "Click to close the video") {
					$(this).attr("title", "Click to open the video");
					$(this).next("object").remove();
				} else {
					$(this).attr("title", "Click to close the video");
					var videoId = $(this).parent().attr("class");
					var embed = $("ul#video-data li." + videoId).html();
					$(this).parent().append(embed);
				}
			});
		});
		
		$(".comments").click(function(e) {
			e.preventDefault();
			wwiaircombat.commentBox = $(this);
			
			$.getJSON("get-comments.php", {a:"view",id: $(this).attr("alt")},
			   function (data)
			   {
					wwiaircombat.output = "";
					try {
			        	$.each ( data, function(i, curComment) {
							if (curComment.email) {
								wwiaircombat.output += "<li><p class='name'><a href='mailto:" + curComment.email + "'>" + curComment.name + "</a></p><p>" + curComment.comment + "</p><p class='time'>" + curComment.timestamp + "</p></li>";
							} else {
								wwiaircombat.output += "<li><p class='name'>" + curComment.name + "</p><p class='comment'>" + curComment.comment + "</p><p class='time'>" + curComment.timestamp + "</p></li>";
							}
						});
			 		} catch (e) {
						console.log("error: " + e);
					}
					wwiaircombat.commentBox.next().html(wwiaircombat.output);
			   });
    	});
	});
};

wwiaircombat();

