var DownloadsManager = jQuery.inherit({

	shownElement : undefined,

	__constructor : function() {
		var myObj = this;
		myObj.hideAllDescriptions();
		
		jQuery('.downloaditem-caption').each(function() {
			var element = jQuery(this);
			
			descriptionId = this.id.replace('-caption-', '-description-');
			descriptionElement = jQuery('#' + descriptionId);
			
			if (jQuery.trim(descriptionElement.html()).length == 0) {
				return;
			}
			element.html(element.html() + ' <span>mehr Infos</span>');
			element.css('cursor', 'pointer');			
			element.click(function() {

				showId = this.id.replace('-caption-', '-description-');
				showElement = jQuery('#' + showId);
				
				if (myObj.shownElement != undefined && showElement.attr('id') == myObj.shownElement.attr('id')) {
					showElement.slideUp();
					myObj.shownElement = undefined;
					return;
				}
				
				if (myObj.shownElement != undefined) {
					myObj.shownElement.slideUp();
				}
				
				showElement.slideDown();
				myObj.shownElement = showElement; 
			});
			
			
			jQuery('.downloaditem-description').click(function() {
				this.slideUp();
			});		
		});

	},

	hideAllDescriptions : function() {
		jQuery('.downloaditem-description').each(function() {
			var element = jQuery(this);
			element.hide();
		});	
	}
});

jQuery(document).ready(function() {
	var downloads = new DownloadsManager();
});