
	function initialize(x,y,content,div) {
		if((empty(x) || empty(y))){
			$('#supportmap' + div).hide();
		}else{
			//console.log(x + ', ' + y + ', ' + content + ', ' + div);
		    var myLatlng = new google.maps.LatLng(x, y);
		    var myOptions = {
		      zoom: 12,
		      center: myLatlng,
		      mapTypeId: google.maps.MapTypeId.ROADMAP
		    }
		    var mapdiv = 'map' + div;
		    var map = new google.maps.Map(document.getElementById(mapdiv), myOptions);
		    console.log($('#' + mapdiv));
		    var marker = new google.maps.Marker({
		        position: myLatlng, 
		        map: map,
		        title:content
		    }); 
		}
  	}
	

	/* ADD MARKER */
	function addmarker(map,point,content) {
			map.setCenter(point, 16);
			var marker = new GMarker(point);
			var size = new GSize('628', '450');
			map.size=size;
			map.addOverlay(marker);
			map.addControl(new GLargeMapControl());
			// marker
			if(!empty(content)){
				GEvent.addListener(marker, "click", function(){
	          		marker.openInfoWindowHtml(content);
	            });
			}
		}

	function eventload(page,target,url){
	console.log('eventload');
		genericPrototype(url+'/page/'+page, 'genericJson', 'post','target='+target);
	}



$(document).ready(function() {
	
	$('#keywords').focus(function (){
		this.value = '';
	})
	

	$("#calendarsearch").validationEngine({
		unbindEngine: false,
        success :  function() {$.formsClassJson.saveActionNoajax(formsSearchCalendar)},
        failure : function() {}
       });
	
	//link signal
	$(".signal").live('click',function(){
		$.fn.colorbox({href:this.rel,height:"250px", width:"500px"});
		return false;
	});	
	
	//init accordion
	$(".accordion dt").eq(0).addClass("active");
	$(".accordion dd").eq(0).show();
	var localisationx = $('.accordion dt.active .googledatax').val();
	var localisationy = $('.accordion dt.active .googledatay').val();
	var gmapdiv		  = $('.accordion dt.active .googlediv').val();
	var gmapgenerated = $('.accordion dt.active .googleisgenerated').val() == 1 ? true : false ;
    var content = '<h3>'+$(".accordion dt h3").html()+'</h3>';
    content = content+$('.accordion dd .contact').html();
    if (!gmapgenerated) {
		initialize(localisationx,localisationy,content,gmapdiv);
	}
	
	// menu accordion
	$(".accordion dt").live('click',function(){
	  //click
	  $(this).next("dd").slideToggle("slow").siblings("dd:visible").slideUp("slow");
	  $(this).toggleClass("active");
	  $(this).siblings("dt").removeClass("active");
	  if($(this).attr('class')=='hover'){
		  //$('#supportmap').hide("slow");
	  }else{
		  //localisation
		  var localisationx = $(this).find('.googledatax').val();
		  var localisationy = $(this).find('.googledatay').val();
		  var gmapdiv	    = $(this).find('.googlediv').val();
		  var gmapgenerated = $(this).find('.googleisgenerated').val() == 1 ? true : false ;
		  var content = '<h3>' + $(this).find('h3').html() + '</h3>';
		  content = content + $(this).next("dd").find('.contact').html();
		  if (!gmapgenerated) {
			initialize(localisationx,localisationy,content,gmapdiv);
		  }
	  }
	});
	
	//change tabs
	$('.tabs ul.tabNav li a.tabs').click(function(){
		  idTabs = '#'+$(this).attr('rel');
		  localisationx = $(idTabs).find('.accordion dt.active .googledatax').val();
		  localisationy = $(idTabs).find('.accordion dt.active .googledatay').val();
		  gmapdiv	    = $(idTabs).find('.accordion dt.active .googlediv').val();
		  gmapgenerated = $(idTabs).find('.accordion dt.active .googleisgenerated').val() == 1 ? true : false ;
		  var content = '<h3>' + $(".accordion dt h3").html() + '</h3>';
		  content = content + $('.accordion dd .contact').html();
		  if(empty(localisationx) && empty(localisationy)){
			  $('#supportmap' + gmapdiv).hide();
		  }else{
		  	  $('#supportmap' + gmapdiv).show();
		  	  $('#map' + gmapdiv).html('');
			  if (!gmapgenerated) {
				initialize(localisationx,localisationy,content,gmapdiv);
			  }
		  }
	});
	
	
	/*hover*/
	$(".accordion dt").hover(
		  function () {
			$(this).addClass("hover");
		  },
		  function () {
			$(this).removeClass("hover");
		  }
	);
});	
