$(document).ready(function() {
	
	//intercept the A tags and check for the .flv termination
	$('A[href]').click(function() {
		var link=$(this).attr('href');
		var isflv = false;
		if(link.indexOf('.mp4') == (link.length - 4) && link.length > 5) isflv=true;
		//console.info(isflv);
		if(isflv)
		{
			var havedivs=$('#moviedivoverlay').length;
			if(!havedivs)
			{
				$('BODY').append('<div id="moviedivoverlay"></div><div id="moviediv"></div>');
				havedivs=$('#moviedivoverlay').length;
			}
			$('#moviedivoverlay').show();
			$('#moviediv').show();
			var vh;
			var vw;
			var videobase;
			//get the sizes
			var vp=link.split('_');
			vw=vp[0];
			vw=vw.split("/");
			vw=parseInt(vw[vw.length-1]);
			vh=vp[1];
			videobase=link.substr(0,link.length-4);
			//alert(videobase);
			var html='<center><div id="moviedivclose" style="width: '+(vw+28)+'px; text-align: right;" onclick="lightvideoclose()"></div>';
			html+='<iframe name="videoIframe" src="video.php?vh='+vh+'&vw='+vw+'&video='+escape($('BASE').attr('href') + videobase)+'.mp4" scrolling="no" FRAMEBORDER="0" style="width:'+vw+'px; height: '+vh+'px; border:0;"></iframe>';
			//html+='<source src="'+$('BASE').attr('href') + videobase+'.mp4" type="video/mp4">';
			//html+='<source src="'+$('BASE').attr('href') + videobase+'.webm" type="video/webm">';
			html+='</video></center>';
			//alert(vw);
			//setTimeout('$("#my_video_1").css("width", "'+vw+'px")', 1000);

			/*	<object width="750" height="421" id="flvPlayer">'; 
			html+='<param name="movie" value="fileadmin/sys/videoplayer-.swf?movie='+$("base").attr("href") + link+'&btncolor=0x333333&accentcolor=0x31b8e9&txtcolor=0xdddddd&volume=30&autoload=on&autoplay=on&controls=false">';
			html+="<param name='controls' value='false'>";
			html+="<embed src='fileadmin/sys/videoplayer-.swf?movie="+$("base").attr("href") + link+"&btncolor=0x333333&accentcolor=0x31b8e9&txtcolor=0xdddddd&volume=30&autoload=on&autoplay=on&controls=false' width='750' height='421' allowFullScreen='false' type='application/x-shockwave-flash'>";
			html+='</object></center>';
			*/
			$('#moviediv').html(html);
			
			setTimeout('$(".vjs-loading-spinner").hide()', 2000);
			//console.info(havedivs);
		}
		return !isflv;
	});
});

function lightvideoclose()
{
	$('#moviediv').remove();
	$('#moviedivoverlay').remove();
}
