// Cd-Media.fr - 10/2002
// common.js

window.onDomReady(function()
{
	jQuery.noConflict();
//	jQuery(function() { jQuery(".lavaLamp").lavaLamp({ fx: "backout", speed: 700 })});
	
	hideLoad();
	
	if ( $('map_canvas') ) initialize();
	
	// Initialiser le diaporama
	if( $('diaporama') ) {
		var intro = new gallery($('diaporama'), {
			timed: true,
			slideInfoZoneSlide: true,
			showCarousel: false,
			fadeDuration: 1500,
			delay: 6000,
			embedLinks: false,
			showArrows: false,
			forceSize: true,
			elementWidth: '367px',
			elementHeight: '143px',
			useThumbGenerator: true
		});
	}
	
	for (j = 0; j < 4; j++ ) {
		navRoot = $("nav" + j.toString());
		
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			
			if (node.nodeName == "LI") {
				node.onmouseover=function() {  this.className = ( this.className.match( "current" ) ) ? "current over" : "over"; }
				node.onmouseout=function() { this.className = ( this.className.match( "current" ) ) ? "current" : ""; }
			}
		}
	}
	
	
	
	var myTimer, idSection = 2, nbAg = $('nbAg').value, divAg, idDivToMov = 1, divToMov, nbBis = nbAg;
	
	divAg = 'agendaJSHome';
	
	var scroll = new Fx.Scroll(divAg, {
		wait: false,
		duration: 3500,
		offset: {'x': -200, 'y': 0},
		transition: Fx.Transitions.Quad.easeInOut
	});
	
	scroll.addEvent( 'onComplete', function () {
		divToMov = $('section' + idDivToMov.toString());
		divToMov_clone = divToMov.clone();
		divToMov_clone.setProperty( 'id', 'section' + (++nbBis).toString() )
		divToMov_clone.inject( $('main_content') );
		
		idDivToMov++;
		if ( idDivToMov > nbAg ) idDivToMov = 1;
	});
		
	function timedScroll() {
		scroll.toElement('section' + idSection.toString());
		idSection++;
//		if ( idSection > nbAg ) idSection = 1;
		
		myTimer = timedScroll.delay(8500);
	}
	
	myTimer = timedScroll.delay(5000);
	
});


var newfen=null;

function processPage( form )
{
         document.location = form.sel.options[form.sel.selectedIndex].value;
         form.sel.options[0].selected = true;
}




function fenexy( nom, x, y, sc ) {
  strhei = "HEIGHT=" + y
  strwid = "WIDTH=" + x
  if( sc ==null )  sc = 0
  scrol = "scrollbars=" + sc
  strf = strhei + "," + strwid + "," + scrol
  if( newfen != null ){
    newfen.close() }
  newfen = window.open(nom,"", strf)
}

function fenexy1( nom, x, y, sc ) {
	strhei = "HEIGHT=" + y
	strwid = "WIDTH=" + x
	if( sc ==null )  sc = 0
	scrol = "scrollbars=" + sc
	strf = strhei + "," + strwid + "," + scrol
	window.open(nom,"", strf)
}




function ar( container, go_url, methode, param  ) {	
	if( arguments.length == 3 ) {
		param =  Form.serialize( document.forms[0] );
	}
//	$(container).innerHTML = 'Loading...';
	
	new Ajax(go_url + '?' + param, {
		onStateChange: showLoad(),
		onComplete: function() { hideLoad(); },
		update: container,
		method: methode}).request();
	/*
	var xmlHttp = new Ajax.Updater( container, go_url, 
					{	method: methode,
						parameters: param
					}
				);
					*/
}


function showLoad()
{
	// Montrer le div de chargement en haut a gauche de l'écran
	$('page_loading').setStyles({ visibility: 'visible' });
}

// Cacher img chargement
//
function hideLoad()
{
	// Cacher le div de chargement en haut a gauche de l'écran
	$('page_loading').setStyles({ visibility: 'hidden' });
}




// Google Map
//
var map = null;
var geocoder = null;

function initialize() {
  if (GBrowserIsCompatible()) {
	map = new GMap2(document.getElementById("map_canvas"));
	//map.setCenter(new GLatLng(46.4419, 9), 7);
	contPos = new GControlPosition( G_ANCHOR_BOTTOM_RIGHT );
	map.addControl( new GSmallZoomControl(), contPos );
	map.addControl( new GMapTypeControl(G_HYBRID_MAP) );
	geocoder = new GClientGeocoder();
	showAddress( "Cargèse, Corse" );
  }
}

function showAddress(address) {
  if (geocoder) {
	geocoder.getLatLng(
	  address,
	  function(point) {
		//alert( point.lat() + ', ' + point.lng() );
		if (!point) {
		  alert(address + " not found");
		} else {
			map.clearOverlays();
//			$('latitude').value = point.lat();
//			$('longitude').value = point.lng();		
		  map.setCenter(point, 13);
		  var marker = new GMarker(point,  {draggable: true});
		  
		GEvent.addListener(marker, "dragstart", function() {
		  map.closeInfoWindow();
		  });
		
		GEvent.addListener(marker, "dragend", function() {
			var tpoint =  marker.getPoint();
//			$('latitude').value = tpoint.lat();
//			$('longitude').value = tpoint.lng();			
		 // marker.openInfoWindowHtml(adress);
		  });
		map.addOverlay(marker);
		//  marker.openInfoWindowHtml(adress);
		}
	  }
	);
  }
}
// Fin Google Map


