//=========================================
// ShowHide
//=========================================

(function($){  
$.fn.flowToggle = function(options) {  

	var defaults = {
		showHideSelector : ".flowShowHide",
		toggleText : "",
		toggleTextAfter : "",
		hideToggle : false
	}; 
	
	var o = $.extend(defaults, options);  
	
	$(o.showHideSelector).hide();
	
	var toggle = $(this);
	
	var toggleHtmlText = $(this).html();
	
	if(toggleHtmlText != ""){
		o.toggleText = toggle.html();
	}
	
	//insert the toggle text
	if(o.toggleText != ""){
		$(this).html(o.toggleText);
	}
	

	toggle.click(function(){
		clickedToggle = $(this);
		$(this).siblings(o.showHideSelector).slideToggle("slow", changeToggleText);
		return false;
	});

	function changeToggleText(){
		if(o.hideToggle){
			clickedToggle.hide();
		}

		if(o.toggleTextAfter!=""){
			if($(this).is(":visible")){
				clickedToggle.html(o.toggleTextAfter);
			}
		};

		if(o.toggleText!=""){
			if(!$(this).is(":visible")){
				clickedToggle.html(o.toggleText);
			}
		};	
	}
	
	
};
})(jQuery);

(function($){
	/**
	* jQuery delayed event execution.
	*/
	$.fn.delay = function(options) {
		var timer;
		var delayImpl = function(eventObj) {
			if (timer != null) {
				clearTimeout(timer);
			}
			var newFn = function() {
				options.fn(eventObj);
			};
			timer = setTimeout(newFn, options.delay);
		}

		return this.each(function() {
			var obj = $(this);
			obj.bind(options.event, function(eventObj) {
				delayImpl(eventObj);  
			});
		});
	};
})(jQuery);



