/* Vertigro */
(function($){$.fn.vertigro=function(){return this.filter('textarea').each(function(){var grow=function(e){var h=parseInt($(this).css('lineHeight'))||20;if(this.clientHeight<this.scrollHeight)$(this).height(this.scrollHeight+h+'px');};$(this).css('overflow','hidden').bind('keydown keyup change',grow).keyup();});};})(jQuery);

function removeMSWordChars(str) {
	var myReplacements = new Array();
	var myCode, intReplacement;
	myReplacements[8216] = 39;
	myReplacements[8217] = 39;
	myReplacements[8220] = 34;
	myReplacements[8221] = 34;
	myReplacements[8212] = 45;
	for(c=0; c<str.length; c++) {
		var myCode = str.charCodeAt(c);
		if(myReplacements[myCode] != undefined) {
			intReplacement = myReplacements[myCode];
			str = str.substr(0,c) + String.fromCharCode(intReplacement) + str.substr(c+1);
		}
	}
	return str;
}

$(function(){
	$('textarea.expanding').vertigro();	
	
	$('#MainNav a').hover(
		function(){
			var $this = $(this);
			clearTimeout($this.data('removeHoverTimer'));
			$this.addClass('hover');
		},
		function(){
			var $this = $(this);
			var removeHover = function(){
				$this.removeClass('hover');
			};
			$this.data('removeHoverTimer',setTimeout(removeHover,150));
		}
	);
	$(".showHideLink").click(function(){
		var targetDiv = $(this).parent().parent().find(".hideMe");
		if(targetDiv.is(":visible")) {
			$(this).parent().parent().find(".hideMe").slideToggle('slow');
			$(this).html('<br><a href="#" class="showHideLink">Out Of My Way!</a>');
			$(this).html('<br><a href="#" class="showHideLink">Ok, Come Back!</a>');
		}
		else {
			$(this).parent().parent().find(".hideMe").slideToggle('slow');
			$(this).html('<br><a href="#" class="showHideLink">Out Of My Way!</a>');
		}
		
		return false;
	});
	
	$("#RssImage").hover(
		function() {
			
			$("#RssHover").stop(true, true).fadeIn('fast');
		},
		function() {
			$("#RssHover").stop(true, true).fadeOut();
		}
	);
	
	$("#FixMsWordChars").click(function(){
		$("textarea.msWord").each(function(){
			$(this).val(removeMSWordChars(this.value));
		});
	});
	
	$("textarea.msWord").val(String.fromCharCode(8220) + " This is only a test, this has the leaning quotes, see them? " + String.fromCharCode(8221) + "It might depend on your browser whether you see them curl here.");
	
	
	$(" #nav ul ").css({display: "none"}); // Opera Fix
	$(" #nav li").hover(function(){
			$(this).find('ul:first').css({visibility: "visible",display: "none"}).show(400);
			},function(){
			$(this).find('ul:first').css({visibility: "hidden"});
			});

	
	
});