var Local = {

    onCommentReply: function(id) {
		Comments.openReply(id);
	},

    onCancelReply: function(id) {
		Comments.closeReply();
	}
	
};

(function($) {
	$(document).ready(
		function() {
			attachments_list()
		}
	)

	function attachments_list() {
		$('ul.all-attachments').each(
			function(i) {
				var this_list = $(this)
				this_list.before(
					$(jQuery('<div />'))
						.addClass('list-container list-container-' + i)
				)
				this_list.children().each(
					function() {
						var name = String($(this).find('a').html())
						var abbr = name.substr(0, name.indexOf('_'))
						if(abbr == 'pl') {
							var category = 'Price List'
						} else if(abbr == 'pr') {
							var category = 'Promotions'
						} else if(abbr == 'dc') {
							var category = 'Documents'
						} else if(abbr == 'rp') {
							var category = 'Reports'
						} else if(abbr == 'img') {
							var category = 'Images'
						} else {
							abbr = 'misc'
							var category = 'Miscellaneous'
						}
						name = name.substr(abbr.length + 1, (name.length - abbr.length - 1))
						$(this).find('a').html(name)
						if(this_list.prevAll('div.list-container-' + i).find('ul.' + abbr).size() == 0) {
							this_list.prevAll('div.list-container-' + i).append(
								$(jQuery('<ul />'))
									.addClass(abbr)
									.click(
										function() {
											$(this).children().not(':first-child').toggle()
										}
									)
									.append(
										$('<li />')
											.html(category)
											.addClass('first-child')
									)
							)
						}
						this_list.prevAll('div.list-container-' + i).find('ul.' + abbr).append(
							$(this)
						)
						$(this).hide()
					}
				)
				this_list.remove()
			}
		)	
	}

})(jQuery);
