/**
 * Inserisce il player flash per la visualizzazione dei contenuti multimediali
 * @param	string	id			id del file da visualizzare
 * @param	integer	width		width del video da visualizzare 
 * @param	integer	height		height del video da visualizzare
 */

function jsInsertMediaReader(id,width,height)
{
	/*
	// usando swfobject 1.5
	var html = new SWFObject(path_flash + 'mediaplayer.swf','player',width,height,'7');
	html.addParam('allowfullscreen','true');
	html.addVariable('file','/get_playlist.php%3Fmedia%3D'+id);
	html.addVariable('height',height);
	html.addVariable('width',width);
	html.addVariable('shuffle',false);
	html.write('box_principale');
	*/

	// usando swfobject 2.2
	var flashvars = {
		file:'/get_playlist.php%3Fmedia%3D'+id
		, shuffle:false
		, autostart:'true'
		, skin:'file_generali/flash/jwpskin/glow.zip'
		, plugins:'fbit-1,sharing-2,file_generali/flash/ShinyStat.swf,'+path_flash+'ova.swf'
		//, plugins:'fbit-1,/file_generali/flash/ova.swf'

		// "ova" "ova-trial"...
		//, config:path_flash+'ovatrial/jw-trial-config.xml'
		, config:path_flash+'ova/jw-config-2011-06-28.xml'
		// "fbit-1"
		, dock:'true'
		// "sharing-2"
		, 'sharing.link':window.location
		, 'sharing.code':encodeURIComponent('<iframe src="http://multimedia.quotidiano.net/iframe.shtml?tipo=media&media='+id+'" width="'
				+width+'" height="'+height+'" scrolling="no"></iframe>')
		, 'shinystat.account': userShiny
		, 'shinystat.pathswf': 'http://multimedia.quotidiano.net/file_generali/flash/mediaplayer.swf'
		, 'shinystat.idobject': 'player'
		, 'shinystat.idcateg': trackVideo
		, 'shinystat.titvideo': titoloVideo
	};
	var params = {
		allowfullscreen:'true'
		, allowscriptaccess:'always'
	};
	var attributes = {
		id:'player'
		, name:'player'
	};
	swfobject.embedSWF(path_flash+'mediaplayer.swf', 'box_principale', width, height, '7', 'false', flashvars, params, attributes);
}

function jsInsertMediaReaderByFile(mmfile,width,height)
{
	// usando swfobject 2.2
	var flashvars = {
		file:mmfile
		, shuffle:false
		, autostart:'true'
		, skin:'file_generali/flash/jwpskin/glow.zip'
		, plugins:'fbit-1,sharing-2,file_generali/flash/ShinyStat.swf,'+path_flash+'ova.swf'
		//, plugins:'fbit-1,/file_generali/flash/ova.swf'

		// "ova" "ova-trial"...
		//, config:path_flash+'ovatrial/jw-trial-config.xml'
		, config:path_flash+'ova/jw-config-2011-06-28.xml'		
		// "fbit-1"
		, dock:'true'
		// "sharing-2"
		, 'sharing.link':window.location
		, 'sharing.code':encodeURIComponent('<iframe src="http://multimedia.quotidiano.net/iframe.shtml?tipo=media&media='+id+'" width="'
				+width+'" height="'+height+'" scrolling="no"></iframe>')
		, 'shinystat.account': userShiny
		, 'shinystat.pathswf': 'http://multimedia.quotidiano.net/file_generali/flash/mediaplayer.swf'
		, 'shinystat.idobject': 'player'
		, 'shinystat.idcateg': trackVideo
		, 'shinystat.titvideo': titoloVideo
	};
	var params = {
		allowfullscreen:'true'
		, allowscriptaccess:'always'
	};
	var attributes = {
		id:'player'
		, name:'player'
	};
	swfobject.embedSWF(path_flash+'mediaplayer.swf', 'box_principale', width, height, '7', 'false', flashvars, params, attributes);
}

/**
 * Inserisce un oggetto flash da riprodurre.
 * @param	string	filename	nome del file da riprodurre
 * @param	integer	width		width del video da riprodurre 
 * @param	integer	height		height del video da riprodurre
 */
function jsInsertFlashObject(filename,width,height)
{
	var html = new SWFObject(filename,'flash_object',width,height,'7');
	html.addVariable('height',height);
	html.addVariable('width',width);
	html.write('box_principale');
}

/**
 * Modifica l'innerHTML dell'embed per evitare le noiose protezioni della microsoft.
 */
function jsReloadEmbed()
{
	if (document.getElementById('box_principale'))
		document.getElementById('box_principale').innerHTML += '';
}

/**
 * Funzione generica che viene richiamata alla fine dell'aggiornamento di un box dinamico
 * Questa funzione puņ essere personalizzata a piacere dall'utente
 * @param	string	sUniqueName		nome unico della sezione	
 * @param	string	sBoxHrefId		id del box contenente i link da aggiornare
 * @param	string	section			valore della sezione 
 */
function jsAjaxBoxEnded(sUniqueName, sBoxHrefId, section) {
	if (sUniqueName=='canale') {
		updateStyle('canale', 'box_canali_link');
	}
}

/**
 * Aggiorna lo stile dei link di un box in seguito a una chiamata ajax. Si appoggia alla funzione
 * getCurrentState definita dalla classe clsAjaxBox
 * @param string section	nome unico della sezione	
 * @param string box_link	id del box contenente i link da aggiornare
 */
function updateStyle(section,box_link)
{
	var anchors = document.getElementById(box_link).getElementsByTagName('a');

	for (var i=0, len=anchors.length ; i<len ; i++) {
		var anchor  = anchors[i];
		   var aMatch  = anchor.href.match(/^.*?\?(.*)/); // tolgo tutto quello che sta prima del ?
		   var aParams = aMatch[1].split('&');

		   for (var j=0, size=aParams.length ; j<size ; j++) {
			   var aTmp = aParams[j].split('=');
			   if (aTmp[0] == section) {
				   anchor.className =  aTmp[1] == getCurrentState(section) ? 'link_selected' : 'link';
			   }
		   }
	}
}

