function centsToEur(cents){
	var eur = cents / 100; // cents to euros
	eur = eur.toFixed(2); // two number after .
	return eur.replace('.', ','); // replace . with ,
}

$(function(){
    
    //$(".subcategorie, .subcategorie li a, a").pngfix();
    
    // categorieen
    $(".JQdropdown").hover(
        function () {
        	$("#"+$(this).attr("title")).css({ width:"245px" });
            $("#"+$(this).attr("title")).animate({
              "height": "32px"
            }, {duration: 200, queue: false});
        }, 
        function () {
            $("#"+$(this).attr("title")).animate({
              "height": "0"
            }, {duration: 300, queue: false});
            
            $("#"+$(this).attr("title")).css({ width:"0px" });
        }
    );
    
    // sushi online order
    
    $("#orderForm .row").hover(
        function () {
        	$(this).addClass('hover');
        },
        function () {
            $(this).removeClass('hover');
        }
    );
    
    var prices = Array();
    $("#orderForm .row .coll.amount input").keyup(function (){
    	
    	// vars
    	var id = $(this).attr("id");
    	var validAantal = parseInt($(this).val());
    	var price = $("input[name='price_"+id+"']").val();
    	var totalcents;
    	var subtotal = 0;
		
    	
    	// valid input ?
    	if (isNaN(validAantal)){
    		validAantal = '';
    		cents = '0';
    	}
	
    	// format price
		totalcents = price*validAantal; // calculate
		
		prices[id] = totalcents;
		for (i in prices) {
			subtotal = subtotal + prices[i];
		}
		
		// set views
		$(this).val(validAantal);
    	$("#total_"+id+"").html(centsToEur(totalcents));
    	$("#orderForm .subtotal").html(centsToEur(subtotal));
    	if (subtotal > 0){
    		$("input[name='next']").fadeIn();
		}
		else{
			$("input[name='next']").fadeOut();
		}
    });
    
    $("#orderForm .row .coll.img img").hover(
    	function () {
	    	$("#orderForm .row .coll.img .lightImage").hide();
	    	$("#lightImage_"+$(this).attr("id")+"").fadeIn('fast');
    	},
    	function (){
    		$("#orderForm .row .coll.img .lightImage").hide();
    	}
	);
});