this.tooltip = function(){	
		
		xOffset = 10;
		yOffset = 20;		
		
	$("a.tooltip").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");
	});			
};

this.scrollButton = function () {
	$('a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target	|| $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				$('html,body').animate({scrollTop: targetOffset}, 1000);
				return false;
			}
		}
	  });
}

$(function() {
	tooltip();
	
	scrollButton();
	
	$("a.lightbox").lightBox();
	
	$('#mySlides').cycle({ 
		fx:     'scrollHorz', 
		speed:   300, 
		timeout: 6000, 
		next:   '#next', 
		prev:   '#prev',
		cleartypeNoBg: true
	});
	
	$('#pause').toggle(function() {
			$('#mySlides').cycle('pause');
			$(this).attr({ src: "wp-content/themes/service_vent/style/images/play.jpg"});
			$('#pause_over').attr({ src: "wp-content/themes/service_vent/style/images/play_over.jpg"});
		},
		function() {
			$('#mySlides').cycle('resume', true);
			$(this).attr({ src: "wp-content/themes/service_vent/style/images/pause.jpg"});
			$('#pause_over').attr({ src: "wp-content/themes/service_vent/style/images/pause_over.jpg"});
    	}); 
	
	//more buttons 
	$(".fade").hover(function() { 
		$(this).stop().fadeTo(200, 0);
		}, function() {
		$(this).stop().fadeTo(400, 1);
	});
	
	//toggle slides on why ventilate page
	$(".toggle").hide();
	$(".tab > h3").click(function() {
		$(this).next(".toggle").slideToggle(150);
	});  
});


function validateUploadForm(f) {
	//grab form elements for validation
		var name = f.elements[0];
		var email = f.elements[1];
		
	if (f.getAttribute("id") == "quick_upload") {
		var file = f.elements[2];
		var message = f.elements[3];
	} else {
		var file = f.elements[4];
		var message = f.elements[5];
	}
	
	//create validation data
	var e = email.value;
	var validEmail = e.match(/\b[\w-\.\+]+@[\w-\.]+\.[A-Za-z_-]{2,4}\b/);
	var fileType = file.value.substring(file.value.lastIndexOf("."));
	
	//error holder and borders
	var error = "";
	var rb = "solid 1px #ff0000";
	var gb = "solid 1px #cccccc";
	
	//reset borders if not first attempt
	name.style.border = gb;
	email.style.border = gb;
	message.style.border = gb;
	
	if (name.value == "") {
		error += "Please enter your name" + "\n";
		name.style.border = rb;
	}
	
	if (e != validEmail || e == "") {
		error += "Please enter your email" + "\n";
		email.style.border = rb;
	}
	
	if (file.value != "") {
		var rightFile = false;
		if (fileType == ".pdf") {
			rightFile = true;
		} else if (fileType ==".dwg") {
			rightFile = true;
		} else if (fileType ==".jpg") {
			rightFile = true;
		}
		if (!rightFile) {
			error += "Please enter a correct file type (.dwg, .pdf, .jpg)" + "\n";
		}
	}
	
	if (message.value == "") {
		error += "Please enter a message";
		message.style.border = rb;
	}
	
	if (error.length > 0) {
		alert(error);
		return false;
	} else return true;
}
