$.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(){

	Cufon.now();
	Cufon.replace('h2');

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

	showFormPart();

	$('<p class="top"><img src="/images/project-elements/top-arrow.gif" alt="top" /> <a href="#top">Top</a></p>').appendTo('#maincontent').find('a[href=#top]').click(function(){
		$('html,body').animate( { scrollTop: 0 }, 'fast' );
		return false;
	});
	
	$('<iframe src="http://www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2Fpages%2FResonanz-Online%2F216888671668129&amp;width=292&amp;colorscheme=light&amp;show_faces=false&amp;stream=false&amp;header=false&amp;height=62" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:292px; height:62px;" allowTransparency="true"></iframe>').appendTo('div#innerfblike');

	$('table tr:even').addClass('alt');

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

function showFormPart(){

	$('#invoiceaddress').click(function(){
		$("ol.blockstyle2").toggle().css({'paddingTop': '20px'});

	});

}

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();
}
