// jQuery(document).ready( function() {

function mpAlert(pseudo, from, subject, mp_id, total_unread)
{ 
      subject = decodeURIComponent(subject); 
      var content; 
      content = "<p>Bonjour " + pseudo + "<br /><br />"; 
      content += "Vous venez de recevoir un message privé de la part de <strong>" + from + "</strong> avec pour sujet : <strong>" + subject + "</strong>. <br /><br />"; 
       content += '<span style="display: block; text-align: right;">'; 
      content += "<input type=\"button\" onClick=\"document.location.replace('doa.php');\" value=\"Lire\"/> "; 
      content += "<input type=\"button\" class=\"close\" value=\"Annuler\"/>"; 
      content += "</span>";
      content += "<br /><br /><em>Vous avez au total "+ total_unread +" message(s) non-lu(s) dans votre boîte de réception. </em>"; 
      content += "</p>";
      var box = new Boxy(content, {title: "Nouveau message privé ! ", modal: true}); 
      box.resize(400,180);
}

function mpAlert(pseudo, from, subject, mp_id, total_unread)
{ 
      subject = decodeURIComponent(subject); 
      var content; 
      content = "<p>Bonjour " + pseudo + "<br /><br />"; 
      content += "Vous venez de recevoir un message privé de la part de <strong>" + from + "</strong> avec pour sujet : <strong>" + subject + "</strong>. <br /><br />"; 
       content += '<span style="display: block; text-align: right;">'; 
      content += "<input type=\"button\" onClick=\"document.location.replace('doa-mp.php');\" value=\"Lire\"/> "; 
      content += "<input type=\"button\" class=\"close\" value=\"Annuler\"/>"; 
      content += "</span>";
      content += "<br /><br /><em>Vous avez au total "+ total_unread +" message(s) non-lu(s) dans votre boîte de réception. </em>"; 
      content += "</p>";
      var box = new Boxy(content, {title: "Nouveau message privé ! ", modal: true}); 
      box.resize(400,180);
}

function mpNotifier() 
{
      jQuery.getJSON(	"doa-osd-mp.php", 
			{}, 
			function (data, textStatus) {
			      if(data == false)
				    return false; 
			
			      jQuery("#messagerie_menu").html("Messagerie (" + data.nb_unread + ")");
			      if(data.id == false)
			      {
				    return false;
			      }
			      else
			      {
				    mpAlert(data.to, data.from, data.sujet, data.id, data.nb_unread);
			      }
			});
}

$(document).ready( function() {
	mpNotifier();
	setInterval(function(){mpNotifier();}, 120000);
	
	jQuery("#homeplayer").click( function () {
	      if(jQuery("#homeplayer2").css("display") == 'none')
		{
		    var set = 'block'; 
			jQuery(".ipod").css("background-image", "../images/ipod_stop.png");
		}
	      else 
		{
		    var set = 'none';
			jQuery(".ipod").css("background-image", "../images/ipod_play.png");
		}
	      jQuery("#homeplayer2").css("display", set); 
	});

	setTimeout(function(){$(".image-forum-ppp").each(function (i) {
		if($(this).width() > 650)
		{
			$(this).width(650);
			if($(this).parent().get(0).tagName !== "A")
				$(this).wrap('<a href="'+$(this).attr("src")+'" target="_blank"></a>');
		}
	})}, 2000);;
	
	function player_popup()
	{
		window.open(	'http://www.ankadio.com/api/player', 
						"_blank", 
						'width=400,height=320'
					);
	}
	
	$(".ecouter_ankadio_popup").click( function () {
		player_popup();
	});
	
	$(".ipod").click(function () {
		player_popup();
	});
});
			
// });
