


$(document).ready(function()
{
  //gestion des slides de commentaire
  $(".commentaire .btn").click(function()
  {
    $(this).parent().parent().parent().parent().nextAll("div").slideToggle(600);
	$(this).parent().parent().parent().parent().nextAll("div").next("form").slideToggle(600);
  });
  
  $(".node-type-dossier .commentaire .btn").parent().parent().parent().parent().nextAll("div").hide();
  $(".node-type-dossier .commentaire .btn").parent().parent().parent().parent().nextAll("div").next("form").hide();
  
  
  $(".view-v-antenne-emission-contenu-assoc .commentaire .btn").parent().parent().parent().parent().nextAll("div").hide();
  $(".view-v-antenne-emission-contenu-assoc .commentaire .btn").parent().parent().parent().parent().nextAll("div").next("form").hide();
  
  
});


jQuery.fn.liScroll = function(settings) {
    settings = jQuery.extend({
    travelocity: 0.07
    }, settings);   
    return this.each(function(){
        var $strip = jQuery(this);
        //$strip.addClass("newsticker")
        var stripWidth = 0;
        //var $mask = $strip.wrap("<div class='mask'></div>");
        //var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");               
        var containerWidth = $strip.parent().parent().width();  //a.k.a. 'mask' width   
        //$strip.find("li").each(function(i){
        //stripWidth += jQuery(this, i).width();
        //});
        stripWidth = $strip.width();
        $strip.width(stripWidth);     
        var defTiming = stripWidth/settings.travelocity;
        var totalTravel = stripWidth+containerWidth;                
        function scrollnews(spazio, tempo){
        $strip.animate({left: '-='+ spazio}, tempo, "linear", function(){$strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);});
        }
        scrollnews(totalTravel, defTiming);       
        $strip.hover(function(){
        jQuery(this).stop();
        },
        function(){
        var offset = jQuery(this).offset();
        var residualSpace = offset.left + stripWidth;
        var residualTime = residualSpace/settings.travelocity;
        scrollnews(residualSpace, residualTime);
        });     
    }); 
};

// défilement chanson en cour
//var initLive = true;
var position=0;
var positionBlank=25;
var liveSize=0;
var msg="";
var oldguid = "";
var liveContent = "";
var animateLiveInit = true;
	var ancredebut = '<a href="/ckoicetitre">';
	var ancrefin   = '</a>';
function getLive()
{
	$.get("/files/rfPlayer/mouvRSS.xml?"+escape(new Date()), function(xmlDoc){
		var liveSongArtist = xmlDoc.getElementsByTagName('artist_name');
		var liveSongTitle = xmlDoc.getElementsByTagName('song_title');
		var liveSongSoundid = xmlDoc.getElementsByTagName('soundid');
		var liveSongGuid = xmlDoc.getElementsByTagName('guid');
		var liveItem = xmlDoc.getElementsByTagName('item');//modif
		var liveTitle = liveItem[0].getElementsByTagName('title');//modif
		liveSongArtist = liveSongArtist[0].firstChild.nodeValue;
		liveSongTitle = liveSongTitle[0].firstChild.nodeValue;
		liveSongSoundid = liveSongSoundid[0].firstChild.nodeValue;
		liveSongGuid = liveSongGuid[0].firstChild.nodeValue;
		liveTitle = liveTitle[0].firstChild.nodeValue;//modif

    if (liveSongGuid != oldguid)
    {
	    oldguid = liveSongGuid;
//	    liveContent = liveSongArtist+" // "+liveSongTitle;
	    //liveContent = liveTitle;//modif
		//modif
		switch(liveSongSoundid)
		{
		case "9":
			liveContent = liveSongArtist+" - "+liveTitle;
		break;
		case "12":
			liveContent = liveTitle;
		break;
		case "8":
			liveContent = liveTitle+" - "+liveSongTitle;
		break;
		default:
			liveContent = liveTitle;
		}
		
	    liveSize = liveContent.length;
	    position=0;
	    positionBlank=25;

	    if (animateLiveInit)
      {
        animateLiveInit = false;
        banniere();
      }
    }
    setTimeout ("getLive()", 60000);
	}, 'xml');
}
function strpos( haystack, needle, offset){
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Onno Marsman    
    // *     example 1: strpos('Kevin van Zonneveld', 'e', 5);
    // *     returns 1: 14
    var i = (haystack+'').indexOf( needle, offset ); 
    return i===-1 ? false : i;
}
function banniere(){
	
	if (positionBlank != 0)
	{
	  var blank = '';
	  for (i = 0; i < positionBlank; i++)
	   blank += '&nbsp;&nbsp;';
//	  $("#logo H3").html(ancredebut+blank+'<strong>'+(liveContent.replace(/ /g, '&nbsp;').replace(/\/\//g, '</strong><span class="separateur">//</span>'+ancrefin)));
	  $("#logo H3 #texte-defilant").html(ancredebut + blank + liveContent + ancrefin);//modif
	  positionBlank--;
	} else
	{
		var content = liveContent.substring(position,position+35);
//  	$("#logo H3").html(ancredebut+(strpos(content, '/', 1)?'<strong>':'')+content.replace(/ /g, '&nbsp;').replace(/\/\//g, '</strong><span class="separateur">//</span>')+ancrefin);
		$("#logo H3 #texte-defilant").html(ancredebut + content + ancrefin);//modif
	  position=position+1;
	}         
	if (position==liveSize)
	{        
	 position=0;
	 positionBlank=25;
	}        
  setTimeout("banniere()",300);
}

$(document).ready(function(){
  getLive();
});



/**
 *		Affichage des menus medias (a chaque page ou y'a ces icones)
 *			=>	rollover sur les icones video, audio, mouv'box
 *
 *	@ author	paul
 *
 *	Modif de chr
 *	les liens de class .addtomycollection-links et share-link ont leurs propre comportement
 *	et ce comportement interfère avec le leur.
 *
 **/
var timeoutTool = false;
$(function()
{
	$('.tool').hover(function()
	{
		if(!$(this).is('.addtomycollection-links') && !$(this).is('.share-link'))
		{
//       if ($(this).parents().is('#v_buzz_timeline_mots'))
//       {
       timeoutTool=false;
       var offset = $(this).offset();
       $('.fakeTool').remove();
			 $(this).children("ul").clone().prependTo('body').css("z-index","999").css("position","absolute").css('top', offset.top+28).css('left', offset.left).addClass('fakeTool').show().hover(function() {timeoutTool = false;},function() {$(this).remove();});
       // ancienne méthode
//       	$(this).children("ul").css("display","block").css("z-index","999");
//        $(this).parent().css("position","relative").css("z-index","999");
//       }
		}
		
	},
	function()
	{
		if(!$(this).is('.addtomycollection-links') && !$(this).is('.share-link'))
		{
//			if ($(this).parents().is('#v_buzz_timeline_mots'))
//			{
				timeoutTool = true;
				setTimeout("if (timeoutTool) $('.fakeTool').remove();timeoutTool=false;", 250);
				// ancienne méthode
//				$(this).children("ul").css("display","none").css("z-index","0");
//        $(this).parent().css("position","static").css("z-index","0");

		}
	});

})

/*  rnc - Liens podcast */

var timeoutPodcast = false;
$(function()
{
	$('#liens-podcast').hover(function()
	{
      //  console.info("In");
		//if(!$(this).is('.addtomycollection-links') && !$(this).is('.share-link'))
	//	{
//       if ($(this).parents().is('#v_buzz_timeline_mots'))
//       {
       timeoutPodcast=false;
       var offset = $(this).offset();
       $('.fakeTool').remove();
	   $(this).children("ul").clone().prependTo('body').css("z-index","999").css("position","absolute").css('top', offset.top+28).css('left', offset.left).addClass('fakeTool').show().hover(function() {timeoutPodcast = false;},function() {$(this).remove();});
       // ancienne méthode
//       	$(this).children("ul").css("display","block").css("z-index","999");
//        $(this).parent().css("position","relative").css("z-index","999");
//       }
	//	}

	},
	function()
	{
     //   console.info("Out");
		//if(!$(this).is('.addtomycollection-links') && !$(this).is('.share-link'))
	//	{
//			if ($(this).parents().is('#v_buzz_timeline_mots'))
//			{
			//	timeoutPodcast = true;
			//	setTimeout("if (timeoutTool) $('.fakeTool').remove();timeoutTool=false;", 250);
				// ancienne méthode
//				$(this).children("ul").css("display","none").css("z-index","0");
//        $(this).parent().css("position","static").css("z-index","0");

		//}
	});

})

	
	$('.page-blog_home .side-box-bg .side-menu li').click(function () {
		if(this.className.indexOf('active') != -1) {
			$(this).removeClass('active');
			return true;
		}else{
			$('.page-blog_home .side-box-bg .side-menu').each(function (){
				if($(this).children("li").hasClass('active')){
				$(this).children("li").removeClass('active');
				}
			});
			
			$(this).addClass('active');
			return true;
		}
	});




/*
		clic sur recherche faut virer le texte
*/
$("#search-theme-form input[@type='text']").click(function() { $(this).val("").unbind("click"); });
$("#search-theme-form input[@type='text']").focus(function() { $(this).val("").unbind("focus"); });


/**
 *		f_user_login
 *
 *	@ author	paul
 *
 **/
$("#edit-name").click(function() { $("#edit-name").val("").unbind("click"); });
$("#edit-name").focus(function() { $("#edit-name").val("").unbind("focus"); });
$("#edit-pass").click(function() { $("#edit-pass").val("").unbind("click"); });
$("#edit-pass").focus(function() { $("#edit-pass").val("").unbind("focus"); });
$("#midentifier").click(function()
{
	if ( $("#login-box").css("display") == "none" )
	{
		//$("#login-box").css("display","block").css("margin-bottom","5px");
		$("#login-box").css("display","block");
		//$("#login-box").slideDown("fast");
		//$("#inde30").css("margin-top","5px");
		$("#cd_video_dm").css("margin-top","35px");
	}
	else 
	{
		//$("#login-box").css("display","none").css("margin-bottom","60px");
		$("#login-box").css("display","none");
		//$("#login-box").slideUp("fast");
		//$("#inde30").css("margin-top","95px");
		$("#cd_video_dm").css("margin-top","95px");
	}
});



/**
 *		popup_vote - quand on clique sur 'voter' on ajax sur la fonction du module inde30
 *
 *	@ author	paul
 *
 **/
function popup_vote( url, y )
{
	if ( $(".popup").size() == 0 )
	{
		$.ajax({
			type: "POST",
			url: url,
			data: "",
			success:function( msg )
			{
				var html_a = "<!-- popup --><div class='popup' id='popup_inde30_voter'><div class='popup-body'><a href='javascript:void(0)' class='inde30_voter btn-close'>fermer</a><div><p><strong>";
				var html_b = '</strong> <br/> Dirige toi vers <a href="#">My Mouv’box</a>  pour personnaliser ta page perso.</p></div></div></div><!-- /popup -->';
				$("#region_content").append( html_a + msg + html_b );
				$('#popup_inde30_voter').css( "top", y ).css( "left", "45%" ).css( "margin-left", "-207px" );;
				$("#popup_inde30_voter .btn-close").click(function()
				{
					function test() { $("#popup_inde30_voter").remove(); }
					$("#popup_inde30_voter").slideUp("normal",test);
				});
			}
		});
	}
}

//
//		on appelle popup_vote au click sur les <a class="inde30_voter">
//

$('.inde30_voter').click(function(e)
{
	var url = $(this).find('span').html();
	//alert( url );
	popup_vote( url, e.pageY - 50 );
});




/**
 *		fivestar - quand on clique en non-logge faut popup inscription
 *
 *	@ author	paul
 *
 **/
$("#region_content .fivestar-widget-static .star span").click(function(e)
{
	var html = "<!-- popup --><div class='popup' id='popup_inde30_voter'><div class='popup-body'><a href='javascript:void(0)' class='inde30_voter btn-close'>fermer</a><div><p><strong>";
	html += 'Vous devez être identifié. Vous pouvez vous <a href="/user/register">inscrire ici</a>.';
	html += '</strong></p></div></div></div><!-- /popup -->';
	
	if ( $(".popup").size() == 0 ) $("#region_content").append( html );
	$('#popup_inde30_voter').css( "top", e.pageY - 50 ).css( "left", "45%" ).css( "margin-left", "-207px" );;
	$("#popup_inde30_voter .btn-close").click(function()
	{
		function test() { $("#popup_inde30_voter").remove(); }
		$("#popup_inde30_voter").slideUp("normal",test);
	});
});


$(".not-logged-in #region_content .tool.comment.comment-post").click(function(e)
{
	var html = "<!-- popup --><div class='popup' id='popup_inde30_voter'><div class='popup-body'><a href='javascript:void(0)' class='inde30_voter btn-close'>fermer</a><div><p><strong>";
	html += 'Vous devez être identifié. Vous pouvez vous <a href="/user/register">inscrire ici</a>.';
	html += '</strong></p></div></div></div><!-- /popup -->';
	
	if ( $(".popup").size() == 0 ) $("#region_content").append( html );
	$('#popup_inde30_voter').css( "top", e.pageY - 50 ).css( "left", "45%" ).css( "margin-left", "-207px" );;
	$("#popup_inde30_voter .btn-close").click(function()
	{
		function test() { $("#popup_inde30_voter").remove(); }
		$("#popup_inde30_voter").slideUp("normal",test);
	});
});

$(".not-logged-in #region_content .bg-mosaic a").not(".btn").click(function(e)
{
	var html = "<!-- popup --><div class='popup' id='popup_inde30_voter'><div class='popup-body'><a href='javascript:void(0)' class='inde30_voter btn-close'>fermer</a><div><p><strong>";
	html += 'Vous devez être identifié. Vous pouvez vous <a href="/user/register">inscrire ici</a>.';
	html += '</strong></p></div></div></div><!-- /popup -->';

	if ( $(".popup").size() == 0 ) $("#region_content").append( html );
	$('#popup_inde30_voter').css( "top", e.pageY - 50 ).css( "left", "45%" ).css( "margin-left", "-207px" );;
	$("#popup_inde30_voter .btn-close").click(function()
	{
		function test() { $("#popup_inde30_voter").remove(); }
		$("#popup_inde30_voter").slideUp("normal",test);
	});
});

/**
 *		popitup - ouvre une popup pour le player aux bonnes dimensions
 *
 *		@ author	paul
 *		@ param	String	url: adresse du player
 *
 **/
function popitup( url )
{
	newwindow = window.open( url,'name','toolbar=no,menubar=no,resizable=no,location=no,directories=no,status=no,scrollbars=no,copyhistory=no,width=832,height=266'  );
	if ( window.focus ) newwindow.focus();
	return false;
}


$('.popplayer').click(function()
{
	popitup( '/files/rfPlayer/player.html' );
});



/**
 *		On cache les blocs add_comment partout,
 *		qu'on affiche au click sur les liens "commenter"
 *
 *		@ author	paul
 *
 *
$('#comment_add').css( "display", "none" );
$('[href*=comment_add]').click(function()
{
	$('#comment_add').css( "display", "block" );
});*/



/**
 *		réduire/déplier les blocs de blog home + my mouv'box
 *
 *		@ author	paul
 *
 **/
$('.heading a.btn, .modul-box-top a.btn').click(function()
{
	if ( $(this).parent().parent().parent().find( ".side-box-bg, .modul-box-bg" ).css("display") != "none" )
	{
		$(this).removeClass("open");
		$(this).parent().parent().parent().find( ".side-box-bg, .modul-box-bg" ).slideUp("fast");
	}
	else if ( $(this).parent().parent().parent().find( ".side-box-bg, .modul-box-bg" ).css("display") != "block" )
	{
		$(this).addClass("open");
		$(this).parent().parent().parent().find( ".side-box-bg, .modul-box-bg" ).slideDown("fast");
	}
});

var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function encode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }

      output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 
         keyStr.charAt(enc3) + keyStr.charAt(enc4);
   } while (i < input.length);
   
   return output;
}

function decode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

   do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = keyStr.indexOf(input.charAt(i++));

      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;

      output = output + String.fromCharCode(chr1);

      if (enc3 != 64) {
         output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
         output = output + String.fromCharCode(chr3);
      }
   } while (i < input.length);

   return output;
}

/**
 * ouverture player AOD
 */
player = false;
function sendToPlayer(xml)
{ 
  if (player && player.sendToPlayer)
    player.sendToPlayer(xml);
  else
  {
    popitup('/files/rfPlayer/player.html?'+xml);
  }
}
/*
function sendToPlayer(title, link, guid, path, pubDate, rcsid, artist_name, song_title, length)
{
	var xml = "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?><item>" +
			"<title>" + title + "</title>" +
			"<link>" + link + "</link>" +
			"<guid>" + guid + "</guid>" +
			"<pubDate>" + pubDate + "</pubDate>" +
			"<rcsid>" + rcsid + "</rcsid>" +
			"<artist_name>" + artist_name + "</artist_name>" +
			"<song_title>" + title + "</song_title>" +
			"<path>" + path + "</path>" +
			"<duration>" + length + "</duration>" +
			"<uid>" + uid + "</uid>" +
			"<uname>" + uname + "</uname>" +
			"</item>";
	if (player && player.sendToPlayer)
		player.sendToPlayer(xml);
	else
	{
		popitup('/files/rfPlayer/player.html?'+xml);
	}
}
*/
