// JavaScript Document


/* initialisation inscription */



/*fonction menu deroulant*/

$(document).ready(  

 function()

 {


var timeout    = 500;

var closetimer = 0;

var ddmenuitem = 0;


function MenuDeroulant_open()

{  MenuDeroulant_canceltimer();

   MenuDeroulant_close();

   ddmenuitem = $(this).find('ul').css('visibility', 'visible');}


function MenuDeroulant_close()

{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}


function MenuDeroulant_timer()

{  closetimer = window.setTimeout(MenuDeroulant_close, timeout);}


function MenuDeroulant_canceltimer()

{  if(closetimer)

   {  window.clearTimeout(closetimer);

      closetimer = null;}}


$(document).ready(function()

{  $('#MenuDeroulant > li').bind('mouseover', MenuDeroulant_open);

   $('#MenuDeroulant > li').bind('mouseout',  MenuDeroulant_timer);
   
    $('#MenuDeroulant1 > li').bind('mouseover', MenuDeroulant_open);

   $('#MenuDeroulant1 > li').bind('mouseout',  MenuDeroulant_timer);
   
});


document.onclick = MenuDeroulant_close;


});

/**************************************************************************
**  fonction player
*****************************************************************************/

function OpenPlayer(lien){
	
	window.open(lien,'Player','toolbar=0, location=0, directories=0, status=0, scrollbars=0, resizable=0, copyhistory=0, menuBar=0, width=680, height=610');
	
}


/**************************************************************************
**  fonction popUpfenetre
*****************************************************************************/

function OpenPopUp(lien){
	
	window.open(lien,'_blank','toolbar=0, location=0, directories=0, status=0, scrollbars=0, resizable=0, copyhistory=0, menuBar=0, width=680, height=610');
	
}



/**************************************************************************
**  fonction Achat Express 
*****************************************************************************/

function Pannier(type,produit,action,ref,source){
    xajax_Pannier(type,produit,action,ref,source) ;
	
}

/**************************************************************************
**  fonction Paybox
*****************************************************************************/

function Paiement(){
    xajax_Paiement(xajax.getFormValues('formCb')) ;
	
}

/**************************************************************************
**  fonction Paybox
*****************************************************************************/

function abonnePaiement(){
    xajax_abonnePaiement(xajax.getFormValues('formCbAbonne')) ;
	
}

/**************************************************************************
**  fonction Paybox
*****************************************************************************/

function abonneSuppression(){
    xajax_abonneSuppression(xajax.getFormValues('formCbAbonneSup')) ;
	
}


/**************************************************************************
**  fonction Choixoffre
*****************************************************************************/

function Choixoffre(offre){
	//alert('ss'+offre);
	switch (offre)
	{
	case 'ABOCB3':
	window.parent.location.href= "/3/formules-14-99.html" ;
	break;
	case 'ABOCB2':
	window.parent.location.href= "/2/formules-9-99.html" ;
	break;
	default:
	window.parent.location.href= "/1/formules-3-99.html" ;
	break;
	}
	

	
}




/**************************************************************************
**  fonction inscription 
*****************************************************************************/

function inscription(){
    xajax_inscription(xajax.getFormValues('formInscription')) ;
	
}

/**************************************************************************
**  fonction incription facebook
*****************************************************************************/

function inscriptionFacebook(tab){
	xajax_inscription(tab["femail"]) ;
}

/**************************************************************************
**  fonction login
*****************************************************************************/

function login(){
	
	//var tab= new Array();
//	tab['flogin']=xajax.$("flogin").value;
//	tab['fpassword']=xajax.$("fpassword").value;
//	tab['fmemo']="";
//   
//   xajax_login(tab) ; 
   //alert("login : "+xajax.$("flogin").value);
   xajax_login(xajax.getFormValues('formLogin')) ;
}

/**************************************************************************
**  fonction oublie
*****************************************************************************/

function oublie(){
    xajax_alertEmailOublie(xajax.getFormValues('formEmailOublie')) ;
	
}

/**************************************************************************
**  fonction updateInfo
*****************************************************************************/

function updateInfo(){
    xajax_updateInfo(xajax.getFormValues('formInfo')) ;
	
}

/**************************************************************************
**  fonction updateNews
*****************************************************************************/

function updateNews(){
    xajax_updateNews(xajax.getFormValues('formNews')) ;
	
}

/**************************************************************************
**  fonction updateRenouv
*****************************************************************************/

function updateRenouv(){
    xajax_updateRenouv(xajax.getFormValues('formRenouv')) ;
	
}
/**************************************************************************
**  fonction Mise a jour du Pannier apres la confirmation de PBX
*****************************************************************************/
/*
function PBXVidePannier(){
	alert('if');
   xajax_Pannier('caddie','','vid','','parent') ;
   xajax_refreshPannier('parent');
	
}
*/
/**************************************************************************
**  fonction statLabel
*****************************************************************************/

function statLabel(){
    xajax_statLabel(xajax.getFormValues('formStat')) ;
	
}

/********************************************************************
**		PopPup
	
Fond noir => $('a.poplight[href^=#]').popOpen();
Fond transparent => $('a.poplight2[href^=#]').popOpen();
********************************************************************/
	
	
	$(document).ready(function(){

	$.fn.popOpen = function(op){
		
		popID = $(this).attr('rel'); //Get Popup Name
		popURL = $(this).attr('href'); //Get Popup href to define size
		
		//Pull Query & Variables from href URL
		query= popURL.split('?');
		dim= query[1].split('&');
		popWidth = dim[0].split('=')[1]; //Gets the first query string value
	
		
		//Fade in the Popup and add close button
		//$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>');
		$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) });
		
		
		//fond noir grisé affichage au centre
		if(op == '1')
		{
			
			//Define margin for center alignment (vertical + horizontal) - we add 80 to the height/width to accomodate for the padding + border width defined in the css
			var popMargTop = ($('#' + popID).height() + 80) / 2;
			var popMargLeft = ($('#' + popID).width() + 80) / 2;
			
			//Apply Margin to Popup
			$('#' + popID).css({ 
				'margin-top' : -popMargTop,
				'margin-left' : -popMargLeft
			});
			
			//Fade in Background
			$('body').append('<div id="fadePopup" style=" opacity : 0.8; -moz-opacity : 0.8;-ms-filter: "alpha(opacity=80)";filter : alpha(opacity=80);"></div>'); //Add the fadePopup layer to bottom of the body tag.
			$('#fadePopup').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer 
		
		}
		
		//fond transparent affichage a coté du click
		else
		{
			
			//recupére la position de l'element
			var position = $(this).position();
			
			var popMargTop = position.top;
			var popMargLeft = position.left;
			
			//positionne a coté de la source
			$('#' + popID).css({ 
			'top' : popMargTop-50,
			'left' : popMargLeft+70
			});
			
			//Fade in Background
			$('body').append('<div id="fadePopup" style=" opacity : 0; -moz-opacity : 0;-ms-filter: "alpha(opacity=0)";filter : alpha(opacity=0);"></div>'); //Add the fadePopup layer to bottom of the body tag.
			$('#fadePopup').css({'filter' : 'alpha(opacity=0)'}).fadeIn(); //Fade in the fade layer 
		}
		
	};

	//When you click on a link with class of poplight and the href starts with a # 
	
	// fonction bulle centrale
	$('a.poplight[href^=#]').click(function() {
		$(this).popOpen('1'); //Run popOpen function on click
		return false;
	});
	
	//fonction bulle achat 
	$('a.poplight2[href^=#]').click(function() {
		$(this).popOpen('2'); //Run popOpen function on click
		return false;
	});
	
	
	
	//fonction a utilisé pour lancer directement au chargement
	//$('a.poplight[href^=#]').popOpen(); //Run popOpen function once on load
	
	//Close Popups and Fade Layer
	$('a.close, #fadePopup').live('click', function() { //When clicking on the close or fade layer...
	  	$('#fadePopup , .popup_block,.popup_block_offert, .popup_block_achat, .popup_block_achat_titre').fadeOut(); //fade them both out
		$('#fadePopup').remove();
		return false;
	});


	//popOpen
	
});
	
	
/****************************** efface le contenu d'une div  ************************************************/
function flush(div)
{
	$(div).html('');
}


/****************************** gestion pub  ************************************************/
$(document).ready(function() {
	//Show the paging and activate its first link
$(".paging").show();
$(".paging a:first").addClass("active");

//Get size of the image, how many images there are, then determin the size of the image reel.
var imageWidth = $(".window").width();
var imageSum = $(".image_reel img").size();
var imageReelWidth = imageWidth * imageSum;

//Adjust the image reel to its new size
$(".image_reel").css({'width' : imageReelWidth});

//Paging  and Slider Function
rotate = function(){
    var triggerID = $active.attr("rel") - 1; //Get number of times to slide
    var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

    $(".paging a").removeClass('active'); //Remove all active class
    $active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)

    //Slider Animation
    $(".image_reel").animate({
        left: -image_reelPosition
    }, 500 );

}; 

//Rotation  and Timing Event
rotateSwitch = function(){
    play = setInterval(function(){ //Set timer - this will repeat itself every 7 seconds
        $active = $('.paging a.active').next(); //Move to the next paging
        if ( $active.length === 0) { //If paging reaches the end...
            $active = $('.paging a:first'); //go back to first
        }
        rotate(); //Trigger the paging and slider function
    }, 5000); //Timer speed in milliseconds (7 seconds)
};

rotateSwitch(); //Run function on launch

//On Hover
$(".image_reel a").hover(function() {
    clearInterval(play); //Stop the rotation
}, function() {
    rotateSwitch(); //Resume rotation timer
});	

//On Click
$(".paging a").click(function() {
    $active = $(this); //Activate the clicked paging
    //Reset Timer
    clearInterval(play); //Stop the rotation
    rotate(); //Trigger rotation immediately
    rotateSwitch(); // Resume rotation timer
    return false; //Prevent browser jump to link anchor
});

});

// cache un element et fais apparaitre un autre
function hideFadeIn(fadeIn,classActive)
	{
		$("div").find('.'+classActive).hide();
		$(fadeIn).show(); //Fade in the active content
		$(fadeIn).addClass(classActive);
		return false;
	
	}



// class gestion bouton menutoptitre 1 & 2
function addActiveClass(balise,classElement,classActive)
{
		$("div").find(balise+'.'+classActive).removeClass(classActive);
		$(classElement+' '+balise).addClass(classActive);
		return false;
}	


    
function achatOpen(produit,ref,div){
		xajax_achatOpen(produit,ref,div) ;
}


function ajoutPanier(ref){
		
		xajax_ajoutPanier(ref) ;
	  
}

function afficherPannier(){
		xajax_afficherPannier() ;
}

function afficherPlayer(refTitre){
		$(document).ready(function(){
		chaine = "<div class='rounded_ffffff3'><div class='tl'></div><div class='tr'></div><div id='waiting'><img src='/images/lodernoir.gif' width='128' align='left' height='15' />Chargement de la page ...</div><div class='bl'></div><div class='br'></div></div>";
		$('#AlerteTitreOffert').html(chaine);
		$('a.poplight3[href^=#]').popOpen(1);});
		xajax_afficherPlayer(refTitre) ;
}

function postAboTitreV1(){
		xajax_postAboTitreV1(xajax.getFormValues('formAboEmail')) ;
}
/************************************************
** Préchargement de la page de paiement wha
*****************************************************/

    function loadewha()
   {
        document.getElementById('waiting').style.display='none';
        document.getElementById('loade').style.display='block';
   } 

/**************************************************************************
**  fonction auto complétion
*****************************************************************************/

function rc_autocompleter_delay(s) {
            //if(rc_autocompleter_delay_stamp + 100 < rc_microtime()) {
                rc_autocompleter_call();
				xajax_AutoCompleter(xajax.getFormValues('formRecherche'), rc_autocompleter_date); 
           // }    
        }

/**************************************************************************
**  fonction selection des menu page d'accueil (new album, top album)
*****************************************************************************/

//selectionner menutoptitre 1 & 2 par default
$(document).ready(function() {
		
		//top
		$('#album1 a').addClass('activb');	
		$('#topTitre').hide(); //Hide all content
		$('#topVideo').hide();
		$('#topAlbum').addClass('activt');
		//nouveaute
		$('#album2 a').addClass('activbn');	
		$('#newVideo').hide();
		$('#newAlbum').addClass('activn');
		
		
		
		
});

/**************************************************************************
**  fonction desactive les onglets album et titre pour la categorie video
*****************************************************************************/
function categorieVideo()
{

$(document).ready(function() {	
		
		hideFadeIn('#topVideo','activt');
		addActiveClass('a','#video1','activb');
		//$('#album1 a').hide(); //Hide all content
		//$('#titre1 a').hide();
		$("#album1 a").removeAttr("href");
		$("#album1 a").removeAttr("onclick");
		$("#album1 a").removeAttr("onfocus");
		$("#album1 a").css({cursor: 'none'});

		$("#titre1 a").removeAttr("href");
		$("#titre1 a").removeAttr("onclick");
		$("#titre1 a").removeAttr("onfocus");

});
}

/**************************************************************************
** fonction permettant de couper les présentations trop volumineuses liste.tpl
*****************************************************************************/


$(document).ready(function(){
	

	//affichage titre album ou titre format liste
	$(".titreAlbum").each(function(){				   
		var char = $(this).text();
  		if($(this).text().length>23)
		$(this).html($(this).text().substring(0,18)+' ... ');
		
	});
	
	//affichage liste artiste de A a Z
	$(".nomArtiste").each(function(){				   
		var char = $(this).text();
  		if($(this).text().length>30)
		$(this).html($(this).text().substring(0,28)+' ... ');
		
	});
	
	//affichage liste artiste de A a Z
	$(".artiste").each(function(){				   
		var char = $(this).text();
  		if($(this).text().length>45)
		$(this).html($(this).text().substring(0,45)+' ... ');
		
	});
});


