$(document).ready(function() {
	
	$('ul#accordion').accordion({
		autoHeight: false,
		headerSelected: 'active',
		header: '.head'
	});
	
	$("ul#pages").jcarousel({
		scroll: 1,
		animation: 500,
		wrap: "both",
		initCallback: mycarousel_initCallback
    });
    
    $("ul.catalogue").accordion({
    	autoHeight: false,
    	 headerSelected: "active",
    	 header: ".head"
   	});
   	
	$("ul.carte").accordion({
		autoHeight: false,
		headerSelected: "active",
		header: ".head"
	});
});

function mycarousel_initCallback(carousel) {
    $("#menu > ul > li > a").bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval($(this).attr("href")));
        $("#menu > ul > li").removeClass("active");
        $(this).parents("li").addClass("active");
        return false;
    });
};

function SendMailContact() {
	//validation du formulaire
	if(ValidateFormContact()) {
		$("#contact").hide().addClass("mail_loading");
		//$("#contact").addClass("mail_loading");
		$("form#contact").ajaxSubmit({
			success: function(result) {
				if (result!="false"){
					$('#message_contact').html(result);
					$("#contact").hide();
				}
			}
	    });
	}
}

function ValidateFormContact(){
	var alertMsg = "<p>Merci de saisir les champs suivant : ";
	var l_Msg = alertMsg.length;
	$("#contact").find("input,textarea").each(function() {
		if($(this).attr("obligatory")) {
			var val = $(this).val();
			var valinterdite = $(this).attr('valinterdite');			
			if((val=="")||(val==null)||(val==" ")||(val==valinterdite)) {
				var label=$(this).attr('name');
				alertMsg += label+", ";
			}
		}
	});
	if (alertMsg.length == l_Msg) return true;
	else {
		var len = alertMsg.length-2;
		var msg = alertMsg.substring(0,len*1)+"</p>";
		$('#message_contact').html(msg);
	}
}

function RenderMap(lat,lng,zoom,type) {
	setTimeout(function() {
		if(zoom==null) zoom = 10;
		if(type==null) { 
			type = G_NORMAL_MAP;
		} else {
			switch(type) {
				case "map": type = G_NORMAL_MAP; break;
				case "satellite": type = G_SATELLITE_MAP; break;
				case "hybrid": type = G_HYBRID_MAP; break;
			}
		}
		if(GBrowserIsCompatible()) {
			var map = new GMap2(document.getElementById("map"));
			map.setCenter(new GLatLng(lat,lng),zoom,type);
			var point = new GLatLng(lat,lng);
			map.addOverlay(new GMarker(point));
			//map.addControl(new GLargeMapControl3D());
			map.addControl(new GScaleControl());
			//map.addControl(new GMenuMapTypeControl());
		}
	},2500);
}

function OpenGallery(id) {
	var items = $("a.sbxg_"+id);
	Shadowbox.open(items[0]);
}

$.listen("click","a.suite",function() {
	$.ajax({
		type: "POST",
		url: "content/ajax/ajax_pagecoms_module_actualites_suite.php",
		data: "article="+$(this).href,
		success: function(data) {
			Shadowbox.open({
				player: "html",
				title: $(this).attr("title"),
				content: data,
				width: 500,
				height: 400
			});
		}
	});
	return false;
});


/*Génération de la carte gmap lors du déroulement de l'acordéon*/
/*$('#gmap > a.head').click(function() {
	//on récupère la latitude et la longitude du point à afficher
	var lat = $("#sidebar > input.lat").val();
	var lon = $("#sidebar > input.lon").val();
	//appel de la fonction de création de la map
	$("li#gmap >div#map").html(RenderMap(lat,lon));
});*/