$(document).ready(function(){
$(".wpsc_select_variation").each(function(){

var mylist = $(this);
var listitems = mylist.children('option').get();

listitems.sort(function(a, b) {
   var compA = $(a).attr("title").toUpperCase();
   var compB = $(b).attr("title").toUpperCase();
   return (compA < compB) ? -1 : (compA > compB) ? 1 : 0;
});
$.each(listitems, function(idx, itm) { 

	mylist.append(itm); 
});

$(this).val($(this).children('option').first().val());

});

$(".wpsc_select_variation").first().change();

});


// Submit the product form using AJAX
	jQuery("form.product_form, .wpsc-add-to-cart-button-form").live('submit', function() {
		// we cannot submit a file through AJAX, so this needs to return true to submit the form normally if a file formfield is present
		file_upload_elements = jQuery.makeArray(jQuery('input[type="file"]', jQuery(this)));
		if(file_upload_elements.length > 0) {
			return true;
		} else {
			form_values = jQuery(this).serialize();
			// Sometimes jQuery returns an object instead of null, using length tells us how many elements are in the object, which is more reliable than comparing the object to null
			jQuery('input[type=submit]').val("… kaufen");
			
			jQuery.post( 'index.php?ajax=true', form_values, function(returned_data) {
				eval(returned_data);
				jQuery('div.wpsc_loading_animation').css('visibility', 'hidden');

				jQuery('input[type=submit]').val("in den Korb");

			});
			wpsc_fancy_notification(this);
			return false;
		}
	});
	
	$(document).ready(function(){
	
	if($("header").length > 0){
		$("#content_1 h1").html($("header").html());
		$("header").remove();
	}
	
	});
