/*
	NMS Collapse v1.0
	Created by: Steven Monetti
	Last modified: 01/23/2009
	
	
	Functionallity: It automatically hides a div tag and show an arrow simbol to toggle it open and close.
	
*/
(function($) {

$.fn.nms_collapse = function(options) {
	
	//Options
	var defaults = {  
		effect: '',
		speed: '' 
	};  
	
	var options = $.extend(defaults, options); 
	

	//Begin plugin
	return this.each(function() {
		
		// HTML replacement
		var content_html = $(this).html();
		var title = $(this).attr('title'); 		
		var replace_html = '\
			<div class="nms_collapse_container"> \
				<div class="nms_collapse_img closed"></div> \
				<div class="nms_collapse_title"><a>'+title+'</a></div><br class="ciao">\
				<div class="nms_collapse_content">'+content_html+'</div> \
			</div> \
		';
		
		// Replace HTML
		$(this).replaceWith(replace_html);
		
		// Arrow image functionallity (show/hide)
		var toggled = false;
		$('.nms_collapse_title').click(function(){
			if(!toggled) {
				toggled = true;
				$(this).prev().attr('class','nms_collapse_img open');
				if(options.effect == 'slide') $(this).next().next().slideDown(options.speed);
				else $(this).next().next().show(options.speed);
			}
			else {
				toggled = false;
				$(this).prev().attr('class','nms_collapse_img closed');
				if(options.effect == 'slide') $(this).next().next().slideUp(options.speed);
				else $(this).next().next().hide(options.speed);
			}
		});
		
	});

};


})(jQuery);
