function fixExternalLinks() {
	$$('#courant a').each(function(e) {
		if((e.rel != 'radio') && (!e.href.startsWith('mailto:')) && (!e.href.startsWith('#'))) {
			e.target = '_blank';
		}
	});
}

function getItemData(idx) {
	new Ajax.Request(radio[idx], {
    method: 'get',

    onSuccess: function(transport) {
      var response = transport.responseText || "no response text";
      $('courant-ajax').update(response + '<div class="clear"></div>');
     	fixExternalLinks();
    },

    onFailure: function() {
    	$('courant-ajax').update('?I/O Error: ' + radio[idx]);
	  }
  });
}

var afficheRadio = function(displayHeight, displayWidth, playerFile, xspfFile) {
	var playerHeight = displayHeight + 20;
	
	var so = new SWFObject(playerFile,'mpl',displayWidth,playerHeight,'7');
	so.addParam('allowfullscreen','true');
	so.addParam('allowscriptaccess','true');
	so.addParam('wmode', 'transparent');
	so.addVariable('displayheight',displayHeight);
	so.addVariable('file',xspfFile);
	so.addVariable('height',playerHeight);
	so.addVariable('width',displayWidth);
	so.addVariable('displaywidth','0');
	so.addVariable('autostart','false');
	so.addVariable('shuffle','false');
	so.addVariable('repeat','list');
	so.addVariable('enablejs','true');
	so.addVariable('javascriptid','mpl');
	so.addVariable('usefullscreen','false');
	so.addVariable('linkfromdisplay','false');
	so.addVariable('thumbsinplaylist','true');
	so.addVariable('backcolor','0xE7E7DE');
	so.addVariable('frontcolor','0x333333');
	so.addVariable('lightcolor','0x40825E');
	so.addVariable('callback','analytics');
	so.write('player');
}

function playTracker(obj) {
	if(obj.state) {
		if($('courant').getStyle('display') == 'none') {
			Effect.BlindDown($('courant'), { duration: 0.2, queue: 'end' });
		}

	} else {
		if(($('courant').getStyle('display') != 'none') && ($('doc-radio-poste') == undefined)) {
			Effect.BlindUp($('courant'), { duration: 0.2, queue: 'end' });
		}
	}
}

function stateTracker(obj) {
	if(obj.newstate == 'PLAYING') {
		if($('courant').getStyle('display') == 'none') {
			Effect.BlindDown($('courant'), { duration: 0.2, queue: 'end' });
		}
	}
}

function stopTracker(obj) {
	if(($('courant').getStyle('display') != 'none') && ($('doc-radio-poste') == undefined)) {
		Effect.BlindUp($('courant'), { duration: 0.2, queue: 'end' });
	}
}

function itemTracker(obj) {
	currentItem = obj.index;
	setTimeout("getItemData(currentItem)", 100);
	
	if($('courant').getStyle('display') == 'none') {
		Effect.BlindDown($('courant'), { duration: 0.2, queue: 'end' });
	}
}

function playerReady(obj) {
	if($('doc-radio-poste')) {
		$('courant').show();
		//Effect.BlindUp($('courant'), { duration: 0.2, queue: 'end' });
	}

	player = $(obj['id']);
	player.addControllerListener("PLAY", "playTracker");
	player.addControllerListener("STATE", "stateTracker");
	player.addControllerListener("STOP", "stopTracker");
	player.addControllerListener("ITEM", "itemTracker");
	
	if($('doc-radio-poste')) {
		setTimeout("player.sendEvent('PLAY', 'true')", 100);
	}
};

function initRadio() {
}

function thisMovie(movieName) {
	if(navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
}
