$(document).ready(function(){
	initPlayers();
});
function initPlayers(){
    
	links = {};
	var overlayParams = {

		
		expose: '#000000',				
		
		onLoad: function(content) {
			// find the player contained inside this overlay and load it
			this.getOverlay().find("a.player").flowplayer(0).load();
		},
		
		onClose: function(content) {
			$f().unload();
		}
	}
	
	$(".videoLink").each(function(counter){
		href = $(this).attr("href");
		$(this).attr("rel","#overlay"+counter);
		
		$("body").append('<div class="overlay" id="overlay'+ counter + '"><a class="player" href="' + href + '"> </a></div>');
		
		$(this).overlay(overlayParams);
	});
	
	// install flowplayers
	$("a.player").flowplayer("/content/flowplayer/flowplayer-3.2.1.swf"); 
}

var t;

function showPopup(e, head, address, date, link) {
	
	clearTimeout(t);
	
	var left = $(e).css("left");
	var top = $(e).css("top");
	
	left = left.replace("px", "");
	top = top.replace("px", "");
	
	if($(e).hasClass("passive")) {
		$(".bubble h3").show();
	} else {
		$(".bubble h3").hide();
	}
	
	$("#popupHeading").html(head);
	$("#popupAddress span").html(address);
	$("#popupDate span").html(date);
	$("#popupLink a").html(link);
	$("#popupLink a").attr("href", "http://"+link);
	
	$(".bubble").fadeIn("fast");
	
	$(".bubble").css("left", left - 145 + $(e).width()/2 + "px");
	$(".bubble").css("top", top - $(".bubble .padding").height() - 30 + "px");
	
	
	
}

function keepPopup() {
	clearTimeout(t);
}

function hidePopup() {
	clearTimeout(t);
	t = setTimeout("timedHide()", 100);
}

function timedHide() {
	$(".bubble").fadeOut("fast");
}






