function showAddComment(reply_to_id,comment) {
	
	if(reply_to_id) {
		$("#ContentCommentReplyToId").val(reply_to_id);
		$("#ContentCommentSubject").show();
		$("#ContentCommentSubject").attr('disabled', 'disabled');
		$("#ContentCommentSubject").val('RE: '+comment);
	}else{
		$("#ContentCommentReplyToId").val('');
		$("#ContentCommentSubject").val('');
		$("#ContentCommentSubject").hide();
		$("#ContentCommentSubject").val('');
	}
	
	document.getElementById('addComment').style.display = 'block';
	$("#addComment").show();
	
}

$(document).ready(function() {
	$("#ContentCommentSubject").hide();
	
	$("ul.archDate").hide();
	$("ul.selDate").show();
	$('div.archDate').click(
		function (event) {
			$("ul.selDate").slideUp();
			$('#p-'+$(this).attr('id')).slideDown();
			
			
			$("div.selDate").attr('class','subhead archDate');
			$("ul.selDate").attr('class','archDate');
			$('#'+$(this).attr('id')).attr('class','subhead selDate archDate');
			$('#p-'+$(this).attr('id')).attr('class','selDate archDate');
		}
	);
	
	
	// set pdf class for pdf if there is no image inside
	$("#content div.content a[href$='pdf']").addClass('pdf').attr('target','_blank');
	
	$("#content div.content a.pdf img").parent().removeClass('pdf');
	
	
	
	// http://code.google.com/p/swfobject/wiki/documentation
	var collection = jQuery("#content div.content a[href$='swf']");
	
	if (collection){
		
		var i = 0;
		
		collection.each(function() {

			
    		i++;
    		
        	var href = $(this).attr('href');
        	var id = "flashswf" + i;
        	
        	var newDiv = 
        		"<div id=" + id + " >" +
        			"This is a flashswf test" +
        		"</div>";
        	
        	$(this).parent().html(newDiv);
        	
        	var attributes = {
      			  styleclass: "flashswf"
      			};
        	
        	// swfobject.embedSWF(swfUrl, id, width, height, version, expressInstallSwfurl, flashvars, params, attributes);        	
        	swfobject.embedSWF(href,id, '480','380','7.0.0',false,false,false,attributes);
        	
        	
        	
        });
		
	}
	
	var collection = jQuery("#content div.content a[href$='flv']");
	
	
	
	if (collection){
		
		var i = 0;
		
		collection.each(function() {

			
    		i++;
    		
        	var href = $(this).attr('href');
        	var id = "flashflv" + i;
        	
        	var newDiv = 
        		"<div id=" + id + " >" +
        			"This is a flashflvtest" +
        		"</div>";
        	
        	$(this).parent().html(newDiv);
        	
        	var params = {
        			allowfullscreen: "true",
        			wmode: "transparent"
        			};

        	var preview = href.replace('flv','jpg');
        	
        	var flashvars = {
        			  file: href,
        			  image: preview
        			};
        	
        	var attributes = {
        			  styleclass: "flashflv"
        			};

        	
        	swfobject.embedSWF('http://'+ location.host +'/player.swf',id, '480','380','9',false,flashvars,params,attributes);
        	
        	
        	
        	
        });
		
	}	
	
	
	$('#EmailQuestionSubmit')
	.click(
		function (event) {		
			
			event.preventDefault();
			validEmail = false;
			
			user = $('#ContentEmailAddress').val().split("@");
			if(user[1]) {
				
				domain = user[1].split(".");
				if(domain[1]) {
					user = user[0];
					tld = domain[1];
					domain = domain[0];
					
					if(user.length>0 && domain.length>0 && tld.length>0) {
						validEmail = true;
					}
				}
			}

			if(validEmail == false || $('#ContentEmailQuestion').val().length < 1) {
				alert('A valid email address and a question is required.');
			}else{
				$('#EmailQuestionSubmit').val('Sending...');
				$('#EmailQuestionSubmit').attr("disabled","disabled");
				
				var postData = $('#EmailQuestion').serialize();	
				
				var newUrl = "/blogs/sendForm/";
				
				$.ajax({
					type: "POST",
				   	url: newUrl,
				   	data: postData,
				   	success: function(msg){
					
						$('.emailquestion .recipeidea').html(msg);
						
						
						// Fix up the roundcontent height after comment has changed height
						var newHeight = $('.emailquestion .roundcontent').height();
								
						
						$('.emailquestion .roundtop').height(newHeight);
						
		  			}
		  		});
			}
			
		});
	
	
	$('#AddCommentSubmit')
	.click(
		function (event) {
			
			
			
			event.preventDefault();
			
			var postData = $('#ContentCommentAddForm').serialize();	
			
			var newUrl = "/content_comments/add/";
			
			$.ajax({
				type: "POST",
			   	url: newUrl,
			   	data: postData,
			   	success: function(msg){
				
					
				
					$('#addCommentText').html(msg);
					
					
					// Fix up the roundcontent height after comment has changed height
					var newHeight = $('#addComment .roundcontent').height();
							
					
					$('#addComment .roundtop').height(newHeight);
					
	  			}
	  		});
			
			
		});
		
		
		var commentInfo = '<div id="commentInfo" ></div>';
		
		$('label[for=ContentCommentComment]').append(commentInfo);
		
		$('#ContentCommentComment').keyup(function(){
		
			 limitChars('ContentCommentComment', 100, 'commentInfo');
		
		});

	
});


function limitChars(textid, limit, infodiv){

	var text = $('#'+textid).val(); 
	
	var textlength = text.length;
	
	if(textlength > limit){
	
		$('#' + infodiv).html('You cannot write more then '+limit+' characters!');
	
		$('#'+textid).val(text.substr(0,limit));
	
		return false;
	} else {
	
		$('#' + infodiv).html('You have '+ (limit - textlength) +' characters left.');
	
		return true;
	}

}
