Cufon.replace('#main h1, .heading strong, .heading h2');

$.fn.placeholder = function() {
    return this.each(function() {
        var oldval = $(this).val();
        
        $(this).focus(function() {
            if($(this).val() == oldval) {
                $(this).val('');
            }
        });
        $(this).blur(function() {
            if($(this).val() == '') {
                $(this).val(oldval);
            }
        });        
    });
}

$(function(){
	// Produktboxen können als ganzes angeklickt werden
	$('.product').click(function() {
		var productLink = $(this).find('.heading a').attr('href');
		if(productLink != undefined) {
			window.location.href = 'http://' + window.location.hostname + '/' + productLink;
		} else return false;
	});
	
	//Checkbox-Validierung im Gratisproben-Formular nach Absenden
	/*$('.mailformplus_contactform .submit').click(function(){
	if($('.checkbox:checked').length > 2) {
	  alert('Es können maximal 2 Gratisproben angefordert werden.');
	  return false;
	}
		else return true;
	});*/
	// Rahmen des jeweils ersten Boxelements ausblenden
	$('body:not([class^="company"]) .block:first-child').css('border','0');
	// Vorteile Wechsler
	contentToggler();
	// Wechseltabellen
	zebraTables();
	// Blur der Suchbox
	$('#search').find('.text').placeholder();
	// more-Text für Shopinfo
	shopinfo();
	// Globale Fehlermeldung im Shop
	globalizeShopErrors();
});

var zebraTables = function() {
	$('table.naehrwerte').each(function(){
		$(this).find('tr:odd').addClass('odd');
	});
};

var contentToggler = function() {
	var oldHtml = $('.content-toggler').html();
	$('.content-toggler').parents('p').next().hide();
	$('.content-toggler').bind('click', function(ev){
		ev.preventDefault();
		
		$('.content-toggler').parents('p').next().hide();
		$(this).parents('p').next().show();
		
		$('.content-toggler').html(oldHtml);
		$(this).html('▼');
	});
}

var shopinfo = function() {
	$('.com-single .more-text').hide();
	$('.com-single .more').click(function(ev) {
		ev.preventDefault();
		$(this).hide().parent().next('.more-text').show();
	});
}

var globalizeShopErrors = function() {
	if(!$('.tx-commerce-pi3 .error').text().length) return;
	
	var errorText = 'Ihr Angaben sind nicht vollständig, bitte überprüfen Sie diese.',
		errorHtml = $('<p  class="global-error">'+ errorText +'</p>').hide();
	
	$('.tx-commerce-pi3').prepend(errorHtml);
	$('.global-error').fadeIn(1200);
}


