/**
 * Einträge markieren bzw. Markierung aufheben
 **/
function mark_entries(name, action)
{
	var fields = $('form :checkbox');

	jQuery.each(fields, function() {
		if ($(this).attr('name') == name + '[]') {
			if (action == 'add') {
				$(this).attr('checked', 'checked');
			} else {
				$(this).removeAttr('checked');
			}
		}
	});
}

jQuery(function($) {
	// Zu Browserupdate raten
	if (!jQuery.support.boxModel) {
		$('#ie-6').show();
	}

	var curSelected = $('#header ul.navigation-main > li > a.selected');

	// Verschachtelte Navigation
	$('#header ul.navigation-main > li:has(ul)').hover(function() {
		if (!$(this).children('ul').is(':animated')) {
			$('#breadcrumb, #download-latest').animate({ opacity: 'hide' }, 'fast');
			$(this).children('ul').animate({ opacity: 'show' }, 'normal');
			if (!$(this).children('a').is('.selected')) {
				curSelected.removeClass('selected').css({ color: '#000' });
			}
			$(this).children('a').addClass('selected').css({ color: '#c30' });
		}
	}, function() {
		$(this).children('ul').animate({ opacity: 'hide' }, 'fast');
		$(this).children('a').removeClass('selected').css({ color: '#000' });
		curSelected.addClass('selected').css({ color: '#c30' });
		$('#breadcrumb, #download-latest').animate({ opacity: 'show' }, 'normal');
	});

	$('#sidebar > ul.admin > li:has(ul) > a, #sidebar > ul.navigation-sidebar > li:has(ul) > a').click(function() {
		if (!$(this).next('ul').is(':animated')) {
			$(this).next('ul').slideToggle('slow');
		}
		return false;
	});

	// jQuery UI Tabs
	$('#tabs').tabs({ cookie: { expires: 30 }});

	$.fn.clearForm = function() {
		return this.each(function() {
			var type = this.type, tag = this.tagName.toLowerCase();
			if (tag == 'form')
				return $(':input',this).clearForm();
			if (type == 'text' || type == 'password' || tag == 'textarea')
				this.value = '';
			else if (type == 'checkbox' || type == 'radio')
				this.checked = false;
			else if (tag == 'select')
				this.selectedIndex = -1;
		});
	};

	$('#sidebar :submit, #content :submit, #content :reset').each(function() {
		var type = $(this).attr('type') == 'submit' ? 'form-submit' : 'form-reset';
		$(this).replaceWith('<a href="#' + type + '" class="form">' + $(this).val() + '</a>');
	});
	$('a.form').each(function() {
		$(this).attr('class', 'button');
		$(this).prepend('<span class="button-left"></span>');
		$(this).append('<span class="button-right"></span>');
	});

	$('a.button').click(function() {
		if ($(this).attr('href') == '#form-submit') {
			$(this).closest('form').submit();
			return false;
		} else if ($(this).attr('href') == '#form-reset') {
			$(this).closest('form').clearForm();
			return false;
		}
		return true;
	});
})