//jQuery functions

$(document).ready(function(){
						   
//nav functions

    $(".navList").children("li").each(function() {
    var current =  "navList " + ($(this).attr("class")) + "On";
    var parentClass = $(".navList").attr("class");
    if (parentClass != current) {
        $(this).children("a").css({backgroundImage:"none"});
    }
	
	});

	attachNavEvents(".navList", "navCompany");
	attachNavEvents(".navList", "navServices");
	attachNavEvents(".navList", "navPortfolio");
	attachNavEvents(".navList", "navClients");
	attachNavEvents(".navList", "navContact");
	attachNavEvents(".navList", "navBlog");
		
function attachNavEvents(parent, myClass) {
    $(parent + " ." + myClass).mouseover(function() {
        $(this).before('<div class="' + myClass + 'Effect"></div>');
        $("div." + myClass + "Effect").css({display:"none"}).fadeIn(300);
    }).mouseout(function() {
        $("div." + myClass + "Effect").fadeOut(300, function() {
            $(this).remove();
        });
    })
}

//contact bar functions

    $(".contactList").children("li").each(function() {
    var current =  "navList " + ($(this).attr("class")) + "On";
    var parentClass = $(".navList").attr("class");
    if (parentClass != current) {
        $(this).children("a").css({backgroundImage:"none"});
    }
	
	});

	attachNavEvents(".contactList", "contactEmail");
	attachNavEvents(".contactList", "contactPDF");
		
function attachNavEvents(parent, myClass) {
    $(parent + " ." + myClass).mouseover(function() {
        $(this).before('<div class="' + myClass + 'Effect"></div>');
        $("div." + myClass + "Effect").css({display:"none"}).fadeIn(300);
    }).mouseout(function() {
        $("div." + myClass + "Effect").fadeOut(300, function() {
            $(this).remove();
        });
    })
}

//image swaps

$(".imgSwap").hover(function() {
     var urlString = $(this).attr("src");
	 var newURL = urlString.replace(/\.((?!\.)+(?!\/))/,"_on.");
	 $(this).attr("src",newURL);
   },function(){
	 var urlString = $(this).attr("src");
	 var newURL = urlString.replace(/_on\./,".");
	 $(this).attr("src",newURL);
   });

//home project details

$("#areaHomeProject").hover(function() {
		//alert("yep");
		$("#homeProjectsImg img").fadeTo(300, 0.5);
	},function(){
		$("#homeProjectsImg img").fadeTo(300, 1);
	});
	
//portfolio thumbnails

$(".portfolioThumbWrapper").hover(function() {
		$(this).find('img').fadeTo(300, 0.4);
		//$(".portfolioThumbWrapper img").fadeTo(300, 0.6);
		//console.log(this);
	},function(){
		$(this).find('img').fadeTo(300, 1);
	});

//overlays

// adds an effect called "myEffect" to the overlay 
$.tools.overlay.addEffect("myEffect", 
    function(done) { 
        this.getOverlay().show(this.getConf().fast, done); 
    }, 
    function(done) { 
        this.getOverlay().hide(this.getConf().slow, done); 
    } 
);

$("a[rel]").overlay({ 
    effect: 'apple'
});

//porfolio gallery tabs
$(function() { 
    $("ul.portfolioTabs").tabs("div.portfolioPanes > div", {effect: 'fade', fadeOutSpeed: 400}); 
});

//on portfolio load, set image parent to match absolute div height
var portHeight = $(".portfolioPanes div:visible").height();
$(".portfolioPanes").height(portHeight);

$(".portfolioTabs li a").click(function() {
		var index = $(".portfolioTabs li a").index(this);
		var portHeight = $(".portfolioPanes div").eq(index).height();
		$(".portfolioPanes").height(portHeight);
});

// form validation
    $("#suggestionForm").validate( {
		messages: {
			contactName: "A name is required.",
			contactEmail: "A valid email is required.", 
			suggestionName: "A name is required.", 
			suggestionEmail: "A valid email is required."
		}
	});
	
	$("#comment_form").validate( {
		messages: {
			name: "A name is required.",
			email: "A valid email is required."
		}
	});
	
});

