/*
 * Ventura Web Design JavaScript
 * http://www.venturawebdesign.com/
 *
 * Copyright (c) 2009 Ventura Web Design
 *
 * Date: 2009-07-10
 *
 */
function fixIE6flicker(fix) {
	try {
		document.execCommand("BackgroundImageCache", false, fix);
	} catch(err) { }
}
jQuery.fn.extend({
	tooltip: function() {
		xOffset = 10;
		yOffset = 20;

		$(this).hover(
			function(e){
				this.t = this.title;
				this.title = "";
				$("body").append("<p id='tooltip'>"+ this.t +"</p>");
				$("#tooltip")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(e.pageX + yOffset) + "px")
				.fadeIn("fast");
			},
			function(){
				this.title = this.t;
				$("#tooltip").remove();
				$("a.tooltip").mousemove(function(e){
					$("#tooltip")
					.css("top",(e.pageY - xOffset) + "px")
					.css("left",(e.pageX + yOffset) + "px");
				});
			}
		);
	}
});
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 enter a valid number");

$(document).ready(function() {
	if($('.explorer6').length > 0) {
    fixIE6flicker(true);
  }
	$("a.tooltip").tooltip();
	$('#contact-form-wrapper form').validate({
		rules: {
			fname: {required: true},
			lname: {required: true},
			email: {
				required: true,
				email: true
			},
			phone: {phoneUS: true},
			website: {url: true},
			secure: {required: true}
		}
	});
});
