function flumotionVideoPlayer(URL,thumb, width, height, play,type,externalUrl) {

	switch(String(type)) {
		case "1": //youtube		
		//alert("youtube     "  + URL);
				var html = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'">';
			    html += '<param name="movie" value="http://www.youtube.com/v/' + externalUrl + '" />';
			    html += '<param name="wmode" value="transparent" />'; 
			    html += '<embed src="http://www.youtube.com/v/' + externalUrl + '" wmode="transparent" width="'+width+'" height="'+height+'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">';			    
			    html += '</object>';
				break;		
		
		case "2": //qik		
		//alert("qik     "  + URL);
				var html = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'" id="thumbnail" align="middle" style="position:relative">';
			    html += '<param name="movie" value="http://qik.com/player.swf' + externalUrl + '" />';
			    html += '<param name="quality" value="high" />';
			    html += '<param name="allowScriptAccess" value="always" />';  
			    html += '<param name="swLiveConnect" value="true" />'; 
			    html += '<param name="wmode" value="transparent" />';   
			    html += '<embed src="http://qik.com/player.swf' + externalUrl + '" quality="high" wmode="transparent" width="'+width+'" height="'+height+'" name="thumbnail" align="middle" allowScriptAccess="always" swLiveConnect="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">';			    
			    html += '</object>';
				break;
				
		case "3": //fabchannel		
		//alert("fabchannel     "  + URL);
				var html = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'" id="thumbnail" align="middle" style="position:relative">';
				    html += '<param name="movie" value="http://www.fabchannel.com/embed/player.swf' + externalUrl + '" />';
				    html += '<param name="quality" value="high" />';
				    html += '<param name="allowScriptAccess" value="always" />';  
				    html += '<param name="swLiveConnect" value="true" />'; 
				    html += '<param name="wmode" value="transparent" />'; 
				    html += '<embed src="http://www.fabchannel.com/embed/player.swf' + externalUrl + '" quality="high" wmode="transparent" width="'+width+'" height="'+height+'" name="thumbnail" align="middle" allowScriptAccess="always" swLiveConnect="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></object>';			    	
				break;
								
		default: // video normal, el de siempre
		//alert("normal     "  + URL);
				var init = "";
				if(play) {
					init = '&amp;empieza=' + play;
				}
				else {
					init = '&amp;cargavideo=no';
				}
				
			    var html = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'" id="videoPlayer" align="middle">';
			    html += '<param name="movie" value="http://'+location.host+'/static/common/swf/videoPlayer.swf" />';
			    html += '<param name="quality" value="high" />';
			    html += '<param name="bgcolor" value="#ffffff" />';  
			    html += '<param name="wmode" value="transparent" />';
			    html += '<param name="flashvars" value="video='+URL+'&amp;imagen_thum='+thumb+init+'" />';   
			    html += '<embed src="http://'+location.host+'/static/common/swf/videoPlayer.swf" quality="high" bgcolor="#ffffff" width="'+width+'" height="'+height+'" allowFullScreen="true" name="videoPlayer" align="middle" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="video='+URL+'&amp;imagen_thum='+thumb+init+'"></embed>';
			    html += '</object>';
	}
	
    return html;
}


function showPlayer(id, quality,thumb) {	
	if(quality == "high") {
 	      var width = "640";
	      var height = "480";
	      if(id == 3) {
	      	var height = "560";	      	
	      }
        } else {
	      var width = "320";
	      var height = "240";
	      quality = "low";
	}

	if(thumb=="undefined") thumb ="";
	html = flumotionVideoPlayer(id + "." + quality,thumb, width, height,1);
	$('video_player').innerHTML = html;
	
	var scrollval = document.documentElement.scrollTop;
	if($("video_layer")) $("video_layer").style.display = 'block';
	if (window.innerHeight) {
		var altopantalla = window.innerHeight;
	} else {
	 	var altopantalla = document.documentElement.clientHeight;
	}

	posy = parseInt(scrollval) + (parseInt(altopantalla/2) - parseInt($('video_wrap').offsetHeight/2));
	showLayerInPosition("video_wrap", (screen.width/2) - (width/2), posy);
}

function loadVideo(id, forceQuality,thumb) {	
	if(forceQuality != null) {
		quality = forceQuality + "/"; 
	} else {
		quality = "";
	}	
	getChunk("/video/" + id + "/" + quality, "video_layer", function () {
		showPlayer(id,forceQuality,thumb);
	});		
}

function videoChunk(contentId, layerId, alternateId) {
	if(alternateId != null) {
		alternateId = trim(alternateId) + "/";	
	} else {
		alternateId = "";
	}

	contentId = contentId.replace(" ", "");
	alternateId = alternateId.replace(" ", "");

	getChunk("/video/chunk/" + contentId + "/" + alternateId, layerId);
}

