$('document').ready(function() {
	$('#logo, .thumb').fadeTo(0, 0.8).hover(function() {
		$(this).fadeTo(100, 1);
	}, function() {
		$(this).fadeTo(200, 0.8);
	});
	
	$('.orderbutton').click(function() {
		show_form();
		
		return false;
	});
	
	init();
});

function init() {
	$('a[rel=external]').attr('target', '_blank');
	
	$('.hide').hide().removeClass('hide');
	
	$('a.ajax').unbind('click').click(function() {
		var element = $(this);
		var target = $(this).attr('href');
		
		$(this).addClass('inactive');
		
		$.getJSON(target, function(reply) {
			if(reply.result=='success') {
				eval(reply.callback);
			} else alert(reply.message);
		
			$(this).removeClass('inactive');
		});
	
		return false;
	});
}

function show_form() {
	$('.orderform').slideDown().find('input:eq(0)').focus();
	
	$('.orderform input[name=Fotoflat]').change(function () {
		if($(this).attr("checked")) $(this).parent().next().slideDown().next().slideDown();
		else $(this).parent().next().slideUp().next().slideUp();
	});
	
	$('.orderbutton').val('Bestellung absenden').unbind('click').click(function() {
		$('.orderform form').submit();
	});
	
	return false;
}
