$(document).ready(function(){

	//#nav - keep hover class on sub menu expand ************************
	$('#nav li:has("ul")').each(function(){

		var class_hover = $(this).attr('class')+'-hover';

		$(this).children('ul').hover(
			function () {
				$(this).parent('li').addClass(class_hover);
			},
			function () {
				$(this).parent('li').removeClass(class_hover);
			}
		);
	});
	
	
	//min-width of li ul
	//$('#nav li:has("ul")').each(function(){
	//	$(this).children('ul').css('minWidth', $(this).outerWidth());
	//});

	//show/hide any container. Use rel='show-hide' in a link, and use the title tag to specify the ID of the box to hide/show. ************************
	$('a[rel=show-hide]').each(function (event) {
		$($(this).attr("href")).hide(); //hide with js (not css), so non-js browsers will see the content
	}).click(function (event) {
		$($(this).attr("href")).slideToggle(400);
		return false;
	});

	//email nospam ************************
	$('a.email').nospam({replaceText: true, filterLevel: 'low'});

	//external links ************************
	$('a[rel*=external]').click( function() {
		window.open(this.href);
		return false;
	});

	//external target on forms ************************
	$('form._blank').submit(function() {
		this.target = '_blank';
	});

});

/* Functions
-------------------------------------------------------------- */
//defaultValue for inputs
(function($){
	$.fn.clearDefault = function(){
		return this.each(function(){
			var default_value = $(this).val();
			$(this).focusin(function(){
				if ($(this).val() == default_value) { $(this).val(""); }
			}).focusout(function(){
				if ($.trim($(this).val()) == "") { $(this).val(default_value); }
			});
		});
	};
})(jQuery);


/* Plugins
-------------------------------------------------------------- */
// http://www.leftrightdesigns.com/library/jquery/nospam/
jQuery.fn.nospam=function(settings){settings=jQuery.extend({replaceText:false,filterLevel:'normal'},settings);return this.each(function(){e=null;if(settings.filterLevel=='low'){if($(this).is('a[rel]')){e=$(this).attr('rel').replace('//','@').replace(/\//g,'.');}else{e=$(this).text().replace('//','@').replace(/\//g,'.');}}else{if($(this).is('a[rel]')){e=$(this).attr('rel').split('').reverse().join('').replace('//','@').replace(/\//g,'.');}else{e=$(this).text().split('').reverse().join('').replace('//','@').replace(/\//g,'.');}} if(e){if($(this).is('a[rel]')){$(this).attr('href','mailto:'+e);if(settings.replaceText){$(this).text(e);}}else{$(this).text(e);}}});};
