
$(document).ready(function() {
						   
						   
	// Gestion des rollovers d'images en opacité
	// --------------------------------------------

	$(".img_rollover_opac").mouseover(function() { $(this).fadeTo(200, 0.6); }).mouseout(function(){ $(this).fadeTo(200, 1); });

	
	// Bios: expand header (open/close)
	// ---------------------------------
	
	$("#bio_minimize").click(function() { $(this).css("display","none"); $("#bio_infos").css("display","block"); }); //$("#bio_infos").slideDown("fast"); });


	// Connect zone : expand
	// ---------------------------------
	
	$("#connectexit").click(function () { $("#connectfond").animate({ top: "-200px" }, 400); });
	$("#connectbtn").click(function ()  { $("#connectfond").animate({ top: "0px" }, 400); });

	$("#CF").submit(function() { $.post($(this).attr('action'), 
										{ CF_user:$('#CF_user').val(), 
											CF_password:$('#CF_password').val() }, 
									function(data) { 
					
										if(data.message) { 
											$("#CF_error").html(data.message);
										}  else {
											$("#connectform").html('<img src="'+data.avatar+'" width="75" height="75"> Bonjour '+data.pseudo+', passe un bon moment sur ados.fr !');
											$("#connect").html('Hello <a href="'+data.url+'" target="_blank">'+data.pseudo+'</a> ! | <a href="/?disconnect">Me déconnecter</a>');
											 setTimeout(function() { $("#connectfond").animate({ top: "-200px" }, 400); } ,3000);
										}
										
										
									},"json");
									return false;
									});
	
	// Bios: News : on masque le logo si video
	// ---------------------------------------
	
	function isVideo() {
		
		if($("#news_contenu").find('embed').length > 0) { $("#newslogo").css("display", "none"); }
		
	}
	
	//isVideo();
	
	
	// Bios: defilement des images poster
	// ------------------------------------
		
	function bioposters(img, index) {
	
		if($("#bio_poster #nbImages").html()>0) {
		
			i = img;
	
			$("#bio_poster img:eq("+i+")").css("display","none");
			$("#bio_poster img:eq("+i+")").css("z-index",index);
			$("#bio_poster img:eq("+i+")").fadeIn(500);		
			
			i++;
			
			if(i>2) i = 0;
			
			setTimeout(function() {bioposters(i, index+1)}, 3000);
			
		}
		
	}
	
	setTimeout(function() {bioposters(1, 2)}, 3000);
					
	
	// Bios: contenu graphie
	// ------------------------
	
	$(".graphie a").mouseover(function() {
		$(this).find('.texte').slideDown("fast");
    }).mouseleave(function(){  
   		$(this).find('.texte').slideUp("fast");
    });
	
		
	// Bios: player musique
	// ---------------------
	
	$(".titreecoute").click(function() {
		
		if($(this).find('.object').html()=='') {
			
			if ($(this).is('.songplay')) $(this).addClass("song_play_on"); 
			else $(this).addClass("titreecoute_on"); 
			$(this).find('.titre').css("color","#fdfdfd");
			$(this).find('.equalizer').css("display","block");
			loadplayer($(this), $(this).find('.index').text());
			currentplayer = $(this);
			
		} else {
			
			if ($(this).is('.songplay')) $(this).removeClass("song_play_on"); 
			else $(this).removeClass("titreecoute_on"); 
			$(this).find('.titre').css("color","#070707");
			$(this).find('.equalizer').css("display","none");
			$(this).find('.object').html('');
			
		}
		
	});
	
	$(".play_ecoute").click(function() { 
		
		if($(this).parent().find('.object').html()=='') {
			
			$(this).addClass("play_on"); 
			
			$(this).parent().addClass("titreecoute_on"); 
			//$(this).parent().find('.titre').css("color","#fdfdfd");
			$(this).parent().find('.equalizer').css("display","block");
			loadplayer($(this).parent(), $(this).attr('nb'));
			currentplayer = $(this).parent();
			
		} else {
			
			$(this).removeClass("play_on"); 
			
			$(this).parent().removeClass("titreecoute_on"); 
			//$(this).parent().find('.titre').css("color","#070707");
			$(this).parent().find('.equalizer').css("display","none");
			$(this).parent().find('.object').html('');
			
		}					 
									 
	} );
	
	
	$(".play_ecoute").mouseover(function() {
		if($(this).parent().find('.object').html()=='') { $(this).parent().find('.titreextrait').html("&Eacute;couter l'extrait !"); } 
		else {$(this).parent().find('.titreextrait').html("Arr&ecirc;ter.."); }; 
		$(this).parent().find('.titresong').css('display', 'none');
		$(this).parent().find('.titreextrait').css('display', 'block'); 
	}).mouseout(function(){ 
		$(this).parent().find('.titreextrait').css('display', 'none');
		$(this).parent().find('.titresong').css('display', 'block'); 
	});
												
	var currentsong = 0;
	var currentplayer;

	function loadplayer(obj, song) {
	
		if((currentsong!=song)&&(currentsong!=0)) {

			currentplayer.removeClass("titreecoute_on"); 
			//currentplayer.find('.titre').css("color","#070707");
			currentplayer.find('.equalizer').css("display","none");
			currentplayer.find('.play').removeClass("play_on"); 
			currentplayer.find('.object').html('');
			
		}
	
		var contenu = '';
		
		contenu += '<object type="application/x-mplayer2" height="0" width="0" id="player" name="player" data="http://www.virginmega.fr/Musique/StreamPreviewUrl/Track/' + song + '.wmx" style="padding:2px;">';
		contenu += '<param name="FileName" value="http://www.virginmega.fr/Musique/StreamPreviewUrl/Track/' + song + '.wmx" />';
		contenu += '<param name="AnimationatStart" value="0">';
		contenu += '<param name="TransparentatStart" value="0">';
		contenu += '<param name="AutoStart" value="1">';
		contenu += '<param name="ShowControls" value="1">';
		contenu += '<param name="ShowAudioControls" value="1">';
		contenu += '<param name="EnableFullScreenControls" value="0">';
		contenu += '<param name="ShowDisplay" value="0">';
		contenu += '<param name="ShowGotoBar" value="0">';
		contenu += '<param name="ShowPositionControls" value="0">';
		contenu += '<param name="ShowStatusBar" value="1">';
		contenu += '<param name="ShowTracker" value="0">';
		contenu += '<param name="AllowChangeDisplaySize" value="0">';
		contenu += ' <param name="AutoSize" value="0">';
		contenu += '<param name="DisplaySize" value="0">';
		contenu += '<param name="uiMode" value="mini" />'
		contenu += '</object>';
	
		obj.find('.object').html(contenu);
		obj.find('.object').css("display","block");
	
		currentsong = song;
	
	}

	
	// Expand des Bios trop longues
	// --------------------------------
	var isBioexpanded = false;	
	$("#biomore").click(function() { expandbio(); });
	$("#biomore2").click(function() { expandbio(); });
	
	function expandbio() {
		
		if(isBioexpanded) {
			
			$("#bio").animate({ height: "190px" }, 400); 
			$("#biomore").removeClass("picto_expandbis"); 
		
		} else {
			
			$("#bio").animate({ height: $("#bioinside").height() + "px" }, 400); 
			$("#biomore").addClass("picto_expandbis"); 
			
		}
		
		isBioexpanded = !isBioexpanded;
		$("#biomore2").toggle();
		
	}
	
	
	// Gestion des onglets Menu
	// --------------------------------
	
	$("#menu .onglet").mouseover(function()    { $(this).animate({ backgroundColor: '#dedede' }, 100); $(this).css("color","#070707"); }); 
	$("#menu .onglet").mouseout(function()     { $(this).animate({ backgroundColor: '#383738' }, 200); $(this).css("color","#fdfdfd"); });
	$("#menu .bis").mouseover(function() { $(this).animate({ backgroundColor: '#dedede' }, 100); $(this).css("color","#070707"); });
	$("#menu .bis").mouseout(function()  { $(this).animate({ backgroundColor: '#787778' }, 200); $(this).css("color","#fdfdfd"); });
	
	
	// Gestion des onglets de News
	// --------------------------------

	$(".news_liens_www a").mouseover(function() { $(this).shownews(); }).mouseout(function(){ clearTimeout(timernews); });
	$(".news_liens_www").mouseenter(function() {  }).mouseleave(function(){ clearTimeout(timernews); });
	
	
	var current_id = "www";
	var timernews;
	
	$.fn.shownews = function() { 
		clearTimeout(timernews);		
		obj = $(this);
		timernews =  setTimeout(function() {obj.shownewstimer()}, 20);		
		//obj.shownewstimer();
	}
	
	$.fn.shownewstimer = function() {
		
		id = $(this).attr('subdomain');
		
		if(id!=current_id) {
			
			$(".news_liens a[subdomain='"+current_id+"'] .fleche").css("display","none");

			var obj = ".news_liens a[subdomain='"+current_id+"']";
			/*if(current_id!="www") $(obj).animate({ backgroundColor: '#fdfdfd' }, 200);
			else $(obj).animate({ backgroundColor: '#e5e5e5' }, 200);
			$(obj).css("color","#070707");*/
			$(obj).removeClass("on");
			
			
			//colorRef = "#65D1EB";
			//$(this).animate({ backgroundColor: colorRef }, 100);
			//$(obj).css("background-color","#7cd1f6");
			//$(this).css("color","#fdfdfd");
			$(this).addClass("on");
			
			$(this).children('.fleche').css("display","block");
			
			$("#news_"+current_id).css("display","none");
			$("#news_"+id).fadeIn(200);
			
			current_id = id;
			
			clearTimeout(timernews);
		
		}
		
	}
		
	
	$(".news_liens #numero1").mouseover(function() { shownewsnumero(1); }).mouseleave(function(){  });
	$(".news_liens #numero2").mouseover(function() { shownewsnumero(2); }).mouseleave(function(){  });
	$(".news_liens #numero3").mouseover(function() { shownewsnumero(3); }).mouseleave(function(){  });
	
	var newsnumero_id = 1;
	
	function shownewsnumero(id) {

		if(id!=newsnumero_id) {
			
			var obj = "#numero" + newsnumero_id;
			$(obj).removeClass("numero_on"); 
			
			var obj = "#numero" + id;
			$(obj).addClass("numero_on");
			
			$("#news_"+newsnumero_id).css("display","none");
			$("#news_"+id).fadeIn(500);
			
			newsnumero_id = id;
			
		}
	
	}
	
	
	// Gestion des textes sur les vignettes Videos
	// -----------------------------------------------
/*
	var timervideo;
	
	function showvideo(id) {

		clearTimeout(timervideo);		
			
		timervideo =  setTimeout(function() {showvideotimer(id)}, 150);
		
	}
		
	function showvideotimer(id, bool) {
		
		clearTimeout(timervideo);
		
		var obj = "#video" + id;
		$(obj).css("display","block");

		if(id==0) v0.write("video0");
		if(id==1) v1.write("video1");
		if(id==2) {
			var v2 = new SWFObject("http://dev.ados.fr/medias/ados/player_mini.swf", "itw_vid2", "210", "210", "9", "#070707");
			v2.write("video2");
		}
		
		//startVideo("itw_vid"+id);
	
	}
	
	$(".video_teaser").mouseover(function() { var n = $(this).attr('nb'); showvideotimer(n); })
					  .mouseleave(function(){ clearTimeout(timervideo); var n = $(this).attr('nb'); hidevideo(nb); });
	
	
	/*$(".video_teaser_in").mouseover(function() { })
						 .mouseout(function(){ var n = $(this).attr('nb'); hidevideo(n); });
	
	function getFlashMovie(movieName) {
	  var isIE = navigator.appName.indexOf("Microsoft") != -1;
	  return (isIE) ? window[movieName] : document[movieName];
	}
	
	function startVideo(name) {
		 getFlashMovie(name).startVideoAS(name);
	}
	
	function hidevideo(nb) {  alert('rrrr');
	  	//$("#video" + nb).css("display","none");
		$("#video" + nb).html('');
	}
	
	*/
		
	// Gestion des onglets Tops
	// --------------------------------
	
	$(".menutops .td_menu_top").mouseover(function() { showtoptimer($(this).attr("nb")); }).mouseout(function(){ clearTimeout(timertop); });

	var currenttop_id = 0;
	var timertop;
	
	showtop(1);
		
	function showtop(id) {
		
		clearTimeout(timertop);
		
		timertop =  setTimeout(function() {showtoptimer(id)}, 100);
		
	}
	
	function showtoptimer(id) {
		
		clearTimeout(timertop);

		if(id!=currenttop_id) {
			
			var obj = "#td_menu_top_" + currenttop_id + " .fleche";
			$(obj).css("display","none");
			
			var obj = "#td_menu_top_" + currenttop_id;
			$(obj).removeClass("td_menu_top_on");

			var obj = "#td_menu_top_" + id + " .fleche";
			//$(obj).css("display","block");
			
			var obj = "#td_menu_top_" + id;
			$(obj).addClass("td_menu_top_on"); 
			
			$("#top_"+currenttop_id).css("display","none");
			//$("#top_"+id).fadeIn(500);
			$("#top_"+id).css("display","block");
			
			currenttop_id = id;
			
		}
	
	}
	
	
	// Gestion des onglets Concours
	// --------------------------------
	
	$(".concourslien").mouseover(function() { showconcours($(this).attr("nb")); }).mouseleave(function(){ });

	var currentconcours_id = 1;
	
	function showconcours(id) {
		
		if(id!=currentconcours_id) {
		
			var obj = "#concours_" + currentconcours_id;
			$(obj).css("display","none");
			
			var obj = "#concourslien" + currentconcours_id;
			$(obj).removeClass("autres_on"); 
			
			var obj = "#concours_" + id;
			$(obj).fadeIn(500);
			
			var obj = "#concourslien" + id;
			$(obj).addClass("autres_on"); 
				
			currentconcours_id = id;
		
		}
		
	}
	   
	// Footer : tooltip sur les artistes
	// ---------------------------------------	   
	/*$('.aimez a').tooltip({
		track: true,
		delay: 0,
		showURL: false,
		showBody: " - ",
		fade: 250
	});
	*/
	
	// Fonctions Like
	// ---------------------------------------
	
	$("a[id_node_love]").click(function() {
		url = subdomain_url+"add_like/";
		id_node_love = $(this).attr("id_node_love");
		$.get(url, { id_node:id_node_love }, 
				function(data) {
					if(data.status=="ok") {
						$("a[id_node_love="+id_node_love+"]").html(data.nb_like);
						$("a[id_node_love="+id_node_love+"]").addClass('like_on');
					} else {
						$("a[id_node_love="+id_node_love+"]").addClass('like_on');
						//alert('Mettre un tip sur le love pour dire qu\'on a dÃ©jÃ  votÃ©');
					}
				}
				
		,"json");
	});


});










