		$(function() {
			bgImageTotal=5;
			randomNumber = Math.round(Math.random()*(bgImageTotal-1))+1;
			imgPath=('graphx/bg'+randomNumber+'.jpg');
			$('body#homepage, body#landing-page').css('background-image', ('url("'+imgPath+'")'));
			
			$('#glossary-terms dd:first').show();
			$('#glossary-terms dt').click(function () { 
      			$(this).next('dd').slideToggle().siblings('dd:visible').slideUp();
    		});
			
			///////////////// Login/Registration div switching ////////
			
			$('#displayLogin').click(function(){
				$('#login-box').css('display','');
				$('#contactForm').css('display','none');
			});
			
			$('#displayForm').click(function(){
				$('#login-box').css('display','none');
				$('#contactForm').css('display','');
			});
			
			$('.recordDownload').click(function() {
				
				$.post("../trackResourceDownload.php", { type : $(this).attr('rel'), title : $(this).attr('id') } );
			});
			
		});
		
		//Display other div if other is selected in forms //////
		function displayMedAppOther(selectedValue) {
			if(selectedValue == "Other") {
				$(function() {$('#otherFormDiv').css('display','');});
			} else {
				$(function() {$('#otherFormDiv').css('display','none');});
			}
		}
		
		//Validate emial
		function isEmail (s) {
			var isEmail_re       = /^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/;
			return String(s).search (isEmail_re) != -1;
		}

		function validateRadioButton(aform,name,message) {
			myOption = -1;

			var numRadioButtons =  eval("aform."+name+".length");
				
			for (i=0;i<numRadioButtons;++i) {
				if (eval("aform."+name+"["+i+"].checked")) {
					return "";
				}
			}
			
			return message + '\n';
		}

		//Validate Form
		function validateForm(aform) {
			var el = aform.elements;
			var errorMsg = '';
			
			for(var i = 0 ; i < el.length ; ++i) {
				var googleToolbar = el[i].title;
				
				if(googleToolbar.substr(0,11) == "Your Google") {continue;}
				
				if(el[i].name == 'email') {
					if(isEmail(el[i].value) == false) {
						errorMsg += 'Invalid Email' + '\n';
					}
				} else if(el[i].type == 'checkbox') {
					if(el[i].checked == false  && el[i].title.length > 0) {
						errorMsg += el[i].title + '\n';
					}
				} else if (el[i].type == 'select-one') {
					if(el[i].selectedIndex < 1 && el[i].title.length > 0) {
						errorMsg += el[i].title + '\n';
					}
				} else if (el[i].title.length > 0) {
					if(el[i].value.length == 0) {
						errorMsg += el[i].title + '\n';
					}
				}
			}
			
			if(errorMsg.length > 0) {
				errorMsg = 'Please complete all required fields below:\n'+errorMsg;
				alert(errorMsg);
				return false;
			} else {
				return true;
			}
			
			return false;
			
		
		}
		
		
		/**
 * jQuery Cookie plugin
 *
 * Copyright (c) 2010 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
jQuery.cookie = function (key, value, options) {

    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        value = String(value);

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};


$(document).ready(function() {
   /* Landing Page */

// attach handler to form's submit event 
	$('#paper-register').submit(function() { 
	    // submit the form 
	    	// Reference: http://jquery.malsup.com/form/#getting-started

	    $(this).ajaxSubmit( {
	    	url: '/include/forms/thank-you-wp.php', //Overide forms action=
	    	beforeSubmit:  showRequest, 
	    	success: showResponse 
	    
	    }); 
	    // return false to prevent normal browser submit and page navigation 
	    return false; 
	});
	// pre-submit callback 
	function showRequest(formData, jqForm, options) { 
	
	    // formData is an array; here we use $.param to convert it to a string to display it 
	    // but the form plugin does this for you automatically when it submits the data 
	    var queryString = $.param(formData); 
	 
	    // jqForm is a jQuery object encapsulating the form element.  To access the 
	    // DOM element for the form do this: 
	    // var formElement = jqForm[0]; 
	 
	   /*  alert('About to submit: \n\n' + queryString);  */
	 
	    // here we could return false to prevent the form from being submitted; 
	    // returning anything other than false will allow the form submit to continue 
	    return true; 
	} 
	 
	// post-submit callback 
	function showResponse(responseText, statusText, xhr, $form)  { 
	    // for normal html responses, the first argument to the success callback 
	    // is the XMLHttpRequest object's responseText property 
	 
	    // if the ajaxForm method was passed an Options Object with the dataType 
	    // property set to 'xml' then the first argument to the success callback 
	    // is the XMLHttpRequest object's responseXML property 
	 
	    // if the ajaxForm method was passed an Options Object with the dataType 
	    // property set to 'json' then the first argument to the success callback 
	    // is the json data object returned by the server 
	   
	 	 $('#paper-register').fadeOut(function(){$(this).remove();});
	 	
	   $('.thank-you-message').html(responseText).animate({right: '+=240'},1000,'linear')
	}
});
		
			
			
