(function($){
	/*
	 * Creates a treeview
	 */
    $.fn.w2dplugintreeview = function(options){
		
		var settings = {
			imageURL : './images/',
			evenColor: '#222222',
			evenBackground : '#f0f0f0',
			oddColor: '#ffffff',
			oddBackground : '#46A0C8',
			animate: true
		}
		
		if (options) { 
        	$.extend(settings, options);
      	}
		
		id=this.attr('id');
		
		style="<style type=\"text/css\">";
		style+="#"+id+" .even {background-color: "+settings.evenBackground +";color: "+settings.evenColor+" !important;}\n";
		style+="#"+id+" .odd {background-color: "+settings.oddBackground+"; color: "+settings.oddColor+" !important;}\n";
		style+="#"+id+" .main {padding: 10px;margin-top: 10px;}\n";
		style+="#"+id+" .tvlink {text-decoration: underline;}\n";
		style+="#"+id+" .header {position: relative; line-height: 14px;padding: 1px 4px 1px 20px;font-size: 14px;font-weight: bold;background: url("+settings.imageURL+"w2dplugintvneutral.gif) no-repeat;}\n";
		style+="#"+id+" .plus {background: url("+settings.imageURL+"w2dplugintvplus.gif) no-repeat;cursor: pointer;-webkit-user-select:none;-moz-user-select:none;}\n";
		style+="#"+id+" .minus {background: url("+settings.imageURL+"w2dplugintvminus.gif) no-repeat;cursor: pointer;-webkit-user-select:none;-moz-user-select:none;}\n";
		style+="#"+id+" .inline {float: right;padding: 10px 2px 10px 10px;}\n";
		style+="#"+id+" p.abstract {display: block; padding: 10px 0 !important;position: relative;}\n";
		style+="#"+id+" p.withpicture {margin-right: 160px;}\n";
		style+="#"+id+" .clearer {clear: both;line-height: 1px;height: 1px;}\n";
		style+="</style>"
		
		$('head').append(style);
		
		this.find('.plus').parent().children('.more').hide();
		
		this.find('.plus,.minus').bind('selectstart', function() {return false});
				
		this.find('.header').click(function(){
			if ($(this).hasClass('minus')) {
				$(this).addClass('plus');
				$(this).removeClass('minus');
				if (settings.animate) {
					$(this).parent().children('.more').find('*').css('visibility', 'hidden');
					$(this).parent().children('.more').slideUp(100);
				} else {
					$(this).parent().children('.more').hide();
				}
			} else if ($(this).hasClass('plus')) {
				$(this).addClass('minus');
				$(this).removeClass('plus');
				if (settings.animate) {
					$(this).parent().children('.more').find('*').css('visibility', 'hidden');
					$(this).parent().children('.more').slideDown(100, function() {
						$(this).find('*').css('visibility','visible');
					});
				} else {
					$(this).parent().children('.more').show();					
				}
			}		
		});
	}
})(jQuery);
