Flowplayer = function(){

	return {

		init: function(selector, swf_url){
			$(selector||"body").find("a[href$='.mov'], a[href$='.mp4'], a[href$='.m4v']").not(".WGA-Item-Value-Unencoded a")
			.each(function(index, el){
				var img = $(el).find("img");
				if(img.length){
					$(el).width(img.width()).height(img.height());
					img.load(function(){
						$(el).width(img.width()).height(img.height());
					})
				}
				$(el).addClass("video-container");
				var img_wrapper = $("<span class='wrapper' title='Click to play Video ... ...'/>");
				var headline = $("<span class='headline'><span>"+(el.title||"video")+"</span></span>");
				var player = $(el).addClass("video-container").append(img_wrapper).append(headline);					
				
				$f(el, {
					src: "/plugin-flowplayer/file/distribution/flowplayer-3.2.7.swf",
					wmode: "opaque"
				},
				{
					clip: {
						scaling: 'fit'
				 	}
				});
			})
		},
		
		initOverlay: function(config){
			var config = config||{};
			var overlay = $('<div id="flowplayer-overlay" class="flowplayer-overlay"/>')
			var player = $('<div class=""player"/>');
			player.width(config.width||800).height(config.height||530);
			$("body").append(overlay);
			$(overlay).append(player);
			var player = $f(player[0], {
					src: config.swf||"/plugin-flowplayer/file/distribution/flowplayer-3.2.7.swf",
					wmode: "opaque"
				},
				{
					clip: {
						scaling: 'fit'
				 	}
				}
			);

			$(config.selector||"body").find("a[href$='.mov'], a[href$='.mp4'], a[href$='.m4v']").not(".WGA-Item-Value-Unencoded a")
			.each(function(index, el){
				var img = $(el).find("img");
				if(img.length){
					$(el).width(img.width()).height(img.height());
					img.load(function(){
						$(el).width(img.width()).height(img.height());
					});
					var wrapper = $("<span class='wrapper'/>");
					var headline = $("<span class='headline'><span>"+(el.title||"video")+"</span></span>");
					$(el).addClass("video-container").append(wrapper).append(headline)
				}
				$(el).attr("rel", "#flowplayer-overlay")
				.overlay({
					mask: config.mask||"#666666",
					onLoad: function() {			
						player.play(this.getTrigger()[0].href);
					},
					onClose: function() {
						player.stop();
						player.unload();
					}
				});
			})
		}
		
	}
	
}()
