
videos = function(target) {
	var flashvars = {
			image: "/images/video_intro.png",// pass image URL if there is one

			autoplay: false,					// use to autoplay video
			//buffer: 3,						// set buffer length (default is 3)
			
			navAutoHideIdleTime: 2,				// set mouse idle time for navigation to hide
			navAutoHide: true,					// disable navigation auto hide
			//hideNav: true,					// turn off navigation

			//debug: true,						// debug mode
			//scaleMode: "crop",				// use "crop" to change, default mode is "fit"

			// THEMES //////////////////////////////////////////////////
			
			// theming is based on setting hue, saturation, brightness and constrast values
			// to 0xff0000 (red) colour
			
			customTheme: false			// enables custom colours
			
			// themeHue: 100,       // icons and GUI elements params
			// themeBrightness: 100,
			// themeConstrast: 25,
			// themeSaturation: -100,
			// 
			// handleHue: 0,        // handles (sliders) params
			// handleBrightness: 100,
			// handleConstrast: 100,
			// handleSaturation: 0,
			// 
			// preloaderHue: 100,     // preloader progress params
			// preloaderBrightness: -80,
			// preloaderConstrast: -50,
			// preloaderSaturation: 50,
			// 
			// backgroundFrom: 0xff9697A9,  // background colours (use rgb32, AARRGGBB)
			// backgroundTo: 0xff5C5E74
		};
		
    $(target).flash(
	    {
			src: '/flash/flvplayer.swf',
			width: 460,
			height: 368,
			allowFullScreen: true,
			flashvars: flashvars
	    },
	    { 
			update: false,
			expressInstall: false, 
			expressInstallSrc: "/flash/expressInstall.swf", 
			version: "9.0.115"
	    },
	    function(htmlOptions) {
			htmlOptions.flashvars.video = $(this).attr("href");
			img_class = '';
	        if ($($(this).children()[0]).is("img")) {
	          htmlOptions.width = $($(this).children()[0]).attr("width");
	          htmlOptions.height = $($(this).children()[0]).attr("height");
	          img_class = $($(this).children()[0]).attr("align");
	          htmlOptions.flashvars.image = $($(this).children()[0]).attr("src")
	        };
	        z = $.fn.flash.transform(htmlOptions);
	        if (img_class) {
	          z = z.replace('embed', 'embed class="' + img_class + '"');
	        }
	        $(this).before(z);
	        $(this).remove();
			// $(this).empty().append($.fn.flash.transform(htmlOptions));
	    }
	);
}

embed_videos = function() {
	$('#articleContainer a[href*="youtube.com"]').flash(
		{ width: 425, height: 350, wmode: 'transparent' },
		{ version: 8 },
		function(htmlOptions) {
			htmlOptions.src = "http://www.youtube.com/v/" + this.href.match(/v=(.+)/)[1];
			$(this).before($.fn.flash.transform(htmlOptions));
			$(this).remove();
		}
	);

	$('#articleContainer a[href*="vimeo.com"]').flash(
		{ width: 453, height: 340, quality:'best', allowfullscreen:'true', scale:'showAll' },
		{ version: 8 },
		function(htmlOptions) {
			htmlOptions.src = "http://vimeo.com/moogaloop.swf?clip_id=" + this.href.match(/(\d+)/)[1] + "&amp;server=vimeo.com&amp;fullscreen=1&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=FFCF4C";
			$(this).before($.fn.flash.transform(htmlOptions));
			$(this).remove();
		}
	);
}

if (($videos = $("#articleContainer a[href$='.flv'], #articleContainer a[href$='.mp4']")) && $videos.length > 0) videos($videos);
embed_videos();
