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

//home nav functions

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

	attachNavEvents(".homeList", "aboutHome");
	attachNavEvents(".homeList", "workHome");
	attachNavEvents(".homeList", "servicesHome");
	attachNavEvents(".homeList", "contactHome");
	attachNavEvents(".homeList", "testimonials");
	attachNavEvents(".homeList", "furniture");
	attachNavEvents(".homeList", "blog");
		
function attachNavEvents(parent, myClass) {
    $(parent + " ." + myClass).mouseover(function() {
        $(this).before('<div class="' + myClass + 'Effect"></div>');
        $("div." + myClass + "Effect").css({display:"none"}).fadeIn(400);
    }).mouseout(function() {
        $("div." + myClass + "Effect").fadeOut(500, function() {
            $(this).remove();
        });
    })
}

//interior 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", "aboutNav");
	attachNavEvents(".navList", "workNav");
	attachNavEvents(".navList", "servicesNav");
	attachNavEvents(".navList", "testimonialsNav");
	attachNavEvents(".navList", "shopNav");
	attachNavEvents(".navList", "contactNav");
		
function attachNavEvents(parent, myClass) {
    $(parent + " ." + myClass).mouseover(function() {
        $(this).before('<div class="' + myClass + 'Effect"></div>');
        $("div." + myClass + "Effect").css({display:"none"}).fadeIn(400);
    }).mouseout(function() {
        $("div." + myClass + "Effect").fadeOut(500, function() {
            $(this).remove();
        });
    })
}

// faq tabs
$(".faqClose, .faqOpen").click(function(){
		$(".servicesFAQ").slideToggle("slow", function() {
    		$(".servicesFAQ ul").tabs(".panes > div", {effect: 'fade', fadeOutSpeed: 400});
  		});		 
	});

$(".faqClose").hover(function() {
	 $(this).toggleClass("faqCloseOn");
   },function(){
	 $(this).toggleClass("faqCloseOn");
   });

// work thumb tabs
$(".ourWork ul").tabs(".panes > div", {effect: 'fade', fadeOutSpeed: 400});

$(".ourWork .panes div a").hover(function() {
	 $(this).find("img").fadeTo(400, 0.1);
   },function(){
	 $(this).find("img").fadeTo(200, 1);
   });

// projects tabs

//var holds the last clicked tab for turning off old after images
var currentTab = null;

$(".projectsNav ul").tabs(".panes > div", {
				effect: 'fade',
				fadeOutSpeed: 400,

				//callbacks for animating in after images
				onBeforeClick: function(event, tabIndex) {
					//conditional resets previous after images
					if (currentTab != null) {
						//$(".projects .panes div .afterImage").eq(currentTab).css("display","none");
						$(".projects .panes div .afterImage").eq(currentTab).fadeOut(400);
						$(".projects .panes div .labelAfter").eq(currentTab).css("display","none");
					}
			},
			onClick: function(event, tabIndex) {
					//conditional resets previous after images
					
					//update current tab for next tab click
					currentTab = tabIndex;
				
				//animatein current after images
				$(".projects .panes div .afterImage").eq(tabIndex).delay(1000).fadeIn(3000);
				$(".projects .panes div .labelAfter").eq(tabIndex).delay(1000).fadeIn(3000);
			}
		});

});

