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

$(document).ready(function(){

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

	Cufon.now();
	Cufon.replace('h2', { fontFamily: 'Formata Medium' });
	Cufon.replace('h2.bold', { fontFamily: 'Formata Bold' });
	Cufon.replace('h3', { fontFamily: 'Formata Medium' });
	Cufon.replace('h3.bold', { fontFamily: 'Formata Bold' });
	Cufon.replace('p.fontswitch', { fontFamily: 'Formata Medium' });
	Cufon.replace('td.salesarea', { fontFamily: 'Formata Bold' });

	var teamnode = $("nav#mainnavigation > ul > li.produkte");

	if( ! teamnode.hasClass("active") ){
		teamnode.hover(
					function(){

						$(this).children("ul").show();
						$(this).find("a.produkte").css({ "background-position" : "0px -24px" });

					},
					function(){
						$(this).children("ul").hide();
						$(this).find("a.produkte").css({ "background-position" : "0px -0px" });

					}
		);
	}

	$('.data tr:odd').addClass('zebra');

	$('a.youtubin').youtubin({
        swfWidth : 650,
        swfHeight : 510
    });

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

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', contactform, false );

function orderform(){

  // Hide forms
  $( 'form.orderform' ).hide().end();

  // Processing
  $( 'form.orderform' ).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.orderform' ).show().end();
}
