$(document).ready(function(){ /* * Deal with the image boxes */ // assign a hover event handler to all the boxes $('.image').hover(function(){ // get the classname of the hovered item var cn = $(this).attr("class"); // loop over all the boxes $('.image').each(function(){ // if the box is not the one hovered if($(this).attr("class") != cn) { // reduce the width of the box $(this).animate({width:"192px"},400); } }); // increase the width of the selected box $(this).animate({width:"300px"},400); }, function(){ // do nothing on hover out }); /* * Deal with the request form */ // need to encapsulate all the form stuff in a function // so that it works after the ajax call var bindRequestForm = function() { // when the box is clicked get rid of the placeholder text $('#brochureForm #email_sec').click(function(){ if(this.value == 'Your Email Address') { this.value = ''; } }); // if nothing is entered add the placeholder text $('#brochureForm #email_sec').blur(function(){ if(this.value == '') { this.value = 'Your Email Address'; } }); $('#brochureForm').submit(function(){ // init var inputs = []; // loop through form inputs $(':input', this).each(function(){ // grab the form data inputs.push(this.name + '=' + this.value); }); // create ajax request $.ajax({ type: "POST", url: "/includes/sec_quote.inc.php", data: inputs.join("&"), success: function(msg){ // save the response $('#secContent').html(msg); // rebind all the javascript bindRequestForm(); } }); return false; }); } // execute the request form javascript bindRequestForm(); /* * Deal with the login form */ // need to encapsulate all the form stuff in a function // so that it works after the ajax call var bindLoginForm = function() { // when the box is clicked get rid of the placeholder text $('#loginForm #username').click(function(){ if(this.value == 'Your Username') { this.value = ''; } }); // if nothing is entered add the placeholder text $('#loginForm #username').blur(function(){ if(this.value == '') { this.value = 'Your Username'; } }); // when the box is clicked get rid of the placeholder text $('#loginForm #password').click(function(){ if(this.value == 'Your Password') { this.value = ''; } }); // if nothing is entered add the placeholder text $('#loginForm #password').blur(function(){ if(this.value == '') { this.value = 'Your password'; } }); // add on submit event handler $('#loginForm').submit(function(){ // init var inputs = []; // loop through form inputs $(':input', this).each(function(){ // grab the form data inputs.push(this.name + '=' + this.value); }); // create ajax request $.ajax({ type: "POST", url: "/includes/sec_login.inc.php", data: inputs.join("&"), success: function(msg){ // save the response $('#secContent').html(msg); // rebind all the javascript bindLoginForm(); } }); return false; }); } // execute the login form javascript bindLoginForm(); /* * Deal with the contact form */ // need to encapsulate all the form stuff in a function // so that it works after the ajax call var bindContactForm = function() { // hide loading graphic on startup $('.loading').hide(); // add a submit event handler $('#contactForm').submit(function(){ // init var inputs = []; // loop through form inputs $(':input', this).each(function(){ // grab the form data inputs.push(this.name + '=' + this.value); }); // create an ajax request $.ajax({ type: "POST", url: "/includes/contact.inc.php", data: inputs.join("&"), success: function(msg){ // save the ajax response $('.contact_form').html(msg); // rebind all the javascript bindContactForm(); } }); // show loading graphic on ajaxstartup $(".loading").ajaxStart(function(){ $(this).show(); }); // hide loading graphic on ajaxstop $(".loading").ajaxStop(function(){ $(this).hide(); }); // return false so that form does not submit return false; }); } // execute the contact form javascript bindContactForm(); });