$(function(){
    setVideo();
    $('#main #content .section').not('#main #content .section:first').hide();
	$('#main .nav li a').each(function(i){
		$(this).click(function(e){
			e.preventDefault();
			var video = window.document.getElementById('trailer');
            var ind = i.toString();
            if(video){
            	if(ind!='1'){
	                video.pause();
	            }else{
	                video.play(); 
	            }
            }
			$('#main .nav li a').each(function(i){
				$(this).removeClass('active');
			});
            $(this).addClass('active');
			$('#main #content .section').hide();
			$('#main #content .section:eq('+i+')').show();
		});
	});
})


function setVideo()
{

    var browser = $.browser;

    var src = "trailer_old.mp4";
    var type = "video/mp4; codecs=\'avc1.58A01E, mp4a.40.2\'";
    if(browser.mozilla == true)
    {
        src = "trailer.ogg";
        type = "video/ogg"; 
    }
    if((browser.webkit == true) && (browser.version == "533.17.9"))
    {
        src = "trailer_iphone.mp4";
        type = "video/mp4";         
    }
    var videoSrc = $("<video/>").attr({
        src     :   src,
        id      :   "trailer",
        width   :   600,
        height  :   450,
        preload :   "preload",
        controls:   "controls",
        autobuffer: "autobuffer",
        poster  :   "imgs/video_loading.png",
        type    :   type
    });    
   
   if((browser.version<8.5)&&(browser.msie))
   {
   		var videoSrc = '<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" width="600" height="450" codebase="http://www.microsoft.com/Windows/MediaPlayer/"><param name="Filename" value="trailer.wmv"><param name="AutoStart" value="false"><param name="ShowControls" value="true"><param name="BufferingTime" value="2"><param name="ShowStatusBar" value="true"><param name="AutoSize" value="true"><param name="InvokeURLs" value="false"><embed src="trailer.wmv" type="application/x-mplayer2" autostart="0" enabled="1" showstatusbar="1" showdisplay="1" showcontrols="1" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" CODEBASE="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,0,0" width="600" height="450"></embed></object>';
   }
    $("#videoContainer").html(videoSrc);
}

// Plan du site
	//<![CDATA[
	var CarteItineraire;
	var gdir;
	var geocoder = null;
	var addressMarker;

/*TC*	Définition des variables caractérisant la société ... **/
	var NomSociete = 'Business lab';
	var Adresse = '26 rue des Amandiers';
	var CodePostal = '92000';
	var Ville = 'NANTERRE';
	var LatitudeDestination = '48.890155';
	var LongitudeDestination = '2.203565';
	var point;


	function load() {
		if (GBrowserIsCompatible()) {
			
				MaCarte = new GMap2(document.getElementById("EmplacementDeMacarte"));
			
			point = new GLatLng(LatitudeDestination,LongitudeDestination);
			
if( (navigator.platform.indexOf("iPhone") != -1) ||   (navigator.platform.indexOf("iPod") != -1)  ||   (navigator.platform.indexOf("iPad") != -1)) 
	{
		MaCarte.setCenter(point, 13);
	}else{
		MaCarte.setCenter(new GLatLng(48.90856712191363, 2.149801254272461), 13);
	}
			var marker = CreationDuMarqueur(point);
			MaCarte.addOverlay(marker);
		}else{
			alert("Désolé, mais votre navigateur n'est pas compatible avec Google Maps");
		}
	}

	function CreationDuMarqueur(point) {
		var marker = new GMarker(point);
		GEvent.addListener(marker, 'click', function() {
			var formulaire_itineraire ='<div id="formItineraire">' +
			'<form action="#" onsubmit="setDirections(this.from.value, this.to.value, this.locale.value); return false">' +
			'			<h4>Indiquez votre adresse de d&eacute;part ci-dessous :</h4>' +
			'			<input type="text" id="fromAddress" name="from" value="" />' +
			'			<p><h4>Adresse d\'arriv&eacute;e :</h4>' +
			'			'+NomSociete+'<br />'+Adresse+'<br />'+CodePostal+' '+Ville+'</p>' +
			'			<input type="hidden" id="toAddress" name="to" value="'+LatitudeDestination+', '+LongitudeDestination+'" />' +
			'			<p>R&eacute;ponse en :' +
			'				<select id="locale" name="locale">' +
			'					<option value="fr" selected>Français</option>' +
			'					<option value="en">Anglais</option>' +
			'					<option value="de">Allemand</option>' +
			'					<option value="ja">Japonais</option>' +
			'					<option value="es">Espagnol</option>' +
			'				</select>' +
			'				<input name="submit" type="submit" value="Afficher l\'itin&eacute;raire" /></p>' +
			'</form>' +
			'</div>';
			marker.openInfoWindowHtml(formulaire_itineraire);
		});
		return marker;

	}

	function setDirections(fromAddress, toAddress, locale) {
		var resultat = parent.document.getElementById("ReponseItineraire").style;
		resultat.display = '';
		if(gdir){gdir.clear();}
		CarteItineraire = new GMap2(parent.document.getElementById("EmplacementCarteItineraire"));
		gdir = new GDirections(CarteItineraire, parent.document.getElementById("EmplacementTexteItineraire"));
		GEvent.addListener(gdir, "error", EnCasdErreur);
		gdir.load("from: " + fromAddress + " to: " + toAddress,	{ "locale": locale });
	}

	function EnCasdErreur(){
		if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS){

			alert('Aucun endroit géographique ne correspond. Code d\'erreur : ' + gdir.getStatus().code);
		}else{
			alert('Une erreur inconnue s\'est produite.');
		}
	}
	

    //]]>

