function mainmenu(){
$("ul#nav li").hover(function(){
	$(this).find('ul:first').css({visibility: "visible",display: "none"}).fadeIn(300);
},function(){
	$(this).find('ul:first').css({visibility: "hidden"});
});
}

$(function() {
		
	mainmenu();
	
	$('ul.pagelist li:first').addClass('pageh4');
	
	$("ul#nav2 li").hover(function(){
		width = 0;
		marginwidth = 0;
		removeexcess = 0;
		marginwidth = $(this).width() / 2;
		$(this).find('ul:first li').each(function() {
		    width = width + $(this).width();
		});
		$(this).find('ul:first').find('ul:first li').each(function() {
		    removeexcess = removeexcess + $(this).width();
		});
		widthwithoutexcess = width - removeexcess;
		left = widthwithoutexcess/2;
		marginleft = left - (left * 2);
		
		$(this).find('ul:first').css({"width":widthwithoutexcess + 10, "left":marginleft, "marginLeft": marginwidth, visibility: "visible",display: "none"}).show();
		$(this).hover();
	},function(){
		$(this).find('ul:first').css({visibility: "hidden"});
	});
	
	$('ul#nav ul li:last-child').find('a').addClass('bottomline');
	$('ul#nav ul li:last-child').find('a').addClass('bottomline');
	
	$('#footer ul li:last').css({"border":"none"});
	$('ul.tabbuttons li:last').css({"border":"none"});
	$('.tab2').hide();
	$('a.tab1link').click(function() {
		$('.tab2').hide();
		$('.tab1').fadeIn();
		$('.tabbuttons li').removeClass('active');
		$(this).parent('li').addClass('active');
		return false;
	});
	
	$('a.tab2link').click(function() {
		$('.tab1').hide();
		$('.tab2').fadeIn();
		$('.tabbuttons li').removeClass('active');
		$(this).parent('li').addClass('active');
		return false;
	});
	
	
	
	$('a.theshortone').click(function() {
		$('.tab2').hide();
		$('.tab1').show();
		$('a.theshortone').removeClass('reverse');
		$('a.thelongone').removeClass('reverse');
		return false;
	});
	
	$('a.thelongone').click(function() {
		$('.tab1').hide();
		$('.tab2').show();
		$('a.theshortone').addClass('reverse');
		$('a.thelongone').addClass('reverse');
	});
	
	
	
	$('#s').focus(function() {
		if($(this).attr("value") == "Search our wonderful website") { $(this).attr("value",""); }
	});
	$('#s').blur(function() {
		if($(this).attr("value") == "") { $(this).attr("value","Search our wonderful website"); }
	});
	
	
	$('.sidebarcontactform #name').focus(function() {
		if($(this).attr("value") == "Name") { $(this).attr("value",""); }
	});
	$('.sidebarcontactform #name').blur(function() {
		if($(this).attr("value") == "") { $(this).attr("value","Name"); }
	});
	
	$('.sidebarcontactform #email').focus(function() {
		if($(this).attr("value") == "E-mail") { $(this).attr("value",""); }
	});
	$('.sidebarcontactform #email').blur(function() {
		if($(this).attr("value") == "") { $(this).attr("value","E-mail"); }
	});
	
	$('.sidebarcontactform #phone').focus(function() {
		if($(this).attr("value") == "Phone Number") { $(this).attr("value",""); }
	});
	$('.sidebarcontactform #phone').blur(function() {
		if($(this).attr("value") == "") { $(this).attr("value","Phone Number"); }
	});
	
	$('.smallform #name').focus(function() {
		if($(this).attr("value") == "Name") { $(this).attr("value",""); }
	});
	$('.smallform #name').blur(function() {
		if($(this).attr("value") == "") { $(this).attr("value","Name"); }
	});
	
	$('.smallform #email').focus(function() {
		if($(this).attr("value") == "E-mail") { $(this).attr("value",""); }
	});
	$('.smallform #email').blur(function() {
		if($(this).attr("value") == "") { $(this).attr("value","E-mail"); }
	});
	
	$('.smallform #phone').focus(function() {
		if($(this).attr("value") == "Phone Number") { $(this).attr("value",""); }
	});
	$('.smallform #phone').blur(function() {
		if($(this).attr("value") == "") { $(this).attr("value","Phone Number"); }
	});
	
	$('.longform #name').focus(function() {
		if($(this).attr("value") == "Name") { $(this).attr("value",""); }
	});
	$('.longform #name').blur(function() {
		if($(this).attr("value") == "") { $(this).attr("value","Name"); }
	});
	
	$('.longform #email').focus(function() {
		if($(this).attr("value") == "E-mail") { $(this).attr("value",""); }
	});
	$('.longform #email').blur(function() {
		if($(this).attr("value") == "") { $(this).attr("value","E-mail"); }
	});
	
	$('.longform #phone').focus(function() {
		if($(this).attr("value") == "Phone Number") { $(this).attr("value",""); }
	});
	$('.longform #phone').blur(function() {
		if($(this).attr("value") == "") { $(this).attr("value","Phone Number"); }
	});
	
	$('#address').focus(function() {
		if($(this).attr("value") == "Address") { $(this).attr("value",""); }
	});
	$('#address').blur(function() {
		if($(this).attr("value") == "") { $(this).attr("value","Address"); }
	});
	
	$('#businessname').focus(function() {
		if($(this).attr("value") == "Business Name (If applicable)") { $(this).attr("value",""); }
	});
	$('#businessname').blur(function() {
		if($(this).attr("value") == "") { $(this).attr("value","Business Name (If applicable)"); }
	});
	
	$('#additionalinfo').focus(function() {
		if($(this).attr("value") == "Any additional information") { $(this).attr("value",""); }
	});
	$('#additionalinfo').blur(function() {
		if($(this).attr("value") == "") { $(this).attr("value","Any additional information"); }
	});
	
	
	
	
	$('.sidebarcontactform .hidden').hide();
	$('.sidebarcontactform input#name').click(function() {
		$('.sidebarcontactform .hidden').slideDown();
	});
	
	
	$('.smallform #name').click(function() {
		$('.smallform .hide').fadeIn();
		return false;
	});
	
	
	$('.longform #submit').remove();
    $('.longform p.submit').append('<input type="button" name="submit" id="submit" value="Send" />');
    	
    $('.longform #submit').click(function() {
        var name = $('.longform input#name').val();
        var email = $('.longform input#email').val();
        var phone = $('.longform input#phone').val();
        var service = $('.longform #page_id option:selected').text();
        var address = $('.longform textarea#address').val();
        var businessname = $('.longform input#businessname').val();
        var additionalinfo = $('.longform textarea#additionalinfo').val();
        var formtype = "long";

        $.ajax({
            type: 'post',
        	url: 'http://afamilytreeforme.com/wp-content/themes/familyTree/scripts/sendMessage.php',
        	data: 'name=' + name + '&email=' + email + '&phone=' + phone + '&service=' + service + '&address=' + address + '&businessname=' + businessname + '&additionalinfo=' + additionalinfo + '&formtype=' + formtype,

            success: function(results) {
            $('.longform ul.response').show();
            $('.longform ul.response').html(results);
            }
        }); 
    });
	
	
	$('.smallform #submit').remove();
    $('.smallform p.submit').append('<input type="button" name="submit" id="submit" value="Send" />');
    	
    $('.smallform #submit').click(function() {
        var name = $('.smallform input#name').val();
        var email = $('.smallform input#email').val();
        var phone = $('.smallform input#phone').val();
        var service = $('.smallform #page_id option:selected').text();
        var formtype = "small";

        $.ajax({
            type: 'post',
        	url: 'http://afamilytreeforme.com/wp-content/themes/familyTree/scripts/sendMessage.php',
        	data: 'name=' + name + '&email=' + email + '&phone=' + phone + '&service=' + service + '&formtype=' + formtype,

            success: function(results) {
            $('.smallform ul.response').show();
            $('.smallform ul.response').html(results);
            }
        }); 
    });
	
	
	$('.sidebarcontactform #submit').remove();
    $('.sidebarcontactform p.submit').append('<input type="button" name="submit" id="submit" value="Lets Do it >" />');
    	
    $('.sidebarcontactform #submit').click(function() {
        var name = $('.sidebarcontactform input#name').val();
        var email = $('.sidebarcontactform input#email').val();
        var phone = $('.sidebarcontactform input#phone').val();
        var service = $('.sidebarcontactform #page_id option:selected').text();
        var formtype = "small";

        $.ajax({
            type: 'post',
        	url: 'http://afamilytreeforme.com/wp-content/themes/familyTree/scripts/sendMessage.php',
        	data: 'name=' + name + '&email=' + email + '&phone=' + phone + '&service=' + service + '&formtype=' + formtype,

            success: function(results) {
            $('.sidebarcontactform ul.response').show();
            $('.sidebarcontactform ul.response').html(results);
            }
        }); 
    });
    
    $('.contactform ul.response').click(function() {
    	$(this).fadeOut();
    	return false;
    });
	
});
