$(document).ready(function(){
	$("a[rel^='prettyPhoto']").prettyPhoto({theme:'light_rounded',showTitle: false, opacity: 0.2});
		
	$('input.logininput, textarea.logininput, textarea.orderinput, input.orderinput').focus(function(){
    	$(this).addClass('formfocus');
	}).blur(function(){
    	$(this).removeClass('formfocus');
	});
	
	var validator = $("#orderform").validate({ 
        rules: { 
            ordername: "required", 
            orderemail: { 
                required: true, 
                email: true
            }, 
			orderspurl: { 
                required: true, 
                url: true
            }, 
			ordervdurl: { 
                required: "#parentelement:visible"
            }, 
			agree: "required"
        }, 
        messages: { 
            ordername: "Enter your name", 
            orderemail: { 
                required: "Enter a valid email address", 
                minlength: "Enter a valid email address"
            }, 
			orderspurl: { 
                required: "Enter a valid URL"
            }, 
			ordervdurl: { 
                required: "Enter a valid URL"
            }, 
			agree: "You must accept the Terms of Service and Privacy Policy"
        }, 
       
        errorPlacement: function(error, element) { 
            if ( element.is(":radio") ) 
                error.appendTo( element.parent().next().next() ); 
            else if ( element.is(":checkbox") ) 
                error.appendTo ( element.next() ); 
            else 
                error.appendTo( element.parent() ); 
        }
    }); 

      $("#product2").click(function(){
            $("#vinylextra").show("fast");
      });
	   $("#product1").click(function(){
            $("#vinylextra").hide("fast");
      });
	   $("#install1").click(function(){
            $("#freeinstall, #freeinstall2").show("fast");
      });
	   $("#install2").click(function(){
            $("#freeinstall, #freeinstall2").hide("fast");
      });

});

var loader = jQuery('<div><img src="/img/ajax-loader.gif" alt="loading..." /></div>')
			.appendTo("#contactform")
			.hide();
		jQuery().ajaxStart(function() {
			loader.show();
		}).ajaxStop(function() {
			loader.hide();
		}).ajaxError(function(a, b, e) {
			throw e;
		});
		
		var v = jQuery("#contactform").validate({
			rules: { 
            contactname: "required", 
            contactemail: { 
                required: true, 
                email: true
            }, 
            contactmessage: "required"
       		}, 
			messages: { 
            contactname: "Enter your name", 
            contactemail: { 
                required: "Enter a valid email address", 
                minlength: "Enter a valid email address"
            }, 
            contactmessage: "Enter a message"
        	}, 
       		 errorPlacement: function(error, element) { 
            if ( element.is(":radio") ) 
                error.appendTo( element.parent().next().next() ); 
            else if ( element.is(":checkbox") ) 
                error.appendTo ( element.next() ); 
            else 
                error.appendTo( element.parent() ); 
        	},									
			submitHandler: function(form) {
				jQuery(form).ajaxSubmit({
					target: "#displaymessage",
					success:    function() { 
       				 $("#displaymessage").slideDown("slow");
    				} ,
					clearForm: true
				});
			}
		});
