$.fn.clearfocus = function() {
	return this.focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
};

/**
 * File Input Fix
 *
 * @author Jann Glasmachers  <glasmachers@gimmixx.de>
 * @copyright 2007 Jann Glasmachers
 */
fixFileInputSize = function (element, reachableWidth){
	if(element.style.width != 'auto'){
		element.style.width = 'auto';
	}

	while (element.offsetWidth < reachableWidth){
		element.size += 1;
	}

	element.size -= 1;
};

$.fn.hoverClass = function(c) {
	return this.each(function(){
		$(this).hover( 
			function() { $(this).addClass(c);  },
			function() { $(this).removeClass(c); }
		);
	});
};	

$(document).ready(function(){

	$("a").focus(function() {
		$(this).blur();
	});

	$("div.clickzone").hover(
		function(){ 
			$(this).addClass('clickzoneactive');
			//$(this).data('background-image', $(this).css('background-image'));
			//$(this).css({ 'background-color' : '#8cb400', 'background-image' : 'none' }); 
			
		}, 
		
		function(){
			//$(this).css({ 'background-color' : 'transparent', 'background-image' : $(this).data('background-image') }); 
			$(this).removeClass('clickzoneactive');
		} 
	);
	
	$(".fadecontent").hover(
		function(){ 
			$(this).not('.active').children('div').fadeIn('fast');		
		}, 	
		function(){
			$(this).not('.active').children('div').fadeOut('slow');
		} 	
	);
	
	$("#subnavigation ul li.ueber-uns,#subnavigation ul li.orthocaps,#subnavigation ul li.patienten-erfolge,#subnavigation ul li.anwender").hover(
		function(){ $("ul", this).show(); }, 
		function() {$("ul", this).hide(); } 
	);
	$("#subnavigation ul li.ueber-uns,#subnavigation ul li.orthocaps,#subnavigation ul li.patienten-erfolge,#subnavigation ul li.anwender").hoverClass("active");

	$('.jswarning').remove();

	$.get("/token/",function(txt){
	  $("form.secured").append('<input type="hidden" name="ts" value="'+txt+'" />');
	});

	$("p#language-opener a").click(function () {
		reference = this;
		$("div#choose-language").slideToggle("slow", function () {
			
		});
	});

});

if( document.addEventListener ) document.addEventListener( 'DOMContentLoaded', contactform, false );

function contactform(){
  // Hide forms
  $( 'form.contactform' ).hide().end();

  // Processing
  $( 'form.contactform' ).find( 'ol.blockstyle>li>label' ).not( '.nogx' ).each( function( i ){
    var labelContent = this.innerHTML;

    var labelWidth = document.defaultView.getComputedStyle( this, '' ).getPropertyValue( 'width' );

    var labelSpan = document.createElement( 'span' );
        labelSpan.style.display = 'block';
        labelSpan.style.width = labelWidth;
        labelSpan.innerHTML = labelContent;
    this.style.display = '-moz-inline-box';
    this.innerHTML = "";
    this.appendChild( labelSpan );
  } ).end();

  // Show forms
  $( 'form.contactform' ).show().end();
}

if( document.addEventListener ) document.addEventListener( 'DOMContentLoaded', faqform, false );

function faqform(){
  // Hide forms
  $( 'form.faqform' ).hide().end();

  // Processing
  $( 'form.faqform' ).find( 'ol.blockstyle>li>label' ).not( '.nogx' ).each( function( i ){
    var labelContent = this.innerHTML;

    var labelWidth = document.defaultView.getComputedStyle( this, '' ).getPropertyValue( 'width' );

    var labelSpan = document.createElement( 'span' );
        labelSpan.style.display = 'block';
        labelSpan.style.width = labelWidth;
        labelSpan.innerHTML = labelContent;
    this.style.display = '-moz-inline-box';
    this.innerHTML = "";
    this.appendChild( labelSpan );
  } ).end();

  // Show forms
  $( 'form.faqform' ).show().end();
}
