/**
 * @author Evil Buck <buck2769@gmail.com> 2010.06.18
 */

// Pseudo namespace to avoid collisions
var App = (function($){
    var app = {};

    app.init_payment_form_validation = function(){
        var rules,
            _form = $('#billing-info');


        rules = {
            'enox_shopping_order__billing_first_name': 'required',
            'enox_shopping_order__billing_last_name': 'required',
            'enox_shopping_order__billing_address1': 'required',
            'enox_shopping_order__billing_city': 'required',
            'enox_shopping_order__billing_state': 'required',
            'enox_shopping_order__billing_zip5': {
                required: true,
                minlength: 5,
                maxlength: 5,
                digits: true
            },
            'User[email]': {
                required: true,
                email: true
            }/*,
            'enox_shopping_order__billing_phone': {
                required: true,
                phoneUS: true
            }*/
        };

        _form.validate({
            submitHandler: function(form){
                form.submit();
                return false;
            },
            rules: rules,
            invalidHandler: function(form, validator) {
                $('label.error').remove();
            },
            errorPlacement: function(error, element) {
                element.addClass('error').after(error);
            }
        });
    };

	app.init_product_links = function() {
		$('#feature .product').each(function(){
			var _this = $(this);
			_this.click(function(){
				window.location.href = _this.find('a').attr('href');
			});
		});
	};
	
	app.init_flashing_promotion = function() {
	    $('#promotion').effect('pulsate');
	};

    return app;
}(jQuery));

jQuery(function(){
    App.init_payment_form_validation();
	App.init_product_links();
	App.init_flashing_promotion();
});

