$(document).ready(function(){
	$(".link1").click(function(e) {

		//get positioning of clicked item (this)
		myPosition = $(this).position();
		
		//window height, scrollTop
		winHeight = $(window).height();
		winScroll = $(window).scrollTop();

		//get default top
		if(winHeight > 0)
		{
			defTop = Math.round((winHeight - 430) / 2) + winScroll;
		}		

		//set Top, Left, FLV File Name and Title text
		pTop = defTop;
		pLeft =  myPosition.left + 50;
		
		file = $(this).metadata().flvName;
		title = $(this).metadata().title;
		
		//get custom Left, Top if present
		newTop = $(this).metadata().nTop;
		newLeft = $(this).metadata().nLeft;

		//if no custom positioning, use defaults; else, convert custom to integers
		if ((newTop == "") || (newTop == null)) {
			pTop = defTop;
		}
		else {
			pTop = Number($(this).metadata().nTop);
		}

		if ((newLeft == "") || (newLeft == null)) {
			pLeft = myPosition.left + 50;
		}		
		else {
			pLeft = Number($(this).metadata().nLeft);
		}
		

		//get player name
		flvPlayer = $(this).metadata().flvPlayer;
		
		//set player
		if ((flvPlayer == "") || (flvPlayer == null)) {
			flvPlayer = "flv/visa_resource_center_410x229.swf";
		}
		else {
			flvPlayer = flvPlayer = $(this).metadata().flvPlayer;
		}
		
		//get flv width, height
		flvWidth=$(this).metadata().flvWidth;
		flvHeight=$(this).metadata().flvHeight;
		
		//set flv width
		if ((flvWidth == "") || (flvWidth == null)) {
			flvWidth = 420;
		}		
		else {
			flvWidth = Number($(this).metadata().flvWidth);
		}
		
		
		//set flv height
		if ((flvHeight == "") || (flvHeight == null)) {
			flvHeight = 255;
		}		
		else {
			flvHeight = Number($(this).metadata().flvHeight);
		}		
		
		//get tooltip width, height
		tWidth=$(this).metadata().tWidth;
		tHeight=$(this).metadata().tHeight;
		
		//set tooltip width
		if ((tWidth == "") || (tWidth == null)) {
			tWidth = 430;
		}		
		else {
			tWidth = Number($(this).metadata().tWidth);
		}
				
		//set tooltip height
		if ((tHeight == "") || (tHeight == null)) {
			tHeight = 275;
		}		
		else {
			tHeight = Number($(this).metadata().tHeight);
		}		
		

		//call to jTipFLV function with correct parameters
		jTipFLV(pTop, pLeft, tWidth, tHeight, file);
		
		//prevent default event from firing
		e.preventDefault();
	});
});


function jTipFLV(pTop, pLeft, tWidth, tHeight, flv){
	$(".vidPanel").hide();
	resetVideo();
	playVideo(pTop, pLeft, tWidth, tHeight, flv);
	$("#panel1").show();
}

function resetVideo() {
	if($('#flash-replaced').hasClass('flash-replaced') && $('#flash-replaced div.alt').length > 0) {
		var old = $('#flash-replaced div.alt').html();
		$('#flash-replaced').empty().html(old)
	}
}

function playVideo(pTop, pLeft, tWidth, tHeight, flv) {
	//set panel1 positioning + call to bgiframe for IE6
	
	$("#panel1").css({ "top": pTop, "left": pLeft, "width": tWidth, "height":tHeight }).bgiframe();
	
	//get FLV file name
	if (flv != null) {
		var myFLV = flv ;
	}
	
	//call to jquery flash to embed FLV
	$('#flash-replaced').flash(
	{
	  	src: flvPlayer,
	  	menu: 'false',
	  	width: flvWidth,
	  	height: flvHeight,
	  	flashvars: { videoURL: flv }
	},
		{ version: 8, update: false }
	);
	
	//set title text
	$(".flv_title").text(title);
	
	//set cursor for close graphic
	$(".flvPanel_closewindow img").unbind("hover").hover(function() {
		$(this).css("cursor", "pointer");
		if ( $('.flvPanel_closewindow img').attr("src") == "img/other/close_gray.gif" ) {
			$('.flvPanel_closewindow img').attr("src", "img/other/close_gray_hover.gif");
		}
	}, function() {
		$(this).css("cursor", "auto");
		if ( $('.flvPanel_closewindow img').attr("src") == "img/other/close_gray_hover.gif" ) {
			$('.flvPanel_closewindow img').attr("src", "img/other/close_gray.gif");
		}
	});
	
	//close graphic function
	$(".flvPanel_closewindow img").unbind("click").click(function(e) {
		$(".flvPanel").hide();
		resetVideo();
		e.preventDefault();
	});	
}