jQuery.extend(jQuery.browser, {
    flash: (function () {
        var found = false;
		try {
			new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			found = true;
		} catch(e) {
			jQuery.each(navigator.plugins, function () {
				if (this.name.match(/flash/gim)) {
					found = true;
					return false;
				}
			});	
		}
		return found;
    })(),
	
	sl: (function () {
		var found = false;
		try {
			new ActiveXObject("AgControl.AgControl");
			found = true;
		} catch (e) {
			jQuery.each(navigator.plugins, function () {
	            if (this.name.match(/silverlight/gim)) {
	                found = true;
	                return false;
	            }
			});
		}
		return found;
	})(),

    pdf: (function () {
        var found = false;
		try {
			(new ActiveXObject("AcroPDF.PDF") || new ActiveXObject("PDF.PdfCtrl"));
			found = true;
		} catch(e) {
			jQuery.each(navigator.mimeTypes, function () {
	            if (this.suffixes.match(/pdf/gim)) {
	                found = true;
	                return false;
	            }
			});
		}
        return found;
    })(),

    java: (function () {
        return navigator.javaEnabled();
    })(),

    qtime: (function () {
        var found = false;
		try {
			new ActiveXObject("QuickTime.QuickTime");
			found = true;
		} catch(e) {
			jQuery.each(navigator.plugins, function () {
	            if (this.name.match(/quicktime/gim)) {
	                found = true;
	                return false;
	            }
			});
		}
        return found;
    })(),

    wmp: (function () {
        var found = false;
		try {
			new ActiveXObject("WMPlayer.OCX");
			found = true;
		} catch(e) {
			jQuery.each(navigator.plugins, function () {
	            if (this.name.match(/(windows\smedia)|(Microsoft)/gim)) {
	                found = true;
	                return false;
	            }
	        });
		}
        return found;
    })(),
	
	shk: (function () {
		var found = false;
		try {
			new ActiveXObject("SWCtl.SWCtl");
			found = true;
		} catch(e) {
			jQuery.each(navigator.plugins, function () {
	            if (this.name.match(/shockwave/gim) && !this.name.match(/flash/gim)) {
	                found = true;
	                return false;
	            }
	        });
		}
		return found;
	})(),

    rp: (function () {
    	var found = false;
		try {
			new ActiveXObject("RealPlayer");
			found = true;
		} catch(e) {
			jQuery.each(navigator.plugins, function () {
				if (this.name.match(/realplayer/gim)) {
					found = true;
					return false;
				}
			});
		}
        return found;
    })()
});

function playRadio() {
	plugin = detectRadioPlugin();
	$j.get("/radio/play/",{embed: plugin, noLayout: "true"}, function(d){
		$j("#playerRadio").html(d);
	});
}

function stopRadio() {
	plugin = detectRadioPlugin();
	$j("#playerRadio").html("");
}

function detectRadioPlugin() {
	
	if (jQuery.browser.wmp) {
		
		return "wp";
		
	}
	
	if (jQuery.browser.rp) {
		
		return "rm";
	} 
	
	if (jQuery.browser.qtime) {
	
		return "qt";
	} else {
		var info = "Pour pouvoir écouter la Web Radio, vous devez installer Real Player, Windows Media Player ou QuickTime";
		afficheNotification(info);
		return false;
	}
	
}

function refreshRadio() {
	 $j.post('/radio/refresh/', {noLayout: "true"}, function (data) {
			$j('#refreshRadio').html(data);
	});
}
function setRadioTitle(title) {
	$j('#radioTitle').html(title);
}

function setRadioCover(cover) {
	$j('#radioCover').html(cover);
}

function changeRadioButton(songId, songMin, songName) {
	$j("#dediLink").unbind("click");
	$j("#flopLink").unbind("click");
	$j("#topLink").unbind("click");
	$j("#dediLink").attr("onclick", "");
	$j("#flopLink").attr("onclick", "");
	$j("#topLink").attr("onclick", "");
	
	if (songId) {
		$j("#flopLink").show();
		$j("#topLink").show();
		if (songMin > 9) {
			$j("#dediLink").attr("title", "");
			$j("#dediLink").hide();
		} else {
			$j("#dediLink").bind("click",function(){addDedicace(songId);});
			$j("#dediLink").show();
			$j("#dediLink").attr("title", "D\351dicacez " + songName);
		}
		$j("#topLink").bind("click",function(){voteSong('top', songId);});
		$j("#topLink").attr("title", "Vous aimez " + songName);
		$j("#flopLink").bind("click",function(){voteSong('flop', songId);});
		$j("#flopLink").attr("title", "Vous n'aimez pas " + songName);
	} else {
		$j("#dediLink").attr("title", "");
		$j("#flopLink").attr("title", "");
		$j("#topLink").attr("title", "");
		$j("#dediLink").hide();
		$j("#flopLink").hide();
		$j("#topLink").hide();
	}
}

function voteSong(type, id) {
	$j.post('/radio/vote/'+type+'/'+id, {type: type, id: id, noLayout: "true"}, function (data) {
		if(data == "true") {
			afficheNotification('Merci. Votre vote a bien été pris en compte');
		} else {
			if(data == "false") {
				getLogged();
			} else {
				afficheNotification("Vous avez déja voté");
			}
		}
});
}

function addDedicace (id) {
	$j('html, body').animate({scrollTop:0}, 'slow');
	WaitingContact();
	$j.get('/radio/adddedicace', {idsong: id, noLayout: "true"}, function(data) {
		recalculatePosition('#dialog2', 510, 294);
		$j("#dialog2").html(data);
			
	});
	return false;
}
