var videopath = "http://smile-4-life.de/";
var swfplayer = "http://smile-4-life.de/fileadmin/rosin/js/flowplayer/flowplayer-3.1.1.swf";

$(document).ready(function(){
	//Lightbox mit Flowplayer
	$("#links_inhalt a[href$='.flv']").each(function(){
		videoclip=$(this).attr('href');
		$(this).attr('href', "#video_box");
		$(this).fancybox({
			'hideOnContentClick':false,
			'overlayOpacity' :.6,
			'zoomSpeedIn' :400,
			'zoomSpeedOut' :400,
			'callbackOnShow' :function(){
				player = $f("fancy_content",swfplayer,{
					play:{opacity:0},
					clip:{
						autoPlay:true,
						autoBuffering:true,
						url:videopath+videoclip+'',
						onStart:function(clip){
							var wrap=jQuery(this.getParent());
							var clipwidth = clip.metaData.width;
							var clipheight= clip.metaData.height;
							var pos = $.fn.fancybox.getViewport();
							$("#fancy_outer").css({width:clipwidth,height:clipheight});
							$("#fancy_outer").css('left',((clipwidth + 36)> pos[0]?pos[2]:pos[2]+Math.round((pos[0]-clipwidth-36)/2)));
							$("#fancy_outer").css('top',((clipheight + 50)> pos[1]?pos[3]:pos[3]+Math.round((pos[1]-clipheight-50)/2)));
						},
						onFinish:function(){
							$('#fancy_close').trigger('click');
						}
					}
				});
				player.load();
				$('#fancy_close').click(function(){
					$("#fancy_div_api").remove();
				});
			}
		});
	});
	
	$("#links_inhalt a[href*=file]").each(function(){
//		alert($(this).attr("href").match(/file=(.)+\.jpg/));
//		var filtered = $(this).attr("href").match(/file=(.)*jpg/);
		var filtered = $(this).attr("href").slice($(this).attr("href").search(/file=/)+5, $(this).attr("href").search(/.jpg/)+4);
		if(filtered.length<=0){
			filtered = $(this).attr("href").slice($(this).attr("href").search(/file=/)+5, $(this).attr("href").search(/.png/)+4);
		}
		if(filtered.length<=0){
			filtered = $(this).attr("href").slice($(this).attr("href").search(/file=/)+5, $(this).attr("href").search(/.gif/)+4);
		}
		if(filtered.length>0) {
			$(this).attr("href", filtered.replace(/\%2F/g,"\/"));
			$(this).removeAttr("onClick");
			$(this).removeAttr("target");
			$(this).fancybox({
				'hideOnContentClick':true,
				'overlayOpacity' :.6,
				'zoomSpeedIn' :400,
				'zoomSpeedOut' :400			
			});
		}
	});
});
