this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 120;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("li.tooltip").hover(function(e){											  
		this.t = $('.bubble', this).html();
		this.title = "";									  
		$("body").append("<div id='tooltip'>"+ this.t +"</div>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("li.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

$(function() {

	tooltip();
	
	$('body').addClass('js');

	$('#slideshow').nivoSlider({
		effect: 'fold',
		directionNavHide:false,
		pauseTime:5000
	});
	
	$('.project-thumbs a').fancybox();
	$('a.fancybox').fancybox();
	
	$('#projects li a').hover(function() {
			$('#project-hover-title').html($(this).attr('title'));
			$('#project-hover-title').stop().animate({"opacity": "1"}, "medium");
		},
		function() {
			$('#project-hover-title').stop().animate({"opacity": "0"}, "medium");
		}
	);
	
	$('#projects li a').click(function() {
		$('#project-wrapper').slideUp('slow');
		var $this = $(this);
		var toLoad = $this.attr('href')+'.json';
		$.ajax({
			url: toLoad,
			dataType: 'json',
			success: function(data) {
				$('#large-image img').attr('src', '/projects/image/large/'+data.Project.thumb);
				$('#project-title').html(data.Project.title);
				$('#project-description').html('<p>'+data.Project.description+'</p>');
				$('#album-link').attr('href', '/sectors/'+data.Sector.slug+'/'+data.Project.slug);
				$this.addClass('current');
				$('#project-wrapper').slideDown('slow');
			}
		});
		return false;
	});
	
	$('ul#mainNav ul:not(.current)').hide();
	
	$('ul#mainNav a[href^="#"]').click(function() {
		$(this).parent('li').siblings('li').children('ul').slideUp();
		var toShow = $(this).attr('href');
		$(toShow).slideToggle();			
		return false;
	});

	var container = $('#sliderWrap');
    var ul = $('#sliderChoices');
    var tabContainers = $('#show-year > div');

	$('#sliderWrap').scrollable({ size:5, prev:'.prevSlide',next:'.nextSlide',items:'#sliderChoices', hoverClass:'hover',loop:true});
    
    $('a', ul).click(function () {
	var toShow = $(this).attr('href');
        tabContainers.hide().filter(toShow).show();
        
        $('a', ul).removeClass('selected');
        $(this).addClass('selected');
        
        return false;
    }).filter(':first').click();

	$('.blue-fade').hover(function() {
		$(this).stop().animate({opacity:0});
	}, function() {
		$(this).stop().animate({opacity:0.5});		
	});

});
