// JavaScript Document 
$(function(){ 
	
	// Supersubs / Superfish Dropdown Menu
	$("ul.sf-menu").supersubs({ 
	minWidth:    12,   // minimum width of sub-menus in em units 
	maxWidth:    27,   // maximum width of sub-menus in em units 
	extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
					   // due to slight rounding differences and font-family 
	}).superfish();  // call supersubs first, then superfish, so that subs are 
					 // not display:none when measuring. Call before initialising 
					 // containing tabs for same reason. 
					 
	// innerfade - http://medienfreunde.com/lab/innerfade/   
	$('#fader').innerfade({ speed: 700, timeout: 4000, type: 'sequence', containerheight: '383px' });
	$('#client').innerfade({ speed: 700, timeout: 4000, type: 'sequence', containerheight: '90px' });

	
	// form validate - http://docs.jquery.com/Plugins/Validation
	$("#m227e0moduleform_1").validate({
            rules:{
                m227e0fbrp__29: "required",  // first name
                m227e0fbrp__30: "required",  // last name
                m227e0fbrp__31: {            // email
                    required:   true,
                    email:      true
                },
                m227e0fbrp__34: "required"   // message
            },

            messages:{
                m227e0fbrp__29: "Please enter your first name",
                m227e0fbrp__30: "Please enter your last name",
                m227e0fbrp__31: {
                    required:   "Please enter your email address",
                    minlength:  "Please enter a valid email address"
                },
                m227e0fbrp__34: "Please enter your message"
            },

//            submitHandler: function() {
//                alert('hello');
//            },

            errorPlacement: function(error, element) {
                var li = $("<li></li>");
                error.appendTo(li);
                element.parent().after(li);
            }

        });



        ///// format the main navigation]
        $('#mainNav li:not(.minor).depth_1 > a').each(function(){
            var html = $(this).html();
            var tokens = html.split(' ');

            // replace the last space with <br />
            var new_html = "";

            if (tokens.length > 1)
            {
                for (var i = 0; i < tokens.length; i++)
                {
                    var glue = " ";
                    if (i == tokens.length - 1)
                    {
                        glue = "<br />";
                    }
                    new_html = new_html + glue + tokens[i];
                }
            }
            else
                new_html = html;

            $(this).html(new_html);
        });


}); 
 
