/* Deezer External Interface */
function onPlay(Title, Album, Artist){

	document.title = Title+' - '+Album+' - '+Artist+' | Deezer | On Play';

}

function gotoHome() {
	refreshAds("home");
	document.getElementById("dzflash").gotoHome();
}

function getNavigator() {
	var navigateur = navigator.appName;
	document.getElementById("dzflash").setNavigator(navigateur);
}

function setData(array) {
	document.getElementById("dzplayer").receptEI(array);
}

function setPlaylist(array){
	document.getElementById("dzplayer").loadXml(array);
}

function updateTrack(sng_id){
	document.getElementById("dzflash").updateRankTrack(sng_id);
}

function setUserID(userid){
	document.getElementById("dzplayer").getUserID(userid);
}

function launchSmartPlaylist(artid){
	document.getElementById("dzflash").launchSmartPlaylist(artid);
}

function nextSongSmartPlaylist(){
	document.getElementById("dzplayer").nextSongSmartPlaylist();
}

function changeSongSmartPlaylist(){
	document.getElementById("dzflash").changeSongSmartPlaylist();
}

function stopPlayer(){
	document.getElementById("dzplayer").stopPlayer();
}

function displayPopupRegister(){
	document.getElementById("dzflash").displayPopupRegister();
}

function setPageArtist(artid){
	document.getElementById("dzflash").displayArtistPage(artid);
}

function setPageAlbum(albid){
	document.getElementById("dzflash").displayAlbumPage(albid);
}

function createIframeAds(id_parent, id, url, style) {
	iframe = document.createElement("IFRAME");
	iframe.setAttribute('id', id);
	iframe.setAttribute('name', id);
	iframe.setAttribute('frameBorder', '0');
	iframe.setAttribute('frameSpacing', '0');
	iframe.setAttribute('border', '0');
	iframe.setAttribute('scrolling', 'no');
	iframe.setAttribute('hspace', '0');
	iframe.setAttribute('vspace', '0');
	iframe.setAttribute('marginheight', '0');
	iframe.setAttribute('marginwidth', '0');
	iframe.setAttribute('src', url);

	if (document.all) iframe.style.setAttribute('cssText', style);
	else iframe.setAttribute('style', style);

	document.getElementById(id_parent).appendChild(iframe);
}

function refreshAds(param) {
	// PATCH EN ATTENTE DE MODIF DU FLASH
	if (param.substr(0, 12) == "music/result"){
		param = "music/result";
	}
	// FIN PATCH EN ATTENTE DE MODIF DU FLASH

	// on supprime les iframes
	element = document.getElementById('ad728');
	element.parentNode.removeChild(element);

	createIframeAds('banner1', 'ad728', '/ads/'+param+'.html', 'width:728px; height:90px; border: 0px;');

	element = document.getElementById('ad300');
	element.parentNode.removeChild(element);

	createIframeAds('banner2', 'ad300', '/ads2/'+param+'.html', 'width:300px; height:500px; border: 0px;');

	/*
	parent.ad728.document.location = '/ads2/'+param+'.html';
	parent.ad300.document.location = '/ads/'+param+'.html'
	*/
}

function getMessagesInvitations() {
	document.getElementById("dzflash").getMessagesInvitations();
}

function callButtonDisconnect() {
	document.getElementById("logout").style.visibility = "visible";
}

function logout() {
	document.getElementById("dzflash").logout();
}

function windowUp() {
	window.scrollTo(0,0);
}

var iframevideo = null;

function videoBlur() {
	document.getElementById('iframevideo').style.display = 'none';
	document.getElementById('iframevideo').style.display = 'block';
}

function openVideo(source, left, top, width, height) {

	absoluteLeft = getAbsoluteLeft('flash');
	absoluteTop = getAbsoluteTop('flash');
	new_left = (absoluteLeft + left);
	new_top = (absoluteTop + top);
	resize_top = top;
	resize_left = left;
	iframevideo = document.createElement("IFRAME");
	iframevideo.setAttribute('id', 'iframevideo');
	iframevideo.setAttribute('name', 'iframevideo');
	iframevideo.setAttribute('frameborder', '0');
	iframevideo.setAttribute('framespacing', '0');
	iframevideo.setAttribute('scroll', 'no');
	iframevideo.setAttribute('scrollbar', 'no');
	iframevideo.setAttribute('src', '/videoplayer.php?s='+source+'&w='+width+'&h='+height);
	iframevideo.setAttribute('width', '320');
	iframevideo.setAttribute('height', '240');

	if (document.all) {
		iframevideo.style.setAttribute('cssText', 'margin:0; padding:0; width:'+width+'px; height:'+height+'px; position: absolute; top:'+new_top+'px; left:'+new_left+'px');
	} else {
		iframevideo.setAttribute('style', 'margin:0; padding:0; width:'+width+'px; height:'+height+'px; position: absolute; top:'+new_top+'px; left:'+new_left+'px');
	}

	if (document.all)
		iframevideo.onblur = function() { videoBlur(); }

	document.body.appendChild(iframevideo);
}

function resizeVideo() {
	if (iframevideo != null) {
		absoluteLeft2 = getAbsoluteLeft('flash');
		absoluteTop2 = getAbsoluteTop('flash');
		new_left2 = (absoluteLeft2 + resize_left);
		new_top2 = (absoluteTop2 + resize_top);
		document.getElementById('iframevideo').style.left = new_left2+'px';
		document.getElementById('iframevideo').style.top = new_top2+'px';
	}
	return true;
}

function closeVideo() {
	document.body.removeChild(document.getElementById('iframevideo'));
	return true;
}

function rewriting(texte, sep_mots, flashReturnName) {
	car_speciaux = new Array( '%C0', '%C1', '%C2', '%C3', '%C4', '%C5', '%C6', '%E0', '%E1', '%E2', '%E3', '%E4', '%E5', '%E6', '%C8', '%C9', '%CA', '%CB', '%E8', '%E9', '%EA', '%EB', '%CC', '%CD', '%CE', '%CF', '%EC', '%ED', '%EE', '%EF', '%D2', '%D3', '%D4', '%D5', '%D6', '%D8', '%F2', '%F3', '%F4', '%F5', '%F6', '%F8', '%D9', '%DA', '%DB', '%DC', '%F9', '%FA', '%FB', '%FC', '%DF', '%C7', '%E7', '%D0', '%F0', '%D1', '%F1', '%FE', '%DE', '%DD', '%FD' );
	car_normaux  = new Array( 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'E', 'E', 'E', 'E', 'e', 'e', 'e', 'e', 'I', 'I', 'I', 'I', 'i', 'i', 'i', 'i', 'O', 'O', 'O', 'O', 'O', 'O', 'o', 'o', 'o', 'o', 'o', 'o', 'U', 'U', 'U', 'U', 'u', 'u', 'u', 'u', 'B', 'C', 'c', 'D', 'd', 'N', 'n', 'P', 'p', 'Y', 'y' );

	texte = escape(texte.toLowerCase());

	for (var i=0; i<car_speciaux.length; i++) {
		texte = texte.replace(car_speciaux[i], car_normaux[i]);
	}
	texte = unescape(texte);
	var resultat = texte.replace(/[^A-Za-z0-9]+/gi, sep_mots);
	document.getElementById(flashReturnName).returnRewritingString(resultat);
}


function sendWeborama(id, rubrique, sousRubrique, content){
	var w_compteur = new wreport_counter(rubrique, sousRubrique, id);
	if(content != ""){
		w_compteur.add_content(content);
	}
	w_compteur.count();
}

function getArtistPlayed(){
	document.getElementById("dzplayer").getArtistPlayed();
}

function sendArtistPlayed(art_id, song_id){
	document.getElementById("dzflash").recupArtistPlayed(art_id, song_id);
}

window.onresize = resizeVideo;