/**
 * @author Publicis Modem & Dialog
*/

var heroWidth = "957";
var heroHeight = "327";
var videoWidth = "570";
var videoHeight = "324";
var ver = "9.0.45";
var replaceID = "wall-replace";
var basePath = resources+"/flash/";
var expressInstall = basePath + "swfs/expressInstall.swf";
var file = basePath + "swfs/preloader.swf"
var flashvars = {flashPath: basePath};
var params = {
	wmode: "transparent",
	SeamlessTabbing:"false",
	bgcolor: '#FFFFFF', 
	menu: 'false', 
	scale:'noscale', 
	allowScriptAccess:"sameDomain", 
	allowFullScreen:"true"
};
var videoParams = params;
videoParams.scale = "scale"
var videoAtts = {'class':'videoPlayer'};
var attributes = {
	id: "flashHeader",
	name: "flashHeader",
	'class':"flashHeader"
};

swfobject.embedSWF(file, replaceID, heroWidth, heroHeight, ver,expressInstall, flashvars, params, attributes);

/*
embed video players
*/

$(document).ready(setVideoPlaceholders);

function setVideoPlaceholders(){
	var replacetags = $(".entry-asset a");
	jQuery.each(replacetags, function(i, val){
		if($(val).attr('href').indexOf('.flv') > -1){
			$(val).wrap("<span style='display:block;height:"+videoHeight+"px;'></span>")
			var idval = "flashreplace-" + i;
			$(val).attr("id", idval);
			if($(val).find("img")[0] && location.hash != "#play"){
				var placeholdersrc = escape($($(val).find("img")[0]).attr('src'));
				var path =  escape($(val).attr('href'))
				embedLinkFlashVideo($(val), path, placeholdersrc, false, idval)
			}else if(location.hash == "#play"){
				var placeholdersrc = escape($($(val).find("img")[0]).attr('src'));
				var path = escape($(val).attr('href'))
				embedLinkFlashVideo($(val), path, placeholdersrc, true, idval)
			}else{
				var path = escape($(val).attr('href'))
				embedLinkFlashVideo($(val), path, "", false, idval)
			}
		}
	});
};
function embedLinkFlashVideo($target, $path, $placeholder, $autoplay, $ID, $width, $height){
	$width = typeof $width != 'undefined' ? $width : videoWidth;
	$height = typeof $height != 'undefined' ? $height : videoHeight
	var data = {
		'videoUrl': $path.split('%23')[0],
		'imageUrl': $placeholder,
		'xmlFileLocation' : resources+'/xml/videocuepoints.xml',
		'videoName' : $path.indexOf('%23') != -1 ? $path.split('%23')[1] : "EMPTY-NODE",
		'playerID' : $ID,
		'videoWidth' : $width,
		'videoHeight' : $height
	}
	if($autoplay){
		data.autoPlay = $autoplay;
		$("body").data("playing", {
			"id": $target.attr("id"),
			"node": $target.parent().html()
		});
	}
	var basePath = resources+"/flash/";
	var file = basePath + "video-player/swfs/MoviePlayer.swf";
	$target.attr('href','http://get.adobe.com/flashplayer');
	$target.text("Download the Adobe Flash Player to view this content.");
	swfobject.embedSWF(file, $target.attr('id'), videoWidth, videoHeight, ver, expressInstall, data, videoParams, videoAtts);
}

