/*
function deactivateSwfVideoDivs(){
	while (window.activeSwfVideoDivs.length > 0){
		var div = window.activeSwfVideoDivs.pop();
		swfobject.removeSWF(div.attr("flashSpanId"));
		div.html(div.data("divSpanData"));
	}
}
*/
$(function(){
	window.swfflashSpanIdCounter = 0;
//	window.activeSwfVideoDivs = new Array();
	
	$("div.swfVideo:not(.swfEnabled)").each(function(){
		var div = $(this);
		
		window.swfflashSpanIdCounter++;
		var flashSpanId = "swfVideodiv_" + window.swfflashSpanIdCounter;  
		var divSpanData = '<span id="' + flashSpanId + '"></span>';
		div.html(divSpanData);
		div.data("divSpanData", divSpanData);
		div.attr("flashSpanId", flashSpanId);
		
		var videoWidth = div.attr("videoWidth");
		var videoHeight = div.attr("videoHeight");
		if (videoWidth == "") {
			videoWidth = div.outerWidth();
			videoHeight = div.outerHeight();
		}
		
		var playerUrl = div.attr("playerUrl");
		var videoUrl = div.attr("videoUrl");
		var imageUrl = div.attr("imageUrl");
		var linkUrl = div.attr("linkUrl");
		var flashvars = {
			videoURL: videoUrl,
			autoreplay: "false",
			imageUrl: imageUrl,
			linkUrl: linkUrl,
			showFlscr: "false"
		};
		var params = {
			menu: "false",
			wmode: "transparent",
			allowFullScreen: "true"
		};
		var attributes = {};
		
		div.mouseenter(function(){
			if (div.attr("swfVideoActivated") != 1){
				div.attr("swfVideoActivated", 1);
				var rnd = parseInt(Math.random() * 10000000000000, 10);
				var currFlashVars = flashvars;
				currFlashVars.videoURL =  flashvars.videoURL + "?_=" + rnd;
				swfobject.embedSWF(playerUrl, flashSpanId, videoWidth, videoHeight, "9.0.0", "expressInstall.swf", flashvars, params, attributes);
//				window.activeSwfVideoDivs.push(div);
			}
		});
		/*div.mouseleave(function(e){
			deactivateSwfVideoDivs();
		});*/
	}).addClass("swfEnabled");
});