jQuery(document).ready(function($) {
    var which = '';
    var fadeTime;
    timeoutID = '';
   	$(".projsol").hover(function() { hoverOn(1); }, function() { hoverOff(); });
	$(".interstaf").hover(function() { hoverOn(2); }, function() { hoverOff(); });
	$(".execsearch").hover(function() { hoverOn(3); }, function() { hoverOff(); });
	$(".attpara").hover(function() { hoverOn(4); }, function() { hoverOff(); });
    
    function hoverOn(linknum) {
        fadeTime = 1000;
        
        if (linknum == which) {
            return;
        }
        else {
            clearTimeout(timeoutID);
            switch(linknum) {
                case 1:
                    $('#bg_link1, #msg1').css('display', 'block').animate({ opacity: 1 }, fadeTime, function() {
                        if (this.style.removeAttribute && $('#msg1').css('filter')) {
                            this.style.removeAttribute('filter');
                        }
                    });
                    $('#bg_link2, #bg_link3, #bg_link4, #mainbg, #default_message, #msg2, #msg3, #msg4').animate({ opacity: 0 }, fadeTime);
                    which = 1;
                    break;
                case 2:
                    $('#bg_link2, #msg2').css('display', 'block').animate({ opacity: 1 }, fadeTime, function() {
                        if (this.style.removeAttribute && $('#msg2').css('filter')) {
                            this.style.removeAttribute('filter');
                        }
                    });
                    $('#bg_link1, #bg_link3, #bg_link4, #mainbg, #default_message, #msg1, #msg3, #msg4').animate({ opacity: 0 }, fadeTime);
                    which = 2;
                    break;
                case 3:
                    $('#bg_link3, #msg3').css('display', 'block').animate({ opacity: 1 }, fadeTime, function() {
                        if (this.style.removeAttribute && $('#msg3').css('filter')) {
                            this.style.removeAttribute('filter');
                        }
                    });
                    $('#bg_link1, #bg_link2, #bg_link4, #mainbg, #default_message, #msg1, #msg2, #msg4').animate({ opacity: 0 }, fadeTime);
                    which = 3;
                    break;
                case 4:
                    $('#bg_link4, #msg4').css('display', 'block').animate({ opacity: 1 }, fadeTime, function() {
                        if (this.style.removeAttribute && $('#msg4').css('filter')) {
                            this.style.removeAttribute('filter');
                        }
                    });
                    $('#bg_link1, #bg_link2, #bg_link3, #mainbg, #default_message, #msg1, #msg2, #msg3').animate({ opacity: 0 }, fadeTime);
                    which = 4;
                    break;
            }
        }
    }
    
    function hoverOff() {
        timeoutID = setTimeout(function() {
            $('#mainbg, #default_message').animate({ opacity: 1 }, 800, function() {
                if (this.style.removeAttribute && $('#default_message').css('filter')) {
                    this.style.removeAttribute('filter');
                }
            });
            $('.bg_links, #msg1, #msg2, #msg3, #msg4').animate({ opacity: 0 }, 800, function() { $(this).css('display', 'none'); });
            which = '';
        }, 300);
    }
   	
   	
   	$('.nav-services li').hover(function() {
   	    $('.nav-services li').css('opacity', 0.6);
   	    $(this).css('opacity', 1);
   	}, function() {
   	    $('.nav-services li').css('opacity', 1);
   	});
 });
