$(document).ready(function() {
    $('a.add-to-basket').click(function(e) {
        e.preventDefault();
        var form = $(e.target).closest("form").submit();
    });
    
    $('a.reload-basket').click(function(e) {
        e.preventDefault();
        var form = $(e.target).closest("form").submit();
    });
    
    $('div.productitem>form').submit(function() {
        var options = {
                success:       onAddToBasket  // post-submit callback 
                // other available options: 
                //target:    target,   // target element(s) to be updated with server response 
                //url:       url         // override for form's 'action' attribute 
                //type:      type        // 'get' or 'post', override for form's 'method' attribute 
                //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
                //clearForm: true        // clear all form fields after successful submit 
                //resetForm: true        // reset the form after successful submit 
                //beforeSubmit:  bla,  // pre-submit callback 
                
                // $.ajax options can be used here too, for example: 
                //timeout:   3000 
        };
        $(this).ajaxSubmit(options);
        return false; 
    });
    
    $('a.weitereinfos').click(function(e) {
        e.preventDefault();
		$('.productlist.open').removeClass('open').children().first().slideUp(200);
        var pl = $(e.target).closest('.productlist');
		pl.addClass('open');
        var rezept = pl.children().first();
        rezept.slideDown(300);
    });
	
    var plist = $('.productlist:last'),
		addMargin = function(e) {
			plist.addClass('lastOpenProduct');
		};
	
	plist.find('a.weitereinfos').click(addMargin);
	plist.prev().find('a.weitereinfos').click(addMargin);
    
    $('.rezept>a').click(function(e) {
        e.preventDefault();
        var pl = $(e.target).closest('.productlist');
		pl.removeClass('open');
        var rezept = pl.children().first();
        rezept.slideUp(200);
    });
    
    $('#showAddress1').change(function(event) {
        $('#address_1').slideToggle(600);
    });
	
	/*if ($('#email_del').length > 0) {
		function validEmail(value){
			return /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i.test(value);
		}
	
		$('form').submit(function(e) {
			
			if (!validEmail(e.target.email_del.value)) e.preventDefault();
			
		});
		
	}*/
	
});

function onAddToBasket(responseText, statusText, xhr, $form)  { 
    var r = $form.find('.basket-confirm');
    r.show('fast', function() {
       // $(this).hide(1500);
	   $(this).siblings('input[name=amount]').attr('value', 0);
    });
    r.html(responseText);
}

(function($){

var docBody = $(document.body),
	contentinner = $('#contentinner'),
	contentinnerHeight = contentinner.height(),
	fixHeight = function(){
		var bHeight = docBody.height(),
			cHeight = (bHeight > contentinnerHeight) ? bHeight : contentinnerHeight;
		
		contentinner.css('min-height', cHeight - 65);
	};

$(window).bind('resize', fixHeight);
$(window).bind('load', fixHeight);

})(jQuery);





