jQuery(document).ready(function() {
	
	/**
	 * weiter shoppen button
	 */
	jQuery("#body .order form input").click( function(event) {
		
		if ( jQuery(this).val() == "Weiter shoppen"){
			
			if( jQuery("table.basket tr td .art_title:last a") ){
				window.location.href = jQuery("table.basket tr td .art_title:last a").attr("href");
				return false;
			} else {
				history.back();
				return false;
			}
						
			
		}

	});	
	
	/**
	 * varianten Preis aktualisieren von listen varianten
	 * 
	 */
	jQuery("#body .svarta-varianten .svarta_select_variant_liste").change(function(){
		jQuery("#md_variant_box").html( jQuery(".svarta-varianten-liste #mdvariant_" + jQuery(this).val() ).html() );
	});

	
	/**
	 * variantenpreise aktualiesieren von richtigen Varianten
	 * 
	 */
	if( jQuery("#body .hreview-aggregate .product.details.big form .cost big.price").html() ){

		//remofe price from
		jQuery("#body form .cost big.price span.pricefrom").remove();

		try {
			// required for ie
			var tempPrice = jQuery("#body form .cost big.price:first").text();
			tempPrice = jQuery.trim(tempPrice);
			tempPrice = tempPrice.split(" ");
			
		} catch(err){
			return false;
		}
	
		if( tempPrice[0] ){
			var origPrice = tempPrice[0].replace(",", ".");
		}
				
		jQuery("#body form .variants select").change(function(){
			
			var countVariants = 0;
			
			jQuery("#body form .variants select option:selected").each(function(){
				if( jQuery(this).attr('rel') ){
					countVariants = countVariants + parseFloat( jQuery(this).attr('rel').replace(",", ".") );
				}
			});
			
			if( origPrice ){
				
				var tmp = String(countVariants).split('.');
				var fixcurrency = '.00';
				
				if( tmp[1] && tmp[1].length == 1)
					fixcurrency = '0';
				
				if( tmp[1] && tmp[1].length == 2)
					fixcurrency = '';
				
				
				//jQuery("#body .details form .cost big.price").html( (parseInt(origPrice) + parseInt(countVariants) ) + ' ' + tempPrice[1] );
				jQuery("#body .details form .cost big.price").html( (parseFloat(countVariants) + fixcurrency + ' ' + tempPrice[1]).replace(".", ",") );
			}
			
		});
	}
	
	/**
	 * Captcha entfernen
	 */
	jQuery('#test_verificationCode').parent().parent().remove();
	 
});

