$(document).ready(function() { 
	definePage(namePage);
	$('a[href^=LIGNES-FORMATIONS]').each(function() { $(this).attr('href', transMail( $(this).attr('href') ) ); $(this).html( transMail( $(this).attr('href') , true ) ); });
	openMenu();
	$('div.faq p').not('.ttl').each(function(){ $(this).css('display', 'none') });
	$('.pGactu a[rel^=galerie]').click(function() { $(".pGactu a[rel^=galerie]").prettyPhoto({theme:"facebook"}); });
	$('.siteMap a[href$=espace-pro.aspx]').parent().remove();
	$('.gallery ul li a').each(function() { $(this).children('span').hide(); $(this).mouseenter(function(){ $(this).children('span').slideDown(); }).mouseleave(function(){ $(this).children('span').slideUp(); }); });
});



/*
* Verifie l'url de la page et ajoute une classe CSS dans la balise body en fonction de l'url
*/
function definePage(typePage)
{
	switch(typePage)
	{
		case 'deco' : 
		case 'photo' : 
		case 'graphisme' : 
		case 'dessin' :	
		case 'mode' :			
			namePage = typePage;
			wrote('Modules/ModuleFormations', 'Css/', 'css');
			wrote('Formations', 'Js/', 'js');
		//	changeBg(namePage);
			break;
		
		case 'profs' :
		case 'eleves' :
			namePage = typePage;
			wrote('Pages/profs', 'Css/', 'css');
			wrote('profs', 'Js/', 'js');
			wrote('playerVideo', 'Js/', 'js');
			break;
		
		case 'all-formations' :
			namePage = typePage;
			wrote('Pages/all-formations', 'Css/', 'css');
			break;
		
		case 'deco options':
		case 'photo options':
		case 'graphisme options':
		case 'dessin options':
		case 'mode options':
			namePage = typePage;
			wrote('Pages/Options', 'Css/', 'css');
			break;
		
		case 'espace-pro':
			namePage = typePage;
			wrote('Modules/ModuleEspacePro', 'Css/', 'css');
		
		case 'actu':
			namePage = typePage;
			wrote('Modules/ModuleActualites', 'Css/', 'css');
			break;
		
		case 'methode':
			namePage = typePage;
			wrote('Pages/Methode', 'Css/', 'css');
			wrote('jquery.wslide', 'Js/JQuery/', 'shared-js');
			wrote('Methode', 'Js/', 'js');
			break;
		
		case 'peda':
			namePage = typePage;
			break;
		
		default : 
			namePage = '';
			break;
	}
	
	$('body').addClass(namePage);
}

/*
* Fonction include
*/
function wrote(i, t, ex)
{
	var src = "www.lignes" + '-' + "formations.com";
	switch(ex)
	{
		case 'css' :
			$('head').append('<link href="' + '/Content/' + src + '/' + t + i + '.css' + '" rel="stylesheet" type="text/css" />');
			break;
		
		case 'js' :
			$('head').append('<script type="text/javascript" src="' + '/Content/' + src + '/' + t + i + '.js' + '"></script>');
			break;
		
		case 'shared-js':
			$('head').append('<script type="text/javascript" src="' + '/Content/' + 'Shared' + '/' + t + i + '.js' + '"></script>');
			break;

		case 'shared-css':
			$('head').append('<script type="text/javascript" src="' + '/Content/' + 'Shared' + '/' + t + i + '.css' + '"></script>');
			break;

		default :
			break;
	}
}
function test()
{
//	alert($('#sb-content .hide .galerie-'+v).length);
	$('#sb-content a[rel*=galerie]').show();
}
/*
* Ouvre dans une shadowBox, le fichier requis
*/
function openInShadow(f, galId)
{
	var error = false;
	var vContent = '';
	var vTitle = '';
	var vHeight = '';
	var vWidth = '';
	var Type = '';
	
	var testEleve = f.substring(0, 6);
	if(testEleve == 'eleve-')
	{
		Type = f.substring(6, f.length);
		f = f.substring(0, 6);
	}
	
	switch(f)
	{
		case 'teaser':
			vPlayer = 'iframe';
			vContent = '/Content/www.lignes-formations.com/Swf/demo/index.html';
			vTitle = "D\351mo du module en ligne D\351co-Design";
			vHeight = 505;
			vWidth = 575;
			break;

		case 'galerie':
			vPlayer	 = "html";
			vContent = $('.exclusif').html();
			vTitle	 = "Bienvenue dans la galerie des travaux d'\351l\350ves de Lignes et Formations";
			vHeight	 = (galId != undefined) ? 550 : 325;
			vWidth	 = 875;
			
			if(galId != undefined)
			{				
				setTimeout(function()
				{ 
					initPPT+=1; 
					var plus = '#sb-content .hide#initPPT-' + initPPT + ' ';	
					openGal(galId); 
					$('#sb-content .hide').attr('id', 'initPPT-'+initPPT); 
					$('#sb-content .hide#initPPT-' + (initPPT-1) + ' a[rel*=galerie]').unbind()
					$(plus+"a[rel*=galerie]").prettyPhoto({LFplus:plus, theme:"facebook", hideflash:true}); 
				},1500);
			}
		//	if(galId != 'undefined') $('#galerie-'+galId).trigger('click');
			break;
		
		case 'entretien':
			vPlayer	 = "html";
			vContent = $('.hide').html();
			vTitle	 = "Entretien avec Emilie MEVEL, Enseignante en Arts appliqu\351s et Design de mode.";
			vHeight	 = 600;
			vWidth	 = 600;
			break;
		
		case 'wcb':
			vPlayer	 = "iframe";
			vContent = '/Content/Files/fc/file/WCB_Lignes/wcb-js-immediat.htm';
			vTitle	 = "Nous vous rappelons gratuitement";
			vHeight	 = 215;
			vWidth	 = 300;
			break;
		
		case 'fullVideos':
			vPlayer	 = "iframe";
			vContent = '/temoignages-videos.aspx';
			vTitle	 = "T\351moignages d'anciens \351l\350ves et d'\351l\350ves en cours de formation";
			vHeight	 = 350;
			vWidth	 = 650;
			break;
		
		case 'prof-deco':
		case 'prof-photo':
		case 'prof-graphisme':
		case 'prof-dessin':
		case 'eleve-':
			
			if(Type != '')
			{
				f = f + Type;
				vTitle = 'T\351moignages d&#8242;\351l\350ves';
			}
			vPlayer	 = "html";
			vContent += '<object width="320" height="280" type="application/x-shockwave-flash" data="/Content/Files/fc/file/Videos_Lignes/flash/' + f + '.swf">';
			vContent += '<param name="movie" value="/Content/Files/fc/file/Videos_Lignes/flash/' + f + '.swf" />';
			vContent += '<embed src="/Content/Files/fc/file/Videos_Lignes/flash/' + f + '.swf" width="320" height="280" wmode="transparent" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" menu="false"></embed>';
			vContent += "</object>";
			vTitle	 = (vTitle == '') ? "Regard du professeur" : vTitle;
			vHeight	 = 280;
			vWidth	 = 320;
			break;
		
		default: error = true;
			break;
	}

	if(error === true) return false;

	Shadowbox.open(
		{
			player: vPlayer, 
			content: vContent, 
			title:vTitle, 
			height:vHeight, 
			width:vWidth, 
			handleOversize: 'none', 
			overlayColor:'#fff'
		}
	);
}

/*
* Verifie si c'est une galerie toutes sections
*/
function initPP()
{
/*	if(initPPT === false)
	{ //alert('');*/
		
		var plus = ($('.exclusif ul').length > 0) ? '#sb-content ' : '';
		$("a[rel*=galerie]").prettyPhoto({LFplus:plus, theme:"facebook", hideflash:true});
	//	initPPT = true; // Sert a ne pas RE-declarer la galerie
		$('#sb-content a[rel*=galerie] img').each(function() { $(this).attr('title', $(this).attr('alt')); });
//	}
}

/*
* Affiche les miniatures dans la galerie
*/
function openGal(sect)
{ 
	var nomSect = '';
	var heightGal = 550;
	var num = 0;
	
	switch(sect)
	{
		case 'deco' :
			num = 1;
			nomSect = 'Deco design'; 
			heightGal = 550;
			break;
		
		case 'photo' : 
			num = 2;
			nomSect = 'Photographie'; 
			heightGal = 550;
			break;
		
		case 'graphisme' : 
			num = 3;
			nomSect = 'Graphisme';
			heightGal = 550;
			break;
		
		case 'dessin' : 
			num = 4;
			nomSect = 'Dessin';
			heightGal = 550;
			break;
		
		case 'mode' : 
			num = 5;
			nomSect = 'Mode';
			heightGal = 500;
			break;
		
		default: 
			num = 01;
			nomSect = '';
			heightGal = 550;
			break;
	}
	
	$('#sb-content .hide .desc').html('<p style="font-size:5px;">&nbsp;</p><p><strong>Galerie de la section ' + nomSect + ' :</strong></p><p style="font-size:5px;">&nbsp;</p>');
	
	var vTop = (window.innerHeight - heightGal) / 2;
	$('#sb-wrapper').animate({top: vTop+'px'});
	$('#sb-body').animate({height:heightGal+'px'});
	var vLeft = (num-1) * 168 + 64;
	$('#sb-content #follow img.arrow').show();
	$('#sb-content #follow img.arrow').animate({ display:'block', left:vLeft+'px'});
	$('#sb-content .hide div').each(function() { $(this).hide(); });
	$('#sb-content .hide .galerie-' +  sect).slideDown('fast');
	
	/*$('#sb-content a[rel*=galerie]').unbind();
	if(initPPT === true) initPPT = false;*/

	//alert(plus+"a[rel*=galerie]");

}

/*
* De/Code l'adresse mail
*/
function transMail(subj, justMail) { StrCode = "Q64COQC@ZWU4SB-T6A2OCW64B.Q62"; StrCodage = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ1234567890"; IntLong=StrCode.length; StrLien=""; for (i=0; i<StrCode.length; i++) { if (StrCodage.indexOf(StrCode.charAt(i))==-1) { StrLettre=StrCode.charAt(i); StrLien+=(StrLettre); } else { StrLettre = (StrCodage.indexOf(StrCode.charAt(i))-IntLong+StrCodage.length) % StrCodage.length; StrLien+=(StrCodage.charAt(StrLettre)); } } if(justMail === true) return StrLien; else return 'mailto:'+StrLien+'?subject='+subj; }

/*
* Ouvre le menu selon l'url
*/
function openMenu()
{
	var addr = document.location.href;
	var url = addr.split('/');
	var nbCarSite = url[0].length + url[2].length + 2; 
	var regExpMenu = new RegExp(addr.substring(nbCarSite,addr.length), "gi");
	
	if(url[3].length !== 0)
	{
		$('ul.jd_menu li li').each(function(){
			if($(this).children().attr('href').match(regExpMenu))
			{
				$(this).parent().parent().addClass('jdm_hover');
				$(this).parent().show();
				$(this).children().wrapInner("<strong></strong>");
			}
		});
	}
}

/*
* Applique un effet pour le FAQ
*/
function slideFAQ(e)
{
	$(e).parent().siblings('p').slideToggle();
}

/*
* Affiche / Cache tout 
*/
function showHide(e)
{
	$('.faq div p').not('.ttl').each(function(){
		if(e == 'none')
			$(this).slideUp();
		else
			$(this).slideDown();
	});
}
