// Fonctions Google maps
	function initialize1() {
		var local1 = new google.maps.LatLng(-20.896649,55.482379);
		
		var optionsCarte1 = {
		  zoom: 10,
		  center: local1,
		  streetViewControl: false,
		  //mapTypeControl: false,
		  mapTypeId: google.maps.MapTypeId.ROADMAP
		}
		var maCarte = new google.maps.Map(document.getElementById("map_canvas"), optionsCarte1);
		
		//var contenuinfoBulle1 = '<div id="conteneurinfoBulle1">' +
		//							'<strong>TetraNergy</strong><br/>' + 
		//						'</div> ';
		//var infoBulle1 = new google.maps.InfoWindow({
		//	 content: contenuinfoBulle1
		//})
		var optionsMarqueur1 = {
			  position: local1,
			  map: maCarte,
			  title: "TetraNergy Ile de la Réunion - Nord"
		}
		var marqueur1 = new google.maps.Marker(optionsMarqueur1);
		google.maps.event.addListener(marqueur1, 'click', function() {
			 maCarte.panTo(local1);
			 maCarte.setZoom(16);
		//	 infoBulle1.open(maCarte, marqueur1);
		});
	}
	
	function initialize2() {
		var local2 = new google.maps.LatLng(-21.33761,55.474699);
		var optionsCarte2 = {
		  zoom: 10,
		  center: local2,
		  streetViewControl: false,
		  //mapTypeControl: false,
		  mapTypeId: google.maps.MapTypeId.ROADMAP
		}
		var maCarte = new google.maps.Map(document.getElementById("map_canvas"), optionsCarte2);
		
		//var contenuinfoBulle2 = '<div id="conteneurinfoBulle2">' +
		//							'<strong>TetraNergy</strong><br/>' + 
		//						'</div> ';
		//var infoBulle2 = new google.maps.InfoWindow({
		//	 content: contenuinfoBulle2
		//})
		var optionsMarqueur2 = {
			  position: local2,
			  map: maCarte,
			  title: "TetraNergy Ile de la Réunion - Sud"
		}
		var marqueur2 = new google.maps.Marker(optionsMarqueur2);
		google.maps.event.addListener(marqueur2, 'click', function() {
			 maCarte.panTo(local2);
			 maCarte.setZoom(16);
		//	 infoBulle2.open(maCarte, marqueur2);
		});
	}
	
	function initialize3() {
		var local3 = new google.maps.LatLng(-20.242756,57.492201);
		var optionsCarte3 = {
		  zoom: 10,
		  center: local3,
		  streetViewControl: false,
		  //mapTypeControl: false,
		  mapTypeId: google.maps.MapTypeId.ROADMAP
		}
		var maCarte = new google.maps.Map(document.getElementById("map_canvas"), optionsCarte3);
		
		//var contenuinfoBulle3 = '<div id="conteneurinfoBulle3">' +
		//							'<strong>TetraNergy</strong><br/>' + 
		//						'</div> ';
		//var infoBulle3 = new google.maps.InfoWindow({
		//	 content: contenuinfoBulle3
		//})
		var optionsMarqueur3 = {
			  position: local3,
			  map: maCarte,
			  title: "TetraNergy Ile Maurice"
		}
		var marqueur2 = new google.maps.Marker(optionsMarqueur3);
		google.maps.event.addListener(marqueur2, 'click', function() {
			 maCarte.panTo(local3);
			 maCarte.setZoom(16);
		//	 infoBulle2.open(maCarte, marqueur2);
		});
	}

// Fonctions jquery validator
	jQuery.validator.addMethod( 
		"selectNone", 
		function(value, element) { 
			if (element.value == "none") 
			{ 
			 return false; 
			} 
			else return true; 
		}, 
		"Sélection obligatoire !" 
	); 


// Fonctions dimensionnement Titre1
	fen_size = {
	  _h: function() {
		  if (document.documentElement && document.documentElement.clientHeight) {
			//Internet Explorer mode Strict
			H = document.documentElement.clientHeight;
		  }
		  else if (document.body && document.body.clientHeight) {
			//Autres Internet Explorer
			H = document.body.clientHeight;
		  }
		  return H ;
	  },
	  _w: function() {
		  if (document.documentElement && document.documentElement.clientHeight) {
				//Internet Explorer mode Strict
				W = document.documentElement.clientWidth;
			}
			else if (document.body && document.body.clientHeight) {
				//Autres Internet Explorer
				W = document.body.clientWidth;
			}
			return W ;
	  }
	};
		
	function resizeTitle() {
		var Lb = 960;
		var e = 90;
		$('#titre').css({
			'display': 'block',
			'width': (fen_size._w() / 2 + e + Lb / 2),
			'margin-left': (fen_size._w() / 2 - e - Lb / 2)
		});
	};

// Fonctions test ajax
		function loadPage(page) {
			var html = $.ajax({
			  url: page,
			  async: false
			}).responseText;
			$("#main2").html(html);
		};
		


// Fonctions objet Flowplayer
		function vidHtml(link) {
			config ='';
			config = '{"plugins": { "controls": { "url": "datas/swf/flowplayer/flowplayer.controls-3.2.3.swf", "progressColor":"#E30095", "volumeColor":"#E30095", "durationColor":"#de9bc8" } },';
			config = config +'"clip":{ "baseUrl":"", "url":"'+link+'"}}';
			
			html ='<object id="flowplayer" width="540" height="432" data="datas/swf/flowplayer/flowplayer-3.2.5.swf"';
			html = html+' type="application/x-shockwave-flash">';
			html = html+' <param name="movie" value="datas/swf/flowplayer/flowplayer-3.2.5.swf" />';
			html = html+' <param name="allowfullscreen" value="true" />';
			html = html+' <param name="flashvars"';
			html = html+" value="+"'"+'config='+config+"'"+' />';
			html = html+' </object>';
			return html;
		};
		
		
		function vidHtml2(link) {
			config ='';
			config = '{"plugins": { "controls": { "url": "datas/swf/flowplayer/flowplayer.controls-3.2.3.swf", "progressColor":"#E30095", "volumeColor":"#E30095", "durationColor":"#de9bc8" } },';
			config = config +'"clip":{ "baseUrl":"", "url":"'+link+'"}}';
			
			html ='<object id="flowplayer" width="560" height="304" data="datas/swf/flowplayer/flowplayer-3.2.5.swf"';
			html = html+' type="application/x-shockwave-flash">';
			html = html+' <param name="movie" value="datas/swf/flowplayer/flowplayer-3.2.5.swf" />';
			html = html+' <param name="allowfullscreen" value="true" />';
			html = html+' <param name="flashvars"';
			html = html+" value="+"'"+'config='+config+"'"+' />';
			html = html+' </object>';
			return html;
		};
		
		
		function audioHtml(link) {
			config ='';
			config = '{"plugins": { "controls": { "url": "datas/swf/flowplayer/flowplayer.controls-3.2.3.swf", "progressColor":"#E30095", "volumeColor":"#E30095", "durationColor":"#de9bc8", "fullscreen": false, "autoHide":false } },';
			config = config +'"clip":{ "baseUrl":"", "url":"'+link+'"}}';
			
			html ='<object id="flowplayer" width="540" height="30" data="datas/swf/flowplayer/flowplayer-3.2.5.swf"';
			html = html+' type="application/x-shockwave-flash">';
			html = html+' <param name="movie" value="datas/swf/flowplayer/flowplayer-3.2.5.swf" />';
			html = html+' <param name="allowfullscreen" value="true" />';
			html = html+' <param name="flashvars"';
			html = html+" value="+"'"+'config='+config+"'"+' />';
			html = html+' </object>';
			return html;
		};
		
		//News admin
		
		//$("#loginNews").fancybox();
		
		function add() {
		$.fancybox({
				href		:	"datas/php/actualites_add_form.inc.php",
				titleShow	:	false,
				autoDimensions: false,
				width		:	720,
				onComplete	:	function() {
									//TinyMCE
									tinyMCE.init({
										mode : "textareas",
										theme : "advanced",
										forced_root_block : false,
										force_br_newlines : true,
										force_p_newlines : false,
										relative_urls : false,
										
										theme_advanced_resizing: true,
										theme_advanced_resize_horizontal:false,
										theme_advanced_path : false,
										theme_advanced_statusbar_location: "bottom",
										
										theme_advanced_buttons1 : "bold,italic,underline,sub,sup,|,undo,redo,removeformat,|,link,unlink",
										//theme_advanced_buttons1 : "bold,italic,underline,sub,sup,|,bullist,numlist,|,undo,redo,removeformat,|,link,unlink",
										theme_advanced_buttons2 : false,
										theme_advanced_buttons3 : false,
										theme_advanced_toolbar_align : "center",
										
										valid_elements : "strong,em,br"
									});
									//Soumission formulaire
									$("form.add").bind("submit", function() {
										$.fancybox.showActivity();
										$.ajax({
											type	: "POST",
											cache	: false,
											url		: "datas/php/actualites_add.inc.php",
											data	: $(this).serializeArray(),
											success	: function(data) {
														$.fancybox({
															titleShow	:	false,
															content		:	"L'article a été créé.",
															onComplete	:	function() { $(data).insertBefore('.toEdit:first'); }
														});
													}
										});
										return false;
									});
								}
		});
		};
		
		
		function edit(id) {
		$.fancybox({
				href		:	"datas/php/actualites_edit_form.inc.php?id="+id,
				titleShow	:	false,
				autoDimensions: false,
				width		:	720,
				onComplete	:	function() {
									//TinyMCE
									tinyMCE.init({
										mode : "textareas",
										theme : "advanced",
										forced_root_block : false,
										force_br_newlines : true,
										force_p_newlines : false,
										relative_urls : false,
										
										theme_advanced_resizing: true,
										theme_advanced_resize_horizontal:false,
										theme_advanced_path : false,
										theme_advanced_statusbar_location: "bottom",
										
										theme_advanced_buttons1 : "bold,italic,underline,sub,sup,|,undo,redo,removeformat,|,link,unlink",
										//theme_advanced_buttons1 : "bold,italic,underline,sub,sup,|,bullist,numlist,|,undo,redo,removeformat,|,link,unlink",
										theme_advanced_buttons2 : false,
										theme_advanced_buttons3 : false,
										theme_advanced_toolbar_align : "center",
										
										valid_elements : "strong,em,br"
									});
									//Soumission formulaire
									$("form.edit").bind("submit", function() {
										$.fancybox.showActivity();
										$.ajax({
											type	: "POST",
											cache	: false,
											url		: "datas/php/actualites_edit.inc.php",
											data	: $(this).serializeArray(),
											success	: function(data) {
														$.fancybox({
															titleShow	:	false,
															content		:	'Les modifications ont été enregistrées.',
															onComplete	:	function() {
																				var d = $(data);
																				$('#'+id+' .article span.h3').first().html(d.children('span.h3').html());
																				$('#'+id+' .article span.texte').html(d.children('span.texte').html());
																			}
														});
													}
										});
										return false;
									});
								}
		});
		};
		
		
		function manage_img(id) {
		$.fancybox({
				href		:	"datas/php/actualites_manage_img.inc.php?id="+id,
				titleShow	:	false,
				autoDimensions: false,
				width		:	720,
				onComplete	:	function() {
								}
		});
		};
		
		// Gestion des images
		function sort_img() {
			$(".sortable").sortable({ opacity: 0.6, cursor: 'move', update: function() {
					var articleID = $(this).parent().parent().parent().attr('id');
					var order = $(this).sortable("serialize") + '&action=updateRecordsListings' + '&articleID=' + articleID;
					$.post("datas/php/sort_img_updateDB.php", order );
				}
			});
		}
		function del_img(articleID, imgID) {$.fancybox({
				href		:	"datas/php/actualites_del_img_form.inc.php?articleID="+articleID+"&imgID="+imgID,
				titleShow	:	false,
				autoDimensions: false,
				width		:	720,
				onComplete	:	function() {
									//alert($('this').attr('href');)
									$("form.delete").bind("submit", function() {
										$.fancybox.showActivity();
										$.ajax({
											type	: "POST",
											cache	: false,
											url		: "datas/php/actualites_del_img.inc.php",
											data	: $(this).serializeArray(),
											success	: function(data) {
														$('#recordsArray_'+imgID).remove();
														$.fancybox.close();
														sort_img();
													}
										});
										return false;
									});
								}
		});
		}
		function add_img(articleID) {$.fancybox({
				href		:	"datas/php/actualites_add_img_form.inc.php?articleID="+articleID,
				titleShow	:	false,
				autoDimensions: false,
				width		:	720,
				onComplete	:	function() {									  
									$('#file_upload').uploadify({
										'uploader'  : 'datas/js/jquery.uploadify-v2.1.4/uploadify.swf',
										'script'    : 'datas/js/jquery.uploadify-v2.1.4/uploadify.php',
										'cancelImg' : 'datas/js/jquery.uploadify-v2.1.4/cancel.png',
										'folder'    : 'datas/actu_img/uploads',
										'removeCompleted' : false,
										'sizeLimit' : 10000000,
										'fileExt'	: ".jpg, .png, .gif, .bmp",
										'auto'      : true,
										'onComplete'  : function(event, ID, fileObj, response, data) {
															alert(fileObj.name + " est bien chargé");
															$.ajax({
																type	: "GET",
																cache	: false,
																url		: "datas/php/actualites_add_img.inc.php?articleID="+articleID+"&imgName="+fileObj.name,
																data	: $(this).serializeArray(),
																success	: function(data2) {
																			$('#'+articleID+' .sortable').append('<span id="recordsArray_'+eval(data2)+'" ><img src="datas/actu_img/'+eval(data2)+'_s.jpg"class="pic" /><a class="delpic" onclick="javascript: del_img( '+articleID+', '+eval(data2)+');" title="Supprimer l\'image"><img src="datas/images/delete.png"/></a></span>');
																			sort_img();
																		}
															});
														}
									});
								}
		});
		}
		
		function del(id) {
		$.fancybox({
				href		:	"datas/php/actualites_delete_form.inc.php?id="+id,
				titleShow	:	false,
				autoDimensions: false,
				width		:	720,
				onComplete	:	function() {
									//alert($('this').attr('href');)
									$("form.delete").bind("submit", function() {
										$.fancybox.showActivity();
										$.ajax({
											type	: "POST",
											cache	: false,
											url		: "datas/php/actualites_delete.inc.php",
											data	: $(this).serializeArray(),
											success	: function(data) {
														$.fancybox({
															titleShow	:	false,
															content		:	"L'article a été supprimé.",
															onComplete	:	function() { $('#'+id).remove(); }
														});
													}
										});
										return false;
									});
								}
		});
		};
		
		
		function moveUp(id) {
			idInit = id;
			idFinal = $('#'+id).prev().attr('id');
			$.fancybox.showActivity();
			$.ajax({
				type	: "GET",
				cache	: false,
				url		: "datas/php/actualites_move.inc.php?init="+idInit+"&final="+idFinal,
				data	: $(this).serializeArray(),
				success	: function(data) {
							$('#'+idFinal).insertAfter('#'+idInit);
							$('#'+idFinal).attr('id', 0);
							$('#'+idInit).attr('id', idFinal);
							$('#'+0).attr('id', idInit);
							
							$.fancybox.hideActivity();
						}
			});
			return false;
		};
		
		function moveDown(id) {
			idInit = id;
			idFinal = $('#'+id).next().attr('id');
			$.fancybox.showActivity();
			$.ajax({
				type	: "GET",
				cache	: false,
				url		: "datas/php/actualites_move.inc.php?init="+idInit+"&final="+idFinal,
				data	: $(this).serializeArray(),
				success	: function(data) {
							$('#'+idFinal).insertBefore('#'+idInit);
							$('#'+idFinal).attr('id', 0);
							$('#'+idInit).attr('id', idFinal);
							$('#'+0).attr('id', idInit);
							
							$.fancybox.hideActivity();
						}
			});
			return false
		};
		
		

		function toggleEditor(id) {
			if (!tinyMCE.get(id))
			tinyMCE.execCommand('mceAddControl', false, id);
			else
			tinyMCE.execCommand('mceRemoveControl', false, id);
		};
		
// Actions après chargement de la page ////////////////////////////////////////////////////////////////////////////////////////////
	$(document).ready(function() {

		
		//Jquery.sortable
		sort_img();
		
		// Jquery.validator
		$("#contact").validate({
			submitHandler:function(form) {
				SubmittingForm();
			},
			rules: {
				nom: "required",
				prenom: "required",
				email: {
					required: true,
					email: true
				},
				situation: {
					selectNone: true	
				},
				localite: {
					selectNone: true	
				},
				objet: "required"
			},
			messages: {
				nom: "Champs obligatoire !",
				prenom: "Champs obligatoire !",
				email: "Email non-valide !",
				objet: "Champs obligatoire !"
			}
		});
		
		// Titre h1
		
		resizeTitle();
		$(window).resize(function() {
			resizeTitle(fen_size._w());
		});
		
		// Correction CSS IE
		if ( ! $('#nav a:last').hasClass('active') ) {
			$('#nav a:last').css("border-bottom", "1px solid #CCCCCC");
		}
		
		
		// Animation page d'accueil
		$('.index').hover( function() {
			$(this).children('.overlay').animate({
				"top": "-225px",
				"height": "222px"
			}, '300ms');
		}, function() {
			$(this).children('.overlay').animate({
				"top": "-46px",
				"height": "43px"
			}, '300ms');
		});

		
		
		// Jcarousel
		$('#carouselRef').jcarousel({
			vertical: false,
			scroll: 1,
			auto: 2,
			wrap: 'circular'
		});
		
		
		$('#carouselRef2').jcarousel({
			vertical: true,
			scroll: 1,
			auto: 3,
			wrap: 'both',
			buttonNextHTML: null,
			buttonPrevHTML: null
		});
		
		// Tipsy
		$('.icone').tipsy({fade:true, gravity:'s'});
		$('#partenaires>a').tipsy({fade:true, gravity:'s'});
		$('a.partenaire').tipsy({fade:true, gravity:'s'});
		$('a.theme').tipsy({fade:true, gravity:'s'});
		$('.video_link, .audio_link, .video_link2').tipsy({fade:false, gravity:'n'});
		//$('.shortArt').tipsy({fade:true, gravity:'e', html: true});
		
		//Test ajax
		//$("#nav a").click(function() {
		//	var link=$(this);
		//	link.removeAttr("href").addClass("active").siblings().removeClass("active");
		//	$("#main2").slideUp(function() {
		//		loadPage("datas/php/" + link.attr("name"));
		//	}).slideDown();
		//});
		
		// Afficher / Masquer les formations diplômantes
		$(".expandable").each(function() {
			$(this).hide().parent().append('<span class="expand">afficher les détails</span>');
		});
		
		$(".expand").click(function() {
			var p = $(this).parent();
			if (p.hasClass('expanded')) {
				p.removeClass('expanded').children('.expandable').slideUp('slow', function() {
					p.children(".expand").html('afficher les détails');
				});
			}
			else{
				p.addClass('expanded').children('.expandable').slideDown('slow', function() {
					p.children(".expand").html('masquer les détails');
				});
				p.siblings().removeClass('expanded').children('.expandable').slideUp('slow', function() {
					p.siblings().children(".expand").html('afficher les détails');
				});
			}
		});
		
		//Google maps
		$('#message').show();
		$('.adresse[name="1"]').click(function() {
			$('#message').hide();
			$('#cursor').show().css('left', 92 );
			$(this).addClass('active').siblings('.adresse').removeClass('active');
			$("#map_canvas").css('display', 'block');
			initialize1();
		});
		$('.adresse[name="2"]').click(function() {
			$('#message').hide();
			$('#cursor').show().css('left', 92+182 );
			$(this).addClass('active').siblings('.adresse').removeClass('active');
			$("#map_canvas").css('display', 'block');
			initialize2();
		});
		$('.adresse[name="3"]').click(function() {
			$('#message').hide();
			$('#cursor').show().css('left', 92+182*2 );
			$(this).addClass('active').siblings('.adresse').removeClass('active');
			$("#map_canvas").css('display', 'block');
			initialize3();
		});
		
		
		
		//Medias (flowplayer + fancybox)
		
		$("a.video_link").append('<img style="position: relative; width: 20px; height: 17px; bottom:22px;left: 77px;" src="datas/images/video.png" alt="tag video"/>');
		$("a.video_link2").append('<img style="position: relative; width: 20px; height: 17px; bottom:22px;left: 77px;" src="datas/images/video.png" alt="tag video"/>');
		$("a.audio_link").append('<img style="position: relative; width: 20px; height: 17px; bottom:22px;left: 77px;" src="datas/images/video.png" alt="tag audio"/>');
		
		$(".video_link").click(function() {
			link = $(this).attr('href');
			title = $(this).attr('original-title');
			$.fancybox({
				content : vidHtml(link),
				title	: title
			});
			return false;
		});
		
		$(".video_link2").click(function() {
			link = $(this).attr('href');
			title = $(this).attr('original-title');
			$.fancybox({
				content : vidHtml2(link),
				title	: title
			});
			return false;
		});
		
		$(".audio_link").click(function() {
			link = $(this).attr('href');
			title = $(this).attr('original-title');
			$.fancybox({
				content : audioHtml(link),
				title	: title
			});
			return false;
		});
				
		$(".image_link").fancybox({
		'hideOnContentClick': true
		});
		
		$(".fancybox").fancybox({
		'hideOnContentClick': true
		});
		
	
		
	});
	
