jQuery.fn.extend({
    center: function () {
        return this.each(function() {
            var top = ($(window).height() - $(this).outerHeight()) / 2 + $(window).scrollTop();
            var left = ($(window).width() - $(this).outerWidth()) / 2 + $(window).scrollLeft();
            $(this).css({position:'absolute', margin:0, top: (top > 0 ? top : 0)+'px', left: (left > 0 ? left : 0)+'px'});
        });
    }
}); 

$(function() {
	// allen Dokument-relativen Ankern die aktuelle URL voran stellen
	var thisLocation = window.location.href;
	$('a[href^="#"]').each(function() {
		$(this).attr('href', thisLocation + $(this).attr('href')); 
	});
});

function showContactForm() {
	var treatmentId = showContactForm.arguments.length > 0 ? showContactForm.arguments[0] : null,
		cityZip     = showContactForm.arguments.length > 1 ? showContactForm.arguments[1] : null,
		clinics     = showContactForm.arguments.length > 2 && $.isArray(showContactForm.arguments[2]) ? showContactForm.arguments[2] : null;
	
	if ($('#contactFormWrapper').length == 0) {
		$('body')
			.append('<div class="ui-widget-overlay" style="z-index:199"></div>')
				.find('div.ui-widget-overlay:last')
				.css({
					width: $(document).width(),
					height: $(document).height()
				})
				.end()
			.append('<div id="contactFormWrapper"></div>')
				.find('#contactFormWrapper')
				.load('/medclinicen/contact/contactform',
					{
						treatmentId: treatmentId,
						cityZip: cityZip,
						clinics: clinics
					},
					function() {
						$('#contactFormWrapper')
							.center()
							.fadeIn()
							.center();
					});
	} else {
		$('#contactFormWrapper')
			.center()
			.fadeIn()
			.center();
	}
}
