$(function () {
        $('.bubbleInfo').each(function () {
            var distance = 10;
            var time = 250;
            var hideDelay = 500;

            var hideDelayTimer = null;

            var beingShown = false;
            var shown = false;
            var trigger = $('.trigger', this);
            var info = $('.popup', this).css('opacity', 0);


            $([trigger.get(0), info.get(0)]).mouseover(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                if (beingShown || shown) {
                    // don't trigger the animation again
                    return;
                } else {
                    // reset position of info box
                    beingShown = true;

                    info.css({
                        top: 50,
                        right: 0,
                        display: 'block'
                    }).animate({
                        top: '+=' + distance + 'px',
                        opacity: 1
                    }, time, 'swing', function() {
                        beingShown = false;
                        shown = true;
                    });
                }

                return false;
            }).mouseout(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                hideDelayTimer = setTimeout(function () {
                    hideDelayTimer = null;
                    info.animate({
                        top: '+=' + distance + 'px',
                        opacity: 0
                    }, time, 'swing', function () {
                        shown = false;
                        info.css('display', 'none');
                    });

                }, hideDelay);

                return false;
            });
        });
        function centerProjects(){
        var sliderDiv = $("#project-list");
        var projects = $("#project-list li.project").length;
        var listwidth = projects * 1080;
        $(sliderDiv).width(listwidth)
		var sliderMask = $("#projects");
		var position = sliderDiv.position();
		var sliderWidth = sliderDiv.width();
		var minX = 0;
		var maxX = minX + sliderWidth;
		var width = sliderMask.width();
		var center = sliderWidth / 2;
		var left = (maxX - width) / 2 * -1;
		jQuery(sliderDiv).css("left", left+"px");
		}
		function onKeyUp(evt) {
		     if (evt.keyCode == 39) {
		    	scrollLeft();
		    }
		    if (evt.keyCode == 37) {
		    	scrollRight();
		    }
		   
		}
		
		$("li.left-nav a").click(scrollRight);
		$("li.right-nav a").click(scrollLeft);
		
		function scrollLeft(){
			var position = $("#project-list").position();
			var width = $("#project-list").width();
			
			if(position.left > ((width * -1)+2160)){
			$("#project-list").animate({
		    		left: '-=1080'
		    	}, 700);
		    	}
		    
		}
		function scrollRight(){
			var position = $("#project-list").position();
			var width = $("#project-list").width();
			if(position.left < 0){
			$("#project-list").animate({
		    		left: '+=1080'
		    	}, 700);
		    }
		}
		centerProjects();
		$(document).keyup(onKeyUp);
		$(window).resize(centerProjects)

		$("a#about-link").click(function(){
    		if ($("#contact-bar").length == 0) {
    		$("body").prepend('<div id="contact-bar"></div>');
    		$("#contact-bar").load('about.html', function() {
				$(this).slideDown();
			});
    		} else {
    			$("#contact-bar").slideToggle();
    		}
    	});


});


    

