$(document).ready(function()
{
	$('.items').bind('check', null, function()
	{
		var price      = parseFloat($(this).attr('price'));
		var totalPrice = parseFloat($('#total-price').val());
		
		totalPrice += price;
		totalPrice = Math.round(totalPrice * 100) / 100;
		totalPrice = totalPrice.toString().substring(0, 5);
		var iDotPos = totalPrice.indexOf('.');

        if (iDotPos == -1)
		{
			totalPrice += '.00';
		}
		else
		{
			var sDec = totalPrice.substr(iDotPos + 1);
			if (sDec.length == 1)
			{
				totalPrice += '0';
			}
		}
		$('#total-price').val(totalPrice);
		$('.total-price').html(totalPrice);
	}).bind('uncheck', null, function()
	{
		var price      = parseFloat($(this).attr('price'));
		var totalPrice = parseFloat($('#total-price').val());

		totalPrice -= price;
		
		if ( totalPrice < 0 )
		{
			totalPrice = 0;
		}
		totalPrice = Math.round(totalPrice * 100) / 100;
		totalPrice = totalPrice.toString().substring(0, 5);
		var iDotPos = totalPrice.indexOf('.');

        if (iDotPos == -1)
        {
            totalPrice += '.00';
        }
        else
        {
            var sDec = totalPrice.substr(iDotPos + 1);
            if (sDec.length == 1)
            {
                totalPrice += '0';
            }
        }
		$('#total-price').val(totalPrice);
		$('.total-price').html(totalPrice);
	});
	
	


	$('#items-form').submit(function()
	{
		var aErrors = new Array();
		
		if ( $('input.items:checked').size() == 0 )
		{
			aErrors.push('Please select at least one item');
		}
		
		var sFullName   = $('input[name=full_name]').val();
		var sEmail      = $('input[name=email]').val();
		var phoneNumber = $('input[name=phone]').val();	
		
		if ( sFullName == '' )
		{
			aErrors.push('Please enter your full name');
		}
		
		if ( sEmail == '' )
		{
			aErrors.push('Please enter your email address');
		}
		
		if ( phoneNumber == '' )
		{
			aErrors.push('Please enter your phone number');
		}
		
		if ( aErrors.length == 0 )
		{
			return true;
		}
		else
		{
			$('.b-errors').html(aErrors.join('<br />'));
		}
		
		return false;
	});

	
	$('input:checkbox').checkbox(
	{
		empty: '/breakfast/skin/site/main/img/empty.gif'
	});
});
