
$.fn.customFadeIn = function(speed, callback) {
		$(this).fadeIn(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.customFadeOut = function(speed, callback) {
		$(this).fadeOut(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};

function mainmenu(){
	$(".nav li ul").css({display: "none"}); // Opera Fix
	
	//$('.nav ul').css('opacity', '0'); 
	$(".nav li").hover(function(){
		$(this).find('ul:first').css({visibility: "visible",display: "none"}).customFadeIn();
		//$(this).find('ul:first').css({visibility: "visible",display: "none"}).stop().animate({"opacity": 1},"fast");
		
		//$('ul', $(this)).css({visibility: "visible",display: "none"}).fadeIn(200); 
	},function(){
		$(this).find('ul:first').customFadeOut();
		//$('ul', $(this)).fadeOut(200); 
	});
}

$(document).ready(function(){
	$("#topNav ul li:last-child").addClass("last");
	$("#topNav li > a").attr('title', '');
	$(".children li:last-child").addClass("last");
	
	//mainmenu();


	//var nav = new siteNav();
	
	/********************
	eteam page functionality
	*****************/
	$('.person a').hover(
		function() {
			 $('span', $(this)).stop().animate({"opacity": 1}, 200);
		}, 
		function() { 	
			var myClass = $(this).parent().attr("class");
			
			//only fade out on inactive
			if(myClass == "person inactive") {
				$('span', $(this)).stop().animate({"opacity": 0}, 200); 
			}
		}
	);
	
	var lastItem = $('.person.current');
	var currentItem = null;
	
	$('.person a').click(function() {              
		$('.panel').hide();
		var $href = $(this).attr('href');
		$($href).show();
		
		$(lastItem).removeClass('current').addClass('inactive');
		$('span', lastItem).stop().animate({"opacity": 0}, 200); 
		
		currentItem = $(this).parent();
		$(currentItem).removeClass('inactive').addClass('current');
		   				
		lastItem = currentItem;
		
		return false;
	});
	
	$('.logo a').hover(
		function() {
			 $('span', $(this)).stop().animate({"opacity": 1}, 200);
		}, 
		function() { 	
			var myClass = $(this).parent().attr("class");
			
			//only fade out on inactive
			if(myClass == "logo inactive") {
				$('span', $(this)).stop().animate({"opacity": 0}, 200); 
			}
		}
	);
	
	var lastItemLogo = $('.logo.current');
	var currentItemLogo = null;
	
	$('.logo a').click(function() {              
		$('.panel').hide();
		var $href = $(this).attr('href');
		$($href).show();
		
		$(lastItemLogo).removeClass('current').addClass('inactive');
		$('span', lastItemLogo).stop().animate({"opacity": 0}, 200); 
		
		currentItemLogo = $(this).parent();
		$(currentItemLogo).removeClass('inactive').addClass('current');
		   				
		lastItemLogo = currentItemLogo;
		
		return false;
	});
	
	/********************
	home page slideshow
	*****************/
	var services = ["online","scoring","psychometrics","pub"];
	
	var currentSlide = null;
	var lastSlide = null;
	
	$('#online').addClass('current');
	
	function onAfter(curr, next, opts) {
    	var index = opts.currSlide;
		
		currentSlide = $('#'+services[index]);
    	
		$(currentSlide).addClass('current');
		$(lastSlide).removeClass('current');
		
		lastSlide = currentSlide;
	}
	
	$('#mainDisplay .inner').cycle({ 
		fx:     'fade', 
		speed:  500, 
		timeout: 7000, 
		pause: 1,
		after:   onAfter,
		next:   '.next', 
		prev:   '.prev'  
	})

	
	/********************
	Contact Form
	*****************/
	// validate signup form on keyup and submit
	$("#contact-form").validate({
		rules: {
			name: "required",
			email: "required",
			message: "required"
	
		},
		messages: {
			name: "Please enter your name",
			message: "Please enter your message",
			email: "Please enter a valid email address"
		}
	});
	
	$("#submit").click(function() {
		var name = $("input#name").val();
		var email = $("input#email").val();
		var phone = $("input#phone").val();
		var message = $("textarea#message").val();
		
		var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&message=' + message;
		
		$.ajax({
			  type: "POST",
			  url: "http://www.pacificmetrics.com/main/wp-content/themes/pm/form/process-contact.php",
			  data: dataString,
			  success: function() {
				$('#contact-form').html("<div id='message'></div>");
				$('#message').html("<p>Thank you for contacting us. We will get back to you promptly.</p>")
			  }
		});
		return false;
	  
	});
	
	
	/********************
	department quotes
	*****************/
	
	//department sidebar
	$('#quotes').cycle({ 
		fx:     'fade', 
		speed:  500, 
		timeout: 10000, 
		pause: 1
	});
	
	
	/********************
	benefits tooltips
	*****************/
	
	var contents = [
				   'Pacific Metrics provides and pays for a portion of medical, and all dental, life, and disability insurance benefits for employees. Dependents may be added at the employee\'s expense. Employees become eligible for health insurance on the 1st of the month following 30 days of full-time employment. We also offer our employees an optional pre-tax flexible spending account.',
				   'Pacific Metrics sponsors a 401(k) Profit Sharing Plan with a generous matching program. Employees are eligible for an annual bonus at the end of the year based on company performance.',
				   'Pacific Metrics provides employees the opportunity to accrue 15 days of vacation per year. After 5 years of service, the employee can accrue 20 days per year.',
				   'Pacific Metrics observes eleven paid holidays during the year, which include extended time off during the holiday season.',
				   'We offer flexible schedules and alternative work situations with the understanding that not all employees are able to work in the office full time. We understand that unanticipated life events occur and provide time off based on employee need.',
				   'We have multiple activities throughout the year and encourage our employees to collaborate with their teams regularly. Our calendar includes optional monthly seminars, frequent themed office parties (Mardi Gras being a favorite), and special events throughout the year where employees are recognized and rewarded for their achievements.',
				   'Pacific Metrics consists of people with diverse skills and backgrounds, all focused on the goal of being the best in the industry. We have an open door policy and encourage employee innovation. Our business casual culture has created a positive working environment, and we are proud to say that many of our employees have been here for over 5 years.',
				   'Pacific Metrics\' corporate headquarters is located on Cannery Row in Monterey, California. Our office provides a scenic working environment with full ocean views. Amenities include break rooms with complimentary snacks, bike parking, and nearby walking trails. Every Friday the office provides free bagels-an employee favorite! Our workstations are state-of-the-art, and every employee is given a personal laptop with up-to-date software for business use.',
				   'Pacific Metrics supports our employees\' educational goals, and offers workplace training and seminars.'
				   ];
	var i = 0;
	//Tool tips
	
	$('.benefit').each( function() {
		$(this).qtip({
			content: contents[i],
			position: {
			  my: 'bottom middle',
			  at: 'top middle',
			  adjust: {
				 x: 00, // 100px from the left
				 y: 50 // 300px from the top
			  }
		   },
		   style: {
				tip: true
		   }
	   });
		
		i++;
	});
	/*
	$('.benefit').qtip({
      	content: contents[i],
		position: {
		  my: 'bottom middle',
      	  at: 'top middle',
		  adjust: {
			 x: 00, // 100px from the left
			 y: 50 // 300px from the top
		  }
	   },
	   style: {
      		tip: true,
	   }
   });
	*/
	
	/*var i = 0;
	$(".benefit").each(function() {
		$(this).simpletip({ // Configuration properties 
			content: 'My Simpletip', fixed: false });
	})*/
	
	//$("#insurance").simpletip({ // Configuration properties 
		//	content: 'My Simpletip', fixed: false });
	
	//$("#accordion").msAccordion({vertical:true});
	
	//$('.content').hide();  
	
	$('.title').click(function() {
							   
		var $div = $(this).next('.content');

	  
	  	if ( $div.is(':visible') ) {
			$div.stop().slideUp(500);
	  	} else {
			$div.stop().slideDown(500).children().show();
	 	 }
		 
		$(this).parent().siblings('.set').children('.content').stop().slideUp(500);
		
	  	return false;
	});
	
	/*
	$(function() {

		$('.content').hide();              
	
		$('.title').click(function() {
			
								   
			$(this).next('.content').stop().slideDown(500);
			
			
			
					
	
			$(this).next('.content').stop().slideToggle(500, function () {
      			$(this).next('.content').css('display', "block");
    		});
			
			
			$(this).parent().siblings('.set').children('.content').stop().slideUp(500);

			
			
	
		}, function() {
	
			$(this).next('.content').stop().slideToggle(500);
			
	
		});
	});
	*/
	
	/********************
	email signup
	*****************/
	
	$('.error').hide(); 
		
	$(".button").click(function() {
      // validate and process form here
	  $('.error').hide();
	  
	   var email = $("input#mc_mv_EMAIL").val();  
        if (email == "") {  
		  $("label#email_error").show();  
		  $("input#mc_mv_EMAIL").focus();  
		  return false;  
		}  
		
		  var dataString = '&email=' + email;
		  //alert (dataString);return false;
		  $.ajax({
			type: "POST",
			url: "http://www.pacificmetrics.com/main/wp-content/themes/pm/form/process.php",
			data: dataString,
			success: function() {
			  $('#mc_signup').html("<div id='newsletter-message'></div>");
			  $('#newsletter-message').html("<p>Thank you for signing up for our newsletter. For questions please email <a href='mailto:info@pacificmetrics.com'>info@pacificmetrics.com</a> or fill out this <a href='http://www.pacificmetrics.com/main/contact-us/'>form</a>.</p>");
			}
		  });
		  return false;
    });

});
