// Inserisce il video nel div inserito come placeholder
function drawControl(divObject,playerName,movieURL,width,height,autoStart,showControls) {
	var autoStartParam = "false";
	var showControlParam = "true";
	var autoStartEmbed = 0;
	var showControlEmbed = 0;
	
	var video = document.getElementById(divObject);
	var out = "";
		
	showControls = 1;
	
	video.innerHTML = out;
	if (autoStart) {
		autoStartParam = "true"
		autoStartEmbed = 1;
	}
	if (showControls) {
		showControlParam = "true";
		showControlEmbed = 1;
		height += 45 // aggiunge 45 px per l'ingombro della barra controlli
	}
	
	video.style.width= width;
	video.style.height= height;
	
	out +=  '<object classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" ' +
	        ' codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" '+
	        ' type="application/x-oleobject" name="'+playerName+'" '+
	        ' width="'+ width +'" height="'+height+'" '+
	        ' standby="Loading Microsoft Windows Media Player components..." id="'+playerName+'">'+
		    ' <param name="ShowCaptions" value="0">'+
		    ' <param name="FileName" value="'+ movieURL +'">'+
			' <param name="AnimationatStart" value="false">'+
			' <param name="TransparentatStart" value="true">'+
			' <param name="AutoStart" value="'+autoStartParam+'">'+
			' <param name="ShowControls" value="'+showControlParam+'">'+
			' <param name="ShowStatusBar" value="true">'+
			' <embed src="'+ movieURL +'" width="'+ width +'" height="'+height+'" type="application/x-mplayer2" '+
			' pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/" '+
			' name="'+playerName+'" ShowCaptions="0" '+
			' transparentAtStart="1" animationAtStart="0" showcontrols="'+showControlEmbed+'" AutoStart="'+autoStartEmbed+'">'+
			' </embed></object>';

	//alert(out);	
	
	video.innerHTML = out;
	
	return;
}



// SwapMovie()
// Cambia dinamicamente il filename all' oggetto Mediaplayer
function SwapMovie (Movie) {
	SwapObjMovie('videoPlaceHolder','MediaPlayer',Movie,384,288,true);	
}


function SwapObjMovie(objPlaceHolder,playerName, Movie, width, height,autostart) {
	
	var player = document.getElementById(playerName);
	
	if (navigator.appName == "Netscape") {
		// Mozilla
		drawControl(objPlaceHolder,playerName,Movie,width,height,autostart,true);
	} else if ((navigator.appName == "Microsoft Internet Explorer") && (window.ActiveXObject)) {
		// IE
		if ( player != null) {
			// se esiste l'oggetto mediaplayer
			player.Stop();			
			stopped = true;
			
			player.FileName=Movie;
			//drawControl(objPlaceHolder,playerName,Movie,width,height,autostart,false);
			
			var command="document.getElementById('"+playerName+"').Play()";
			//alert(command);			
			setTimeout(command,250);			
		}		
		else {			
  			drawControl(objPlaceHolder,playerName,Movie,width,height,autostart,false);
  		}
	} 
	else {
		
		drawControl(objPlaceHolder,playerName,Movie,width,height,autostart,true);
	}
	return true;
}

/**
 * NOTA:  i controlli di mediaplayer sono bypassati su mozilla perche non sono compatibili e
 * se seleziono causa un errore di javascript per metodo non supportato
 */
function PlayMovie(playerName) {
	var player = document.getElementById(playerName);
	if (navigator.appName == "Netscape") {
		// Mozilla
		player.Play();
	} else if (navigator.appName == "Microsoft Internet Explorer") {
		// IE
		player.Play();
	}
}

function PauseMovie(playerName) {
	var player = document.getElementById(playerName);
	if (navigator.appName == "Netscape") {
		// Mozilla
		player.Pause();
	} else if (navigator.appName == "Microsoft Internet Explorer") {
		// IE
		player.Pause();
	}
}

function StopMovie(playerName) {
	var player = document.getElementById(playerName);
	if (navigator.appName == "Netscape") {
		// Mozilla
		player.Stop();
	} else if (navigator.appName == "Microsoft Internet Explorer") {
		// IE
		player.Stop();
	}
}

function highlight(idlink,baseid) {
	 void(0);
	
	for( var i = 1; i < 10; i++) {
		var cur = baseid + i;
		if (cur == idlink) {
			document.getElementById(idlink).style.color = "\#B1DCFF";
		}
		else {
			if ( document.getElementById(cur)) {		
				document.getElementById(cur).style.color = "\#6EBCFE";
			}
		}
	}
}

function autoloadVideo(video, type) {
	var querystring = "";
	
	if ( window.top.location.search != 0 ) {
		querystring = window.top.location.search;
		
		var id_video = getParameter( querystring,'video');
		
		var id_page
		if (querystring.indexOf('&') > 0 ) {
		 	id_page = querystring.substring(0,querystring.indexOf('&'));
		}
		
		//alert("id_video: "+id_video +"\nquerystring: "+querystring +"\nvideo: "+video);
		
		if ( id_video != null) {
			//C_3_azienda_10_Interviste_video_VideoIntervista_0_filevideo.wmv?WMThinning=0
			//C_3_videocatalogo_4_prodotti_prodottiitem_0_video.wmv?WMThinning=0
			
			if (type == 'intervista') {
				var id_video_str = "VideoIntervista_"+id_video+"_";
				video = replaceSubstring(video,"VideoIntervista_0_",id_video_str);
			}
			else if (type == 'catalogo') {
				var id_video_str = "prodottiitem_"+id_video+"_";
				video = replaceSubstring(video,"prodottiitem_0_",id_video_str);
			}
			else {
				//file non riconosciuto
				SwapMovie(video);
				return;
			}
			
			SwapMovie(video);
			highlight('linkvideo'+ (parseInt(id_video) +1) ,'linkvideo');
		}
		else {
			SwapMovie(video); // parte il primo video se non ho parametri	
		}
	}
	else {
			
			SwapMovie(video); // parte il primo video se non ho parametri	
		}	
}

function getParameter ( queryString, parameterName ) {
	// Add "=" to the parameter name (i.e. parameterName=value)
	var parameterName = parameterName + "=";
	if ( queryString.length > 0 ) {
		// Find the beginning of the string
		begin = queryString.indexOf ( parameterName );
		// If the parameter name is not found, skip it, otherwise return the value
		if ( begin != -1 ) {
			// Add the length (integer) to the beginning
			begin += parameterName.length;
			// Multiple parameters are separated by the "&" sign
			end = queryString.indexOf ( "&" , begin );
			if ( end == -1 ) {
				end = queryString.length
			}
			// Return the string
			return unescape ( queryString.substring ( begin, end ) );
		}
		// Return "null" if no parameter has been found
		return null;
	}
}

function set_cat(testo)
{
	document.getElementById("titolo").innerHTML=testo;
}