var GLOBAL_DIR = "";

jQuery(document).ready(function($){
	$('.comment-form').submit(function(){ submitCommentForm($(this)); return false;});
	
	 $("#hero").jcarousel({
	    auto: 10,
	    scroll: 1,
	    visible: 1,
	    wrap: 'both',
	    animation: 1000,
	    initCallback: carousel_initCallback,
	    itemVisibleInCallback: {
	      onAfterAnimation:  carousel_next
	    },
	    buttonNextHTML: "",
	    buttonPrevHTML: ""
	  });
  
  
  	//Superfish
	/* setup the main menu */
	$('#mainTopMenu').superfish({
		autoArrows:		false,
		dropShadows:		false,
		speed:			"slow"
	});


	
	tinyMCE.init({
		// Location of TinyMCE script
		//script_url : '/site/tiny_mce/tiny_mce.js',

		// General options
                mode : "specific_textareas",
                editor_selector : "richtextsimple",
                theme : "advanced",
                plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist",

                // Theme options
                theme_advanced_buttons1 : "bold,italic,underline",
                theme_advanced_buttons2 : "",
                theme_advanced_buttons3 : "",
                theme_advanced_buttons4 : "",
                theme_advanced_toolbar_location : "top",
                theme_advanced_toolbar_align : "left",
                //theme_advanced_statusbar_location : "bottom",
                theme_advanced_resizing : true,

                // Example content CSS (should be your site CSS)
                content_css : "",

                relative_urls : false,



                file_browser_callback : "tinyBrowser",
                remove_script_host : false,

                height: "300px",
                width: "450px",

                // Drop lists for link/image/media/template dialogs
                template_external_list_url : "js/template_list.js",
                external_link_list_url : "js/link_list.js",
                external_image_list_url : "js/image_list.js",
                media_external_list_url : "js/media_list.js",

                force_br_newlines : false,
                force_p_newlines : true,

                // Replace values for the template plugin
                template_replace_values : {
              }
	});
	
	$('.autosearchme').each(function(){
		var autosearch = $(this).val();
		$(this).parent().append($("#frontendForm").html());
                $('#frontendForm').remove();
	});
	
	  // Reset Font Size
	//    $(".resetFont").click(function(){
	//    $('.articleContent p, .articleContent caption, .comment-display-message').css('font-size', '12px');
	//  });
	  // Increase Font Size
	//  $(".increaseFont").click(function(){
	//   $('.articleContent p, .articleContent caption, .comment-display-message').css('font-size', '13px');
	//  });
	  // Decrease Font Size
	//  $(".increaseFont2").click(function(){
	//    $('.articleContent p, .articleContent caption, .comment-display-message').css('font-size', '15px');
	//  });

	
	
});

function dropShadows()
{

}

function hideShadows()
{

}

/** Comment functions **/
function submitCommentForm(frm)
{

	var comment = frm.children("textarea.comment-form-textbox").val();
	var type = frm.children(":input[name=type]").val();
	var id = frm.children(":input[name=id]").val();
	var withComments = frm.children(":input[name=withComments]").val();
	var reply = frm.children(":input[name=reply]").val();
	var vote = "";
	
	comment = $.trim(comment);
	
	if(comment == "")
		return false;
				
	if(!(frm.children("div.'comment-check-parent").children(":input[name=comment-check]").is(':checked')))
	{
		alert("You must tick the checkbox regarding the Terms of Use to post a comment.");
		return false
	}
	if(type == "")
	{
		alert("Yacht and Boat system error - Comment form error TYPE_01");
		return false;
	}
	if(id == "")
	{
		alert("Yacht and Boat error - Comment form error IDENTIFIER_01");
		return false;
	}	
	if(reply != 0)
	{
		frm.parent().parent().find(".comment-new:last").append(getCommentScript(comment));
		$(".comment-form-reply").remove();
	}
	else
	{
		frm.parent().parent().find(".comment-new:last").append(getCommentScript(comment));
	}
	
	$.post(GLOBAL_DIR + "/comment/addComment", { comment: comment, type: type, id : id, vote: vote, reply: reply }, function(xml){
		frm.children("textarea.comment-form-textbox").val("");
	});	
	return false;
}

function getCommentScript(comment)
{
	var rtnText = '<div class="comment-display-new"><div class="comment-display-message"><div class="comment-display-avitar">';
	rtnText += '<span class="comment-display-name">You</span><Br /><span class="comment-display-time">Just now</span></div>';
	rtnText += '';
	rtnText += comment;
	rtnText += '</div><div class="clearMe"></div></div>';
	return rtnText;
}

function commentRemove(id, isSub)
{
	if(!confirm("Are you sure you want to remove this comment?"))
	{
		return;
	}
	$("#comment-" + id).css("background-color", "#F2BFBF");
	$("#comment-" + id + " .comment-display-delete").html("removing...");
	$.post(GLOBAL_DIR + "/comment/removeComment", {id : id }, function(xml){
		$("#comment-" + id).fadeTo("slow", 0.33);
		$("#comment-" + id + " .comment-display-delete").html("comment removed");
	});
}


function commentReport(id, isSub)
{
	if(!confirm("Are you sure you want to report this comment?"))
	{
		return;
	}
	$("#comment-" + id).css("background-color", "#F2BFBF");
	$("#comment-" + id + " .comment-display-delete").append("reporting...");
	$.post(GLOBAL_DIR + "/comment/reportComment", {id : id }, function(xml){
		$("#comment-" + id).fadeTo("slow", 0.33);
		$("#comment-" + id + " .comment-display-delete").html("comment reporting");
	});
}

function commentReply(id, id2, type)
{
	var rntText = '<form name="comment-form" class="comment-form-reply comment-form" onSubmit="return false"><textarea class="comment-form-textbox" name="comment" style="width: 500px"></textarea><input type="hidden" name="type" value="' + type + '"><input type="hidden" name="withComments" value="0"><input type="hidden" name="reply" value="' + id + '"><input type="hidden" name="id" value="'+ id2 + '">' + "<div style='float: left' class='comment-check-parent'><input type='checkbox' class='comment-check' name='comment-check'></div><div style='float: left; width: 400px; padding-left: 5px; margin-bottom: 5px'>I understand that submission of this comment is covered by the <a href='http://www.medicalobserver.com.au/about/terms-of-use' target='_blank'>Terms of Use</a> by which I am bound. <a href='http://www.medicalobserver.com.au/about/commenting-rules' target='_blank'>Commenting Rules</a>.</div>" + '<div class="clearAll"></div><input type="submit" class="comment-form-submit" value="Post Reply" style="font-size: 12px"  /></form>';
	$("#comment-" + id + " .comment-display-extra").html(rntText);
	$('.comment-form-reply').submit(function(){ submitCommentForm($(this)); return false;});
}

function validateThread(vv)
{
	if(vv.name.value == "")
	{
		alert("Please provide a name for this thread.");
		
	}
	if(vv.description.value == "")
	{
		alert("Please provide a description for this thread.");
	}
	return true;
}


function doPop(url)
{
   var newwindow=window.open(url,'previewpain','height=720,width=800,scrollbars=yes,resizable=yes');
   if (window.focus)
   	{newwindow.focus()}

}






