$(document).ready(
	function() {

		var lang = $('html').attr('lang');
		$('body').addClass('dom '+ lang);

		$('img').attr('title', '');

		$('input, textarea, button').focus(function() {
			$(this).addClass('focus');
		}).blur(function() {
			$(this).removeClass('focus');
		});

		$('#content a.button, #content p.button a, #content button').each(function() {
			$(this).addClass($(this).text());
		});

		$('p#logo').wrapInner('<span></span>');

		var searchLabel = $('label#label-term');
		var searchInput = document.getElementById('term');
		var searchValue = searchLabel.text();
		searchInput.value = searchValue;
		searchInput.onfocus = function() {
			if (this.value == searchValue) this.value = '';
		};
		searchInput.onblur = function() {
			if (this.value == '') this.value = searchValue;
		};
		searchInput.form.onsubmit = function() {
			searchInput.onfocus();
		};

		$('form#searchform button').each(function() {
			$(this).attr('title', $(this).text());
		});

		$('#page').append('<div id="page-footer"><div><p>im Auftrag des Sächsischen Staatsministeriums für Wirtschaft, Arbeit und Verkehr<br /><span xml:lang="en" lang="en">on behalf of the Saxon State Ministry of Economic Affairs, Labor and Transport</span></p><p>Projektträger: RKW Sachsen GmbH Dienstleistung und Beratung<br /><span xml:lang="en" lang="en">Lead organisation: RKW Sachsen GmbH Service and Consulting</span></p></div></div><!-- /footer -->');

		$('ul#first-nav strong').parent('li').addClass('active');

		$('ul#second-nav li.lang a').each(function() {
			$(this).attr('title', $(this).text());
		});

		$('form.inline:has(select)').dropdownmenu();

		// Accordion
		$(".accordion > .link-item, .accordion > dl dt").each(function() {
			$(this).wrapInner('<a href="#"></a>').children().click(function() {
				$(this).parent().toggleClass('open').nextAll("div:first, dd:first").toggleClass('hideme');
				return false;
			}).parent(":not(.open)").nextAll("div:first, dd:first").addClass('hideme');
		});

		// CarnetDB
		$('#first-content #carnetdb .map').before('<p class="fcn"><a href="#">Karte <span>einblenden</span><span style="display: none;">ausblenden</span></a></p>').hide().prev().prev().addClass('fcn');
		$('#first-content #carnetdb p.fcn a').click(function() {
			$(this).parent().next().animate({height: 'toggle', opacity: 'toggle'}, function() {
				$(this).prev().children().children().toggle();
				if($.browser.msie) mapmap1.checkResize();
			});
			return false;
		});
		$('#carnetdb.detail li:has(span)').each(function() {
			$(this).children('span').replaceWith('<a href="#">' + $(this).children('span').text() + '</a>');
			$(this).children('a').click(function() {
				$(this).next().animate({height: 'toggle', opacity: 'toggle'});
				return false;
			}).next().hide();
		});

	}
);
