
$(document).ready(function() {
	
	if (typeof backend == 'undefined') {
		Cufon.replace('#ContentContainer h1, #ContentContainer h2');
	}
	
	var $serachBox = $('#SearchInput');
	var searchLabel = 'Suche';
	
	$serachBox.focus(function() {
		if ($(this).val() == searchLabel) {
			$(this).val('').removeClass('Inactive');
		}
	}).blur(function() {
		if ($(this).val() == '' || $(this).val() == searchLabel) {
			$(this).val(searchLabel).addClass('Inactive');
		}
	}).blur();
	
	// make downloads box clickable
	$('#ContentContainer div.Download').click(function(e) {
		if (!$(e.target).is('a')) {
			window.open($(this).find('a:first').attr('href'));
		}
	}).css('cursor', 'pointer');
	
	// mini contact form
	var name = $('#MiniFormName');
	var phone = $('#MiniFormPhone');
	var zip = $('#MiniFormZip');
	var subject = $('#MiniFormSubject');
	var submit = $('#MiniFormSubmit');
	
	submit.click(function() {
		var nameVal = $.trim(name.val());
		var phoneVal = $.trim(phone.val());
		var subjectVal = $.trim(subject.val());
		var zipVal = $.trim(zip.val());
		
		if (nameVal == '') {
			alert('Bitte geben Sie Ihren Namen ein.');
			return false;
		}
		
		if (phoneVal == '') {
			alert('Bitte geben Sie Ihre Telefonnummer ein.');
			return false;
		}
		
		if (zipVal == '') {
			alert('Bitte geben Sie Ihre PLZ ein.');
			return false;
		}
		
		var form = $('#MiniForm').addClass('Submitted');
		form.html('Bitte warten...');
		
		$.post('includes/ezajax/ezajax.php', {
			className: 'Content_MiniForm',
			method: 'submit',
			name: nameVal,
			phone: phoneVal,
			subject: subjectVal,
			zip: zipVal
		}, function() {
			form.html('Ihre Anfrage wurde abgeschickt.<br />Vielen Dank!');
		});
	});
	
});

