/**
 * 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)
{
	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');
}

/**
 * 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()
{
	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';
			   }
		   }
	}
}
