/*   
=============================================================================== 
Base jQuery file
...............................................................................
																		2011/03
------------------------------------------------------------------------------- 
COPY / USE AT YOUR OWN SITE'S RISK
=============================================================================== 
*/

/**
 * matches US phone number format 
 * 
 * where the area code may not start with 1 and the prefix may not start with 1 
 * allows '-' or ' ' as a separator and allows parens around area code 
 * some people may want to put a '1' in front of their number 
 * 
 * 1(212)-999-2345
 * or
 * 212 999 2344
 * or
 * 212-999-0983
 * 
 * but not
 * 111-123-5434
 * and not
 * 212 123 4567
 */
 
//ADD TRIM FUNCTIONALITY FOR IE
	if(typeof String.prototype.trim !== 'function')
	{
		String.prototype.trim = function()
		{
			return this.replace(/^\s+|\s+$/g, ''); 
		}
	}

jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
    phone_number = phone_number.replace(/\s+/g, ""); 
	return this.optional(element) || phone_number.length > 9 && phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
}, "Please specify a valid phone number");


jQuery.fn.equalHeights = function(px) {
	jQuery(this).each( function(){
		var currentTallest = 0,
			compare = jQuery(this).children("aside,section");
		compare.each(function(i){
			if (jQuery(this).height() > currentTallest) { currentTallest = jQuery(this).height(); }
		});
		compare.css({'min-height': currentTallest}); 
	});
	return this;
};

jQuery.fn.clearForm = function() {
	return this.each(function() {
		var type = this.type, tag = this.tagName.toLowerCase();
		if (tag === 'form')
			return $(':input',this).clearForm();
		if (type === 'text' || type === 'password' || tag === 'textarea')
			this.value = '';
		else if (type === 'checkbox' || type === 'radio')
			this.checked = false;
		else if (tag === 'select')
			this.selectedIndex = -1;
	});
};

/*var counter = 1,
	next = 1;
function swapImages(){
	if(counter===4)
		next = 1;
	else
		next++;
	
	$('body').removeClass('bg-'+counter).addClass('bg-'+next);
	$('#tagline-'+counter).fadeOut(800, function(){
		$('#tagline-'+next).fadeIn(800);
	});
	//$('#wrapper').switchClass('tag-'+counter,'tag-'+next,1000);
	counter = next;
}*/

jQuery(document).ready( function() {
	
	jQuery('#wrapper').equalHeights();
	
	// request-info dropdown
	var liRequestInfo = $('#nav-request-info'),
		formRequestInfo = $('#form-request-info'),
		closeRequest = formRequestInfo.find('span.close');
	if(liRequestInfo[0]&&formRequestInfo[0]&&closeRequest[0]){
		liRequestInfo.click(function(){
			if (!formRequestInfo.is(':visible')) {
				formRequestInfo.stop(true,true).slideToggle(300);
			}
		});
		closeRequest.click(function(){
			formRequestInfo.stop(true,true).slideUp(300);
		});
		closeRequest.hover(
			function(){
				jQuery(this).addClass('ui-state-hover');
			},
			function(){
				jQuery(this).removeClass('ui-state-hover');
			}
		);
	}
	
	// Initialize dropdown menus
	var sfMenus = $('#menu-primary');
	if(sfMenus[0]){
		sfMenus.superfish({ 
			hoverClass:	'ui-state-hover',
			pathClass:	'ui-state-active',
			pathLevels:	0,
			delay:		800,
			speed:		'normal',
			autoArrows:	false,
			dropShadows:false
		});
	}	
	
	// Homepage cycle
	/*if($('body').hasClass('homepage'))
		setInterval('swapImages()',12000);*/

	
	// Datepicker field(s)
	var datepickers = $("input.datepicker");
	if(datepickers[0]){
		datepickers.datepicker({
			showOn: "button",
			buttonImage: "/siteassets/images/calendar.gif",
			buttonImageOnly: true
		});
	}
	
	// Submit field(s)
	var submits = $("input[type=submit],input[type=button],button");
	if(submits[0]){
		submits.each( function(){
			var theClass = $(this).attr('class');
			$(this).removeAttr('class').wrap('<span class="btnwrap '+theClass+'"/>');
		});
	}

	
	// form validation
	var placementArgs = function(error, element) { 
			if ( element.is(":radio") || element.is(":checkbox") ) {
				error.appendTo( element.closest('fieldset') );
			} else { 
				error.appendTo( element.parent() );
			}
		},
		dialogArgs = {
			width: 400,
			modal: true,
			autoOpen: false,
			title: "<h2><img src='/siteassets/images/headers/h.ARThankYou.png' alt='Thank you for contacting Lake Presidential Golf Club.'/></h2>",
			resizable: false,
			draggable: false
		};
	
	// Request Information
	var submitRequestInfo = jQuery('#btn-submit-requestInfo'),
		requestActionReq = formRequestInfo.attr('action'),
		confirmDialogRI = $("#hdnReqInfoConfirm");
		
	/* uncomment if you wish to change for this instance
	dialogArgs.title = "<h2><img src='/siteassets/images/headers/h.ARThankYou.png' alt='Thank you for contacting Lake Presidential Golf Club.'/></h2>";*/
	
	if (formRequestInfo[0]&&submitRequestInfo[0]&&confirmDialogRI[0]) {
		confirmDialogRI.dialog(dialogArgs);
		formRequestInfo.removeAttr('action').validate({
			rules: {
				/*captcha: "required",*/
				captchaIn: {
					required: true,
					remote: "/siteassets/js/process.cfm"
				},
				firstname: "required",
				lastname: "required",
				phoneUS: {
					phoneUS: true
				},
				email: {
					required: true,
					email: true
				}
			},/**/
			messages: {
				firstname: {
					required: "Please enter your first name."
				},
				lastname: {
					required: "Please enter your last name."
				},
				phoneUS: {
					phoneUS: "Please enter a valid phone number."
				},
				email:  {
					required: "Please enter your email address.",
					email: "Please enter a valid email address."
				},
				captchaIn: {
					required: "Please enter the captcha.",
					remote: "Correct captcha is required."
				}/**/
				/*captcha: {
					required: "Please enter the captcha",
					equalTo: "Make sure to retype the captcha correctly"
				}*/
			},
			errorPlacement: placementArgs
		});
		submitRequestInfo.click( function(){
			if (formRequestInfo.valid()){
				var dataString = formRequestInfo.serialize();
				$.ajax({
					type: "POST",
					url: requestActionReq,
					data: dataString,
					success: function(data, textStatus, jqXHR) {
						formRequestInfo.slideUp(400, function(){
							confirmDialogRI.dialog('open');
						})
						formRequestInfo.clearForm();
					},
					error: function(jqXHR, textStatus, errorThrown) {
						alert(jqXHR.status);
						alert(errorThrown);
						alert('an error has occurred, please try again');
					}
				});
				return false;
			}
		});
	}
	
	// Employment
	var formEmploy = jQuery("#form-employ");
	if (formEmploy[0]) {
		formEmploy.validate({
			rules: {
				captchaIn: {
					required: true,
					remote: "/siteassets/js/process.cfm"
				},
				firstname: "required",
				lastname: "required",
				phoneUS: {
					//required: true,
					phoneUS: true
				},
				email: {
					required: true,
					email: true
				},
				resume: {
					accept: "doc|docx|pdf"
				},
				coverletter: {
					accept: "doc|docx|pdf"
				}
			},
			messages: {
				firstname: "Please enter your first name",
				lastname: "Please enter your last name",
				phoneUS: {
					//required: "Please enter your phone number",
					phoneUS: "Please enter a valid phone number"
				},
				email:  {
					required: "Please enter your email address",
					email: "Please enter a valid email address"
				},
				resume: {
					accept: "Please select a .doc or .pdf"
				},
				coverletter: {
					accept: "Please select a .doc or .pdf"
				},
				captchaIn: {
					required: "Please enter the captcha.",
					remote: "Correct captcha is required."
				}
			},
			errorPlacement: function(error, element) { 
				if ( element.is(":radio") || element.is(":checkbox") ) 
					error.appendTo( element.closest('fieldset') );
				else 
					error.appendTo( element.parent() ); 
			}
		});
	}
	/*var formEmploy = jQuery("#form-employ"),
		submitEmploy = jQuery('#btn-submit-employ'),
		confirmDialogEmploy = $("#hdnEmployConfirmation");
	
	requestActionEmp = formEmploy.attr('action');*/
	/* uncomment if you wish to change for this instance
	dialogArgs.title = "<h2><img src='/siteassets/images/headers/h.ARThankYou.png' alt='Thank you for contacting Lake Presidential Golf Club.'/></h2>";*/
	
	/*if (formEmploy[0]&&submitEmploy[0]&&confirmDialogEmploy[0]) {
		confirmDialogEmploy.dialog(dialogArgs);
		formEmploy.removeAttr('action').validate({
			rules: {
				firstname: "required",
				lastname: "required",
				phoneUS: {
					//required: true,
					phoneUS: true
				},
				email: {
					required: true,
					email: true
				},
				resume: {
					accept: "doc|docx|pdf"
				},
				coverletter: {
					accept: "doc|docx|pdf"
				}
			},
			messages: {
				firstname: "Please enter your first name",
				lastname: "Please enter your last name",
				phoneUS: {
					//required: "Please enter your phone number",
					phoneUS: "Please enter a valid phone number"
				},
				email:  {
					required: "Please enter your email address",
					email: "Please enter a valid email address"
				},
				resume: {
					accept: "Please select a .doc or .pdf"
				},
				coverletter: {
					accept: "Please select a .doc or .pdf"
				}
			},
			errorPlacement: placementArgs
		});*/
		/*submitEmploy.click( function(){
			if (formEmploy.valid()){
				var dataString = formEmploy.serialize();
				$.ajax({
					type: "POST",
					url: requestActionEmp,
					data: dataString,
					success: function(data, textStatus, jqXHR) {
						confirmDialogEmploy.dialog('open');
						formEmploy.clearForm();
					},
					error: function(jqXHR, textStatus, errorThrown) {
						alert(jqXHR.status);
						alert(errorThrown);
						alert('an error has occurred, please try again');
					}
				});
				return false;
			}
		});
	}*/
	
	// Contact Us
	var formContactUS = jQuery("#form-contact"),
		submitContactUS = jQuery('#btn-submit-contact'),
		confirmDialogContactUS = $("#hdnContactConfirmation");
	
	requestActionContactUS = formContactUS.attr('action');
	//alert('requestActionContactUS='+requestActionContactUS);
	/* uncomment if you wish to change for this instance*/
	dialogArgs.title = "<h2><img src='/siteassets/images/headers/h.ARThankYou.png' alt='Thank you for contacting Lake Presidential Golf Club.'/></h2>";
	
	if (formContactUS[0]&&submitContactUS[0]&&confirmDialogContactUS[0]) {
		confirmDialogContactUS.dialog(dialogArgs);
		formContactUS.removeAttr('action').validate({
			rules: {
				captchaIn: {
					required: true,
					remote: "/siteassets/js/process.cfm"
				},
				firstname: "required",
				lastname: "required",
				phoneUS: {
					required: true,
					phoneUS: true
				},
				email: {
					required: true,
					email: true
				}
			},
			messages: {
				firstname: "Please enter your first name",
				lastname: "Please enter your last name",
				phoneUS: {
					required: "Please enter your phone number",
					phoneUS: "Please enter a valid phone number"
				},
				email:  {
					required: "Please enter your email address",
					email: "Please enter a valid email address"
				},
				captchaIn: {
					required: "Please enter the captcha.",
					remote: "Correct captcha is required."
				}
			},
			errorPlacement: placementArgs
		});
		submitContactUS.click( function(){
			if (formContactUS.valid()){
				var dataString = formContactUS.serialize();
				//alert('dataString='+dataString);
				$.ajax({
					type: "POST",
					url: requestActionContactUS,
					data: dataString,
					success: function(data, textStatus, jqXHR) {
						confirmDialogContactUS.dialog('open');
						formContactUS.clearForm();
					},
					error: function(jqXHR, textStatus, errorThrown)
					{
						alert(jqXHR.status);
						alert(errorThrown);
						alert('an error has occurred, please try again');
					}
				});
				return false;
			}
		});
	}
	
	// Contact Us - Institute
	var formContact = jQuery("#form-contact-institute"),
		submitContact = jQuery('#btn-submit-contact'),
		confirmDialogContact = $("#hdnContactConfirmation");
	
	requestActionContactInst = formContact.attr('action');
	dialogArgs.title = "<h2><img src='/siteassets/images/headers/h.ARThanksInstitute.png' alt='Thank you for contacting The Institute at Lake Presidential.'/></h2>";
	
	if (formContact[0]&&submitContact[0]&&confirmDialogContact[0]) {
		confirmDialogContact.dialog(dialogArgs);
		formContact.removeAttr('action').validate({
			rules: {
				captchaIn: {
					required: true,
					remote: "/siteassets/js/process.cfm"
				},
				firstname: "required",
				lastname: "required",
				phoneUS: {
					//required: true,
					phoneUS: true
				},
				email: {
					required: true,
					email: true
				}
			},
			messages: {
				firstname: "Please enter your first name",
				lastname: "Please enter your last name",
				phoneUS: {
					//required: "Please enter your phone number",
					phoneUS: "Please enter a valid phone number"
				},
				email:  {
					required: "Please enter your email address",
					email: "Please enter a valid email address"
				},
				captchaIn: {
					required: "Please enter the captcha.",
					remote: "Correct captcha is required."
				}
			},
			errorPlacement: placementArgs
		});
		submitContact.click( function(){
			if (formContact.valid()){
				var dataString = formContact.serialize();
				$.ajax({
					type: "POST",
					url: requestActionContactInst,
					data: dataString,
					success: function(data, textStatus, jqXHR) {
						confirmDialogContact.dialog('open');
						formContact.clearForm();
					},
					error: function(jqXHR, textStatus, errorThrown) {
						alert(jqXHR.status);
						alert(errorThrown);
						alert('an error has occurred, please try again');
					}
				});
				return false;
			}
		});
	}
	
	// Meetings
	var formMeeting = jQuery("#form-meeting"),
		submitMeeting = jQuery('#btn-submit-meeting'),
		confirmDialogMeeting = $("#hdnMeetingConfirmation");
	
	requestActionMeetings = formMeeting.attr('action');
	dialogArgs.title = "<h2><img src='/siteassets/images/headers/h.ARThanksEventPlanning.png' alt='Thank you for contacting Lake Presidential regarding your event planning needs.'/></h2>";
	
	if (formMeeting[0]&&submitMeeting[0]&&confirmDialogMeeting[0]) {
		confirmDialogMeeting.dialog(dialogArgs);
		formMeeting.removeAttr('action').validate({
			rules: {
				captchaIn: {
					required: true,
					remote: "/siteassets/js/process.cfm"
				},
				firstname: "required",
				lastname: "required",
				phoneUS: {
					//required: true,
					phoneUS: true
				},
				email: {
					required: true,
					email: true
				},
				preferreddate: {
					date: true
				}
			},
			messages: {
				firstname: "Please enter your first name",
				lastname: "Please enter your last name",
				phoneUS: {
					//required: "Please enter your phone number",
					phoneUS: "Please enter a valid phone number"
				},
				email:  {
					required: "Please enter your email address",
					email: "Please enter a valid email address"
				},
				preferreddate: {
					date: "Please enter a valid date"
				},
				captchaIn: {
					required: "Please enter the captcha.",
					remote: "Correct captcha is required."
				}
			},
			errorPlacement: placementArgs
		});
		submitMeeting.click( function(){
			if (formMeeting.valid()){
				var dataString = formMeeting.serialize();
				$.ajax({
					type: "POST",
					url: requestActionMeetings,
					data: dataString,
					success: function(data, textStatus, jqXHR) {
						confirmDialogMeeting.dialog('open');
						formMeeting.clearForm();
					},
					error: function(jqXHR, textStatus, errorThrown) {
						alert(jqXHR.status);
						alert(errorThrown);
						alert('an error has occurred, please try again');
					}
				});
				return false;
			}
		});
	}
	
	// Parties
	var formParty = jQuery("#form-party"),
		submitParty = jQuery('#btn-submit-party'),
		confirmDialogParty = $("#hdnPartyConfirmation");
	
	requestActionParty = formParty.attr('action');
	dialogArgs.title = "<h2><img src='/siteassets/images/headers/h.ARThanksEventPlanning.png' alt='Thank you for contacting Lake Presidential regarding your event planning needs.'/></h2>";
	
	if (formParty[0]&&submitParty[0]&&confirmDialogParty[0]) {
		confirmDialogParty.dialog(dialogArgs);
		formParty.removeAttr('action').validate({
			rules: {
				captchaIn: {
					required: true,
					remote: "/siteassets/js/process.cfm"
				},
				firstname: "required",
				lastname: "required",
				phoneUS: {
					//required: true,
					phoneUS: true
				},
				email: {
					required: true,
					email: true
				},
				preferreddate: {
					date: true
				}
			},
			messages: {
				firstname: "Please enter your first name",
				lastname: "Please enter your last name",
				phoneUS: {
					//required: "Please enter your phone number",
					phoneUS: "Please enter a valid phone number"
				},
				email:  {
					required: "Please enter your email address",
					email: "Please enter a valid email address"
				},
				preferreddate: {
					date: "Please enter a valid date"
				},
				captchaIn: {
					required: "Please enter the captcha.",
					remote: "Correct captcha is required."
				}
			},
			errorPlacement: placementArgs
		});
		submitParty.click( function(){
			if (formParty.valid()){
				var dataString = formParty.serialize();
				$.ajax({
					type: "POST",
					url: requestActionParty,
					data: dataString,
					success: function(data, textStatus, jqXHR) {
						confirmDialogParty.dialog('open');
						formParty.clearForm();
					},
					error: function(jqXHR, textStatus, errorThrown) {
						alert(jqXHR.status);
						alert(errorThrown);
						alert('an error has occurred, please try again');
					}
				});
				return false;
			}
		});
	}
	
	// Weddings
	var formWedding = jQuery("#form-wedding"),
		submitWedding = jQuery('#btn-submit-wedding'),
		confirmDialogWedding = $("#hdnWeddingConfirmation");
	
	requestActionWeddings = formWedding.attr('action');
	dialogArgs.title = "<h2><img src='/siteassets/images/headers/h.ARThanksWedding.png' alt='Thank you for contacting Lake Presidential regarding your wedding planning needs.'/></h2>";
	
	if (formWedding[0]&&submitWedding[0]&&confirmDialogWedding[0]) {
		confirmDialogWedding.dialog(dialogArgs);
		formWedding.removeAttr('action').validate({
			rules: {
				captchaIn: {
					required: true,
					remote: "/siteassets/js/process.cfm"
				},
				bridefirstname: "required",
				bridelastname: "required",
				groomfirstname: "required",
				groomlastname: "required",
				phoneUS: {
					//required: true,
					phoneUS: true
				},
				email: {
					required: true,
					email: true
				},
				preferreddate: {
					date: true
				}
			},
			messages: {
				bridefirstname: "Please enter the bride&rsquo;s first name",
				bridelastname: "Please enter the bride&rsquo;s last name",
				groomfirstname: "Please enter the groom&rsquo;s first name",
				groomlastname: "Please enter the groom&rsquo;s last name",
				phoneUS: {
					//required: "Please enter your phone number",
					phoneUS: "Please enter a valid phone number"
				},
				email:  {
					required: "Please enter your email address",
					email: "Please enter a valid email address"
				},
				preferreddate: {
					date: "Please enter a valid date"
				},
				captchaIn: {
					required: "Please enter the captcha.",
					remote: "Correct captcha is required."
				}
			},
			errorPlacement: placementArgs
		});
		submitWedding.click( function(){
			if (formWedding.valid()){
				var dataString = formWedding.serialize();
				$.ajax({
					type: "POST",
					url: requestActionWeddings,
					data: dataString,
					success: function(data, textStatus, jqXHR) {
						confirmDialogWedding.dialog('open');
						formWedding.clearForm();
					},
					error: function(jqXHR, textStatus, errorThrown) {
						alert(jqXHR.status);
						alert(errorThrown);
						alert('an error has occurred, please try again');
					}
				});
				return false;
			}
		});
	}
	
	
	// Tournaments or Outings
	var formTournaments = jQuery("#form-tournaments"),
		submitTournaments = jQuery('#btn-submit-tournaments'),
		confirmDialogTournaments = $("#hdnTournamentConfirmation");
	
	requestActionTournaments = formTournaments.attr('action');
	//alert('requestActionTournaments='+requestActionTournaments);
	/* uncomment if you wish to change for this instance*/
	dialogArgs.title = "<h2><img src='/siteassets/images/headers/h.ARThankYou.png' alt='Thank you for contacting Lake Presidential Golf Club.'/></h2>";
	
	if (formTournaments[0]&&submitTournaments[0]&&confirmDialogTournaments[0]) {
		confirmDialogTournaments.dialog(dialogArgs);
		formTournaments.removeAttr('action').validate({
			rules: {
				captchaIn: {
					required: true,
					remote: "/siteassets/js/process.cfm"
				},
				firstname: "required",
				lastname: "required",
				phoneUS: {
					required: true,
					phoneUS: true
				},
				email: {
					required: true,
					email: true
				}
			},
			messages: {
				firstname: "Please enter your first name",
				lastname: "Please enter your last name",
				phoneUS: {
					required: "Please enter your phone number",
					phoneUS: "Please enter a valid phone number"
				},
				email:  {
					required: "Please enter your email address",
					email: "Please enter a valid email address"
				},
				captchaIn: {
					required: "Please enter the captcha.",
					remote: "Correct captcha is required."
				}
			},
			errorPlacement: placementArgs
		});
		submitTournaments.click( function(){
			if (formTournaments.valid()){
				var dataString = formTournaments.serialize();
				//alert('In submitTournaments.click requestActionTournaments='+requestActionTournaments);
				$.ajax({
					type: "POST",
					url: requestActionTournaments,
					data: dataString,
					success: function(data, textStatus, jqXHR) {
						confirmDialogTournaments.dialog('open');
						formTournaments.clearForm();
					},
					error: function(jqXHR, textStatus, errorThrown) {
						alert(jqXHR.status);
						alert(errorThrown);
						alert('an error has occurred, please try again');
					}
				});
				return false;
			}
		});
	}
	
	// Feedback
	var formFeedback = jQuery("#form-feedback"),
		submitFeedback = jQuery('#btn-submit-feedback'),
		confirmDialogFeedback = $("#hdnFeedbackConfirmation");
	
	requestActionFeedback = formFeedback.attr('action');
	//alert('requestActionFeedback='+requestActionFeedback);
	/* uncomment if you wish to change for this instance*/
	dialogArgs.title = "<h2><img src='/siteassets/images/headers/h.ARThankYou.png' alt='Thank you for contacting Lake Presidential Golf Club.'/></h2>";
	
	if (formFeedback[0]&&submitFeedback[0]&&confirmDialogFeedback[0]) {
		confirmDialogFeedback.dialog(dialogArgs);
		formFeedback.removeAttr('action').validate({
			rules: {
				captchaIn: {
					required: true,
					remote: "/siteassets/js/process.cfm"
				},
				firstname: "required",
				lastname: "required",
				/*phoneUS: {
					required: true,
					phoneUS: true
				},*/
				email: {
					required: true,
					email: true
				}
			},
			messages: {
				firstname: "Please enter your first name",
				lastname: "Please enter your last name",
				/*phoneUS: {
					required: "Please enter your phone number",
					phoneUS: "Please enter a valid phone number"
				},*/
				email:  {
					required: "Please enter your email address",
					email: "Please enter a valid email address"
				},
				captchaIn: {
					required: "Please enter the captcha.",
					remote: "Correct captcha is required."
				}
			},
			errorPlacement: placementArgs
		});
		submitFeedback.click( function(){
			if (formFeedback.valid()){
				var dataString = formFeedback.serialize();
				//alert('In submitFeedback.click requestActionFeedback='+requestActionFeedback);
				$.ajax({
					type: "POST",
					url: requestActionFeedback,
					data: dataString,
					success: function(data, textStatus, jqXHR) {
						confirmDialogFeedback.dialog('open');
						formFeedback.clearForm();
					},
					error: function(jqXHR, textStatus, errorThrown) {
						alert(jqXHR.status);
						alert(errorThrown);
						alert('an error has occurred, please try again');
					}
				});
				return false;
			}
		});
	}
	// Preload all rollovers
		$(".rollover img").each(function() {
			// Set the original src
			rollsrc = $(this).attr("src");
			rollON = rollsrc.replace('.png', '_hover.png');
			newImg = new Image(); // create new image obj
			$(newImg).attr("src", rollON); // set new obj's src
		});

		
		// rollovers for select buttons
		$(".rollover").mouseover(function(){
			imgsrc = $(this).children("img").attr("src");
			if (typeof(imgsrc) != 'undefined') {
			imgsrcON = imgsrc.replace('.png', '_hover.png');
			$(this).children("img").attr("src", imgsrcON);
			}
			
		});
		// Handle mouseout
		$(".rollover").mouseout(function(){
			if (typeof(imgsrc) != 'undefined') {
			$(this).children("img").attr("src", imgsrc);
			}
		});
	
	
});
