var logoSpeed = 2000;
var logoDelay = 10000;

$(function() {
	$('a#news').attr('href', '/news/2012-02-09-1.xhtml');
	$('#sidebar #news-index').load('/news/news-index.xhtml');
	//$('#sidebar #news').load('/news/news.xhtml');
	$.get('/news/news.xhtml', function(response){$('#sidebar #news').html(response); $("#archiv").accordion({ header: "h2", autoHeight: false }); $("div h3.sidebar:first-child").css("padding", "0 0 0"); $("h2.sidebar").css("color", "#183000");});
	$('.logo').cycle({fx: 'fade', speed: 2000, timeout: 10000});
	$('.homepics').cycle({fx: 'shuffle', timeout: 8000, pause: 1, random: 1, next: '.homepics', after: onHomePicsAfter});
	$('#contact_ok').hide();
	$('.contact_line input:text, .contact_line textarea').bind('focus', focusContact).bind('blur', blurContact);
	$('.land-use, .population-development, .election').bind('click', showLargeImage);
		
});

var blurContact = function(event) {
	$(event.target).css({backgroundColor: '#d8d8c0', border: '1px solid #cacca2'});
};

var focusContact = function(event) {
	$(event.target).css({backgroundColor: 'white', border: '1px solid #907848'});
};

var showLargeImage = function(event) {
	$.slimbox($(event.target).parents('table:first').attr('href'), $(event.target).parents('table:first').attr('title'));
};

var showContactOkBox = function() {
	$('#contact_ok').slideDown(1000);
};

function onHomePicsAfter() {
	$('.homepics-description .label').html(this.title);
	$('.homepics-description .source').html(this.alt);
};

function sendContactMessage() {
	if ($('.contact_line #givenname').attr('value') == '') {
		alert('Bitte geben Sie Ihren Vornamen ein!');
		$('contact_line #givenname').get(0).focus();
		return;
	}
	if ($('.contact_line #name').attr('value') == '') {
		alert('Bitte geben Sie Ihren Nachnamen ein!');
		$('contact_line #name').get(0).focus();
		return;
	}
	if ($('.contact_line #email').attr('value') == '') {
		alert('Bitte geben Sie Ihre E-Mail-Adresse ein!');
		$('contact_line #email').get(0).focus();
		return;
	}
	if ($('.contact_line #comment').attr('value') == '') {
		alert('Bitte geben Sie eine Nachricht ein!');
		$('contact_line #comment').get(0).focus();
		return;
	}
	var hiddenFormContent = $('#contact_iframe').contents(); 
	$('.contact_line :input').each(function(n) {
		hiddenFormContent.find(':input[name=' + this.name + ']').get(0).value = this.value;
	});
	hiddenFormContent.find('form').get(0).submit();
	$('#contact_box').slideUp(3000, showContactOkBox);
};

