// JavaScript Document
function hoverbox_init(opts) {
	var c=opts.element;
	var hb=$("#hoverbox div");
	$("#hoverbox").css("position","absolute");
	$("#hoverbox").css("display","block");
	hb.css("position","absolute");
	opts.top ? hb.css("top",opts.top) : "";
	opts.left ? hb.css("left",opts.left) : "";
	hb.html($(c).html());
	hb.addClass("sf-menu");
	$("#hoverbox").hover(
		function () {
			hb.fadeIn("fast");
		}, 
		function () {
			hb.fadeOut("fast");
		}
	);
}
function hoverbox_taglineInit() {
	var tags=".tagline";
	var distance = 10;
	var time = 250;
	var top;
	$(tags).each(function() {
		var pw=$(this).parent().width();
		var ph=$(this).parent().height();
		var offset=$(this).parent().offset();
		$(this).css("width","auto");
		$(this).css("height","auto");
		var w=$(this).width();
		var h=$(this).height();
		w>pw ? w=pw-2 : "";
		
		var m=parseInt(pw/2-w/2);
		top=parseInt(ph-100);/*
		//alert("w: "+w+" pw: "+pw+" m: "+m+" top: "+top+" ph :"+ph)
		$(this).css("position","absolute");
		$(this).css("top",top+"px");
		$(this).css("margin-left",m+"px");
		$(this).css("left",offset.left+"px");
		//alert($(this).css("left"));
		//$(this).css("width",(w-m/2)+"px");
		$(this).css("display","block");
	
		$(this).css('opacity', 0);
		*/
		$(this).css("display","none");
	});
	var overBubble=false;
	$(".hoverbox_tagline").hover(
		function () {
            if ($(this).beingShown || $(this).shown) {
				// don't trigger the animation again
				return;
			}
			else {
                $(this).beingShown = true;
				var tagline = $(this).children(tags);
				$(this).append(hoverbox_container(tagline.html()));
				var bubble = $(this).children(".bubble");
				bubble.hover(
					function(){
						overBubble=true;
					},
					function(){
						overBubble=false;
					}
				);
				var offset=$(this).offset();
				var pw=$(this).width();
				var ph=$(this).height();
				bubble.css("left",offset.left+"px");
				var w=bubble.width();
				var h=bubble.height();
				w>pw ? w=pw-2 : "";
				var m=parseInt(pw/2-w/2)-10;
				if($.browser.msie) m=parseInt(m/2);
				bubble.css({
						   'margin-left'	:	m+"px",
						   'width'			:	pw/2
				});
				bubble.corners("10px");
				bubble.css({
					top: (top+10)+'px',
					display: 'block'
				}).animate({
					top: '+=' + distance + 'px',
					opacity: 0.88
				}, time, 'swing', function() {
                    $(this).beingShown = false;
                    $(this).shown = true;
                });
			}
		}, 
		function () {
			if(!overBubble) {
				var bubble = $(this).children(".bubble");
				bubble.animate({
					top: '-=' + distance + 'px',
					opacity: 0
				}, time, 'swing', function(){
					$(this).beingShown = false;
					$(this).shown = false;
					bubble.remove();
				});
			}
		}
	);
}
function hoverbox_container(data) {
	return '<div class="bubble">'+data+'</div>';
	/*
    return '<div class="bubbleInfo">'+
        '<table id="dpop" class="popup">'+
        	'<tbody><tr>'+
        		'<td id="topleft" class="corner"></td>'+
        		'<td class="top"></td>'+

        		'<td id="topright" class="corner"></td>'+
        	'</tr>'+
        	'<tr>'+
        		'<td class="left"></td>'+
        		'<td><table class="popup-contents">'+
        			'<tbody><tr>'+
						'<td>'+data+'</td>'+
        			'</tr>'+
        		'</tbody></table>'+
        		'</td>'+
        		'<td class="right"></td>'+ 
        	'</tr>'+
        	'<tr>'+
        		'<td class="corner" id="bottomleft"></td>'+
        		'<td class="bottom"><img width="30" height="29" alt="popup tail" src="/css/gui/images/bubble-tail2.png"/></td>'+
        		'<td id="bottomright" class="corner"></td>'+
        	'</tr>'+
        '</tbody></table>'+
    '</div>';*/
}