$(document).ready(function(){

	$('#popup').css({opacity:0});

	fresh = true;
	burn = false;
	newX = '';
	url = '';

	$('#header ul li[class*=bubble]').hover(function(e){
		offset = $(this).offset();
		newX = (offset.left - 100) + ($(this).outerWidth()/2);
		burn = false;
		url = $(this).children('a').attr('href');
		img = 'url(global/images/template/bubble_'+$(this).attr('title')+'.gif)';
		if(fresh){
			$('#popup').css({left:newX});
			fresh = false;
		}
		$('#popup h2').css({backgroundImage:img});
		$('#popup').stop([]).show().animate({opacity:1, top:22, left:newX}, 400, 'easeOutExpo');
	},function(e){
		$('#popup').stop([]).animate({opacity:0, top:10}, 200, function(){
			$(this).hide();
			fresh = true;
		});
	});
	
	$('#popup').hover(function(){
		if(fresh==false && burn==false){
			theClass = $('a[href='+url+']').parent('li').attr('class') + 'on';
			$(this).stop([]).show().animate({opacity:1, top:22, left:newX}, 400, 'easeOutExpo');
			$('a[href='+url+']').parent('li').addClass(theClass);
		}
	},function(){
		$(this).stop([]).animate({opacity:0, top:10}, 200, function(){
			$(this).hide();
			fresh = true;
		});
		$('a[href='+url+']').parent('li').removeClass(theClass);
		burn = true;
	});
	
	$('#popup').click(function(){
		document.location = url;
	});

});

jQuery.extend( jQuery.easing,{
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	}
});
