// JavaScript Document
  
////////////////////////////////////////////////////////////////////////////  
//*************************** Flash function *****************************//
////////////////////////////////////////////////////////////////////////////
var player = null;
function playerReady(thePlayer) {
	player = document.getElementById(thePlayer.id);
	addListeners();
}

function afficheType(){
	$("#info_type").slideDown("slow",function(){
 		$(".blocType").slideDown("fast");
 	});
}	

function afficheInfo(type){
	$("#infoTrajet").show();
}  	
function recherche(pays, type, lang, variable){
	$("#divResult").html("");
	$.get("/atc_user/layout/set/xml/infotour/par_"+type+"_result/id/"+variable, {}, function(xml) {
		var compagnies = $("liste_compagnies", xml).children("compagnie");
		$("#divResult").append("<ul>");
		$.each(compagnies, function(i,e){
			$("#divResult").append("<li><a href='/"+ezSiteAccess+"/infotour/"+type+"_compagnie/id/"+$(e).attr("id")+"'>"+$(e).attr("nom")+" : "+$(e).attr("site_web")+"</a></li>");
		});
		$("#divResult").append("</ul>");
        var villes = $("liste_compagnies", xml).children("ville");
        formFiltre(villes, type, variable, 0);
	});

	$("#rechercheTrajet").show();
	$("#pays").text(pays);
}

function formFiltre(villes, type, pays, ville){
    $("#filtre").html('<form id="formFiltre">');
    var sel ='<select name="filtreVille" id="filtreVille" onchange="doFiltre();">';
    sel += '<option value="0">Au d&eacute;part de...</option>';
    $(villes).each(function (i,e){
        sel += '<option value="'+$(e).attr('id')+'" ';
        if ($(e).attr('id') == ville)
                sel +='selected="selected" ';
        sel += '>'+$(e).text()+'</option>';
    });
    sel += '</select>';
    $("#filtre").append(sel);
    $("#filtre").append('<input type="hidden" name="idpays" id="idpays" value="'+pays+'" />');
    $("#filtre").append('<input type="hidden" name="type" id="type" value="'+type+'" />');
    $("#filtre").append('</form>');
}

function doFiltre(){
    var type = document.getElementById("type").value;
    var pays = document.getElementById("idpays").value;
    var ville = $("#filtreVille").val();
    $("#divResult").html("");
    $.get("/atc_user/layout/set/xml/infotour/par_"+type+"_result/id/"+pays+"/ville/"+ville, {}, function(xml) {
		//console.debug(xml);
		var compagnies = $("liste_compagnies", xml).children("compagnie");
		//console.debug(compagnies);
		$("#divResult").append("<ul>");
		$.each(compagnies, function(i,e){
		//infotour/avion_compagnie
			$("#divResult").append("<li><a href='/atc_user/infotour/"+type+"_compagnie/id/"+$(e).attr("id")+"'>"+$(e).attr("nom")+" : "+$(e).attr("site_web")+"</a></li>");
		});
		$("#divResult").append("</ul>");
//        var V = $("liste_compagnies", xml).children("villes");
//        console.debug(V);
        var villes = $("liste_compagnies", xml).children("ville");
//        console.debug(villes);
        formFiltre(villes, type, pays, ville);
	});
}

function addListeners() {
	if (player) { 
		player.addModelListener("TIME", "timeListener");
	} else {
		setTimeout("addListeners()",100);
	}
}
function timeListener(obj) {
	if(obj.position == (obj.duration-0.2)){
		player.sendEvent("PLAY",false);
	}
}

function flashPlayer(file,width, height, name , div, params, flashvars, version ) {
	
		var attributes = {id:name,  name:name}
        swfobject.embedSWF(file, div, width, height, version, false, flashvars, params, attributes);
}
	

	function deleteVideo(theWrapper, thePlaceholder, thePlayerId) { 
		swfobject.removeSWF(thePlayerId);
		var tmp=document.getElementById(theWrapper);
		if (tmp) { tmp.innerHTML = "<div id=" + thePlaceholder + "></div>"; }
	}


	
	
	
	
////////////////////////////////////////////////////////////////////////////
//*********************** Fin Flash function *****************************//
////////////////////////////////////////////////////////////////////////////


var obj = null;
	function checkHover() {
		if (obj) {
			obj.find('dl').fadeOut('fast');	
		} //if
	} //checkHover

$(document).ready(function(){
    $("#div_map").hide();


////////////////////////////////////////////////////////////////////////////
//*************************** Venir function *****************************//
////////////////////////////////////////////////////////////////////////////
	function initAffichage(){
		$("#info_type").hide();
		$(".blocType").hide();
		$("#infoTrajet").hide();
		$(".avion").hide();
		$(".bateau").hide();
		$("#rechercheTrajet").hide();
	}

	$('.testaffichage').click(function() {
			afficheType();
			return false;
			
	});

	$(function(){
		initAffichage();
		swfobject.removeSWF('player1');
		var tmp=document.getElementById('wrapper2');
	if ( $("#carteVenir").length > 0 ) {
        if (tmp) { tmp.innerHTML = '<div id="carteVenir"></div>'; }
		
		
		flashPlayer("/design/atc/flash/carte_venir.swf",493, 333, "player1" , "carteVenir", {allowfullscreen:"true", allowscriptaccess:"always",wmode:"transparent"}, {},"8" );
    }
	});
	
	$(".blocType  a, #infoTrajet a").click(function(){
		var lang ="fr";
//		var path="/design/atc/flash"
		var path="/atc_user/layout/set/xml/infotour"
			
		swfobject.removeSWF('player1');
		var tmp=document.getElementById('wrapper2');
		if (tmp) { tmp.innerHTML = '<div id="europe"><div id="carteVenir"></div></div>'; }
			
		flashPlayer("/design/atc/flash/europe.swf",281, 333, "player1" , "carteVenir",
			{
				allowfullscreen:"true", 
				allowscriptaccess:"always",
				wmode:"transparent"
			}, 
			{
				type:$(this).attr("href"),
				lang:lang,
				path:path
			}
			,"8" 
		);
	
		$('#info_type').hide();
		$('.blocType').hide();
		$("#rechercheTrajet").hide();
		$('#infoTrajet div').hide();
		$("."+$(this).attr("href")).show();
		$('.h2titre').text("Venir en Corse par "+$(this).attr("href"))
			
		//$('#ariane').html('<img src="images/pictos/ariane.gif" alt="" />  <a href="#">Accueil</a> :<a href="#">Venir</a> : <strong>Venir en Corse par '+$(this).attr("href")+'</strong>');
			
		return false;
	});

////////////////////////////////////////////////////////////////////////////
//*********************** Fin venir function *****************************//
////////////////////////////////////////////////////////////////////////////



////////////////////////////////////////////////////////////////////////////
//**************************** font function *****************************//
////////////////////////////////////////////////////////////////////////////
	var arrStyle = ["body","h1", "h2", "#menu", "#menu_lang", "div.drawer-handle"];
	$(".increaseFont").click(function(){
		var increase = 2;
		
		$.each( arrStyle, function(i, n){
			var current = $(n).css('font-size');
			var currentNum = parseFloat(current, 10);
			var newSize = currentNum+increase;
			$(n).css('font-size', newSize);
		});
		return false;
  });
	
  // Decrease Font Size
  $(".decreaseFont").click(function(){
  	var increase = 2;
   $.each( arrStyle, function(i, n){
	
		var current = $(n).css('font-size');
		var currentNum = parseFloat(current, 10);
		 var newSize = currentNum-increase;
		 $(n).css('font-size', newSize);
	});
    return false;
  });

////////////////////////////////////////////////////////////////////////////
//*********************** fin  font function *****************************//
////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////
//*************************** menus function *****************************//
////////////////////////////////////////////////////////////////////////////



	

	$('.flecheLang > img').click(function() {
		$("#menu_lang").slideDown('fast');
		
	});
	
	$('#menu_lang').hover(function() {
		
		}, function() {
		setTimeout(function() {
                $("#menu_lang").slideUp('fast')
            },500);
	});
	
	$('#Nav > li').hover(function() {
		if (obj) {
			obj.find('dl').fadeOut('fast');
			obj = null;
		} 
		
		$(this).find('dl').fadeIn('fast');
	}, function() {
		obj = $(this);
		setTimeout(
			"checkHover()",
			0);
	});
	
////////////////////////////////////////////////////////////////////////////
//************************ fin menu function *****************************//
////////////////////////////////////////////////////////////////////////////

	$(function(){ 
		$(".addCarnet").click(function(){
			if($(".addCarnet img").attr("src") == "images/pictos/ajouter.png"){
				
				$(".message").css("display", "block");
			
				$(".message").append('Lâ€™information a Ã©tÃ© rajoutÃ©e Ã  votre carnet de voyages. Vous pouvez consulter votre carnet en cliquant sur le bouton ci-dessous');
				
				
				$(".message").css("top", $(".action").offset().top - $(".message").height()-20);
				$(".message").css("left", $(".action").offset().left - $(".message").width()/2);
		
				setTimeout(function() {
							$(".message").fadeOut('fast')
						},5000);
				$(".addCarnet img").attr({ src: "images/pictos/carnet.png" });
			}else{
			
			
			}
			return false;
		})
	});
	$(function(){ 

		 $(".smallOnglet:eq(0)").addClass('on'); 
		
	}); 

	$(function(){ 
		$("#formRecherche .smallOnglet a").click(function(){ 
			$(".smallOnglet").removeClass("on");
			$(this).parent(".smallOnglet").addClass("on"); 
			$(".ongletContent").hide(); 
			$(this.hash).show(); 
			this.blur();
			return false; 
		}); 
	});

//****pour afficher cacher map des listes de resultats****//
    $(function(){
		$("#formRecherche .map a").click(function(){
            $(".blocRecherche").hide();
            $("#map").show();
			$("#div_map").show();
            showtenPoints();
			return false;
		});
	});

//****pour afficher la carte en cliquant sur l'onglet "directions"****//
    $(function(){
		$("#formRecherche a[href='#onglet7']").click(function(){
                if (typeof(coor)!='undefined') showMap(2, coor, 12, 0);
		});
	});

        $(function(){
		$("#formRecherche .moteur a").click(function(){
            $(".blocRecherche").show();
			$("#div_map").hide();
			return false;
		});
	});

   
    
	$(function(){ 
		$(".items").click(function(){
		if($(this.hash).attr("src") == "images/pictos/ajouter.png"){
			
			$(".message").css("display", "block");
		
			$(".message").text('Lâ€™information a Ã©tÃ© rajoutÃ©e Ã  votre carnet de voyages. Vous pouvez consulter votre carnet en cliquant sur le bouton ci-dessous');
			
			
			$(".message").css("top", $(this.hash).offset().top - $(".message").height()-20);
			$(".message").css("left", $(this.hash).offset().left - $(".message").width()/2);
		
			setTimeout(function() {
						$(".message").fadeOut('fast')
					},2000);
			$(this.hash).attr({ src: "images/pictos/carnet.png" });
			 return false;
		}else{
		$(this).attr({ href: "#" });
		
		}
		})
	});
	
	$(function() {
        $('.blocImage a').lightBox({
		imageLoading: '/design/atc/images/lightbox-ico-loading.gif',
		imageBtnClose: '/design/atc/images/lightbox-btn-close.gif',
		imageBlank : '/design/atc/images/lightbox-blank.gif'
	   });
    });
	
	
	$(function(){
			$('#rechercheAvance').hide();   
	$('.critere a').toggle(function(){
				$('#rechercheAvance').slideDown("fast",function(){
                    //$(".blocRecherche").backgroundCanvasPaint(blocCanvas);
                });
				$(this).css('background-position','120px -50px' );
                var more = document.getElementById("h_more");
                more.value = 1;
		}, function(){
				$('#rechercheAvance').slideUp("fast",function(){
                   // $(".blocRecherche").backgroundCanvasPaint(blocCanvas);
                });
				$(this).css('background-position','120px 10px' );
                var more = document.getElementById("h_more");
                more.value = -1;
		});
	});
	
	
	$(".infoRegion").hide();
	$("#menuAncre a").toggle(function(){
		$("#menuAncre  a").css("color", "#6a6a6a");
		$("#menuAncre span").css("color", "#fbbd1e");
		$(this).css("color", "#0063ac");
		$("#introRegion").hide();
		$(".infoRegion").hide();
		$(this.hash).show()
		 
		$("#menuAncre span").click(function(){
			$("#introRegion").show();
			$(".infoRegion").hide();
			$("#menuAncre  a").css("color", "#6a6a6a");
			$("#menuAncre span").css("color", "#0063ac");
		});
		
		$("#menuAncre span").hover(function(){
			if($("#introRegion").css("display") == "none"){
				$(this).css("text-decoration", "underline");
				$(this).css("cursor", "pointer");
			}else{
				$(this).css("text-decoration", "none");
				$(this).css("cursor", "auto");
			}
		 },function(){
			$(this).css("text-decoration", "none");
			$(this).css("cursor", "auto");
		 });
	 
	 },function(){ 
		if($(this.hash).css("display") == "none"){
			$("#menuAncre  a").css("color", "#6a6a6a");
			$("#menuAncre span").css("color", "#fbbd1e");
			$(this).css("color", "#0063ac");
			$("#introRegion").hide();
			$(".infoRegion").hide();
			$(this.hash).show()
		}else{
			$("#menuAncre span").css("color", "#0063ac");
			$("#menuAncre  a").css("color", "#6a6a6a");
			$(".infoRegion").hide();
			$("#introRegion").show();
		}
	});
	
	$(function(){ 
		$(".onglet:eq(0)").addClass('on'); 
		$("#espacePerso .onglet a").click(function(){ 
		
			$(".onglet").removeClass("on");
			
		//$(".smallOnglet").removeClass("off");
		
			$(this).parent(".onglet").addClass("on"); 
			$(".ongletContent").hide(); 
			$(this.hash).show(); 
			this.blur(); 
			return false; 
		}); 
	}); 

   // $(".ongletContent").backgroundCanvas();
	//$(".blocEspace").backgroundCanvas(); 
	//$(".blocRecherche").backgroundCanvas(); 
	//$("#sommaire .bloc").backgroundCanvas();
	
});

$(document).ready(function(){
    function initAffichage(){
		$("#info_type").hide();
		$(".blocType").hide();
		$("#infoTrajet").hide();
		$(".avion").hide();
		$(".bateau").hide();
		$("#rechercheTrajet").hide();
	}
    
    function deletePlayer(theWrapper, thePlaceholder, thePlayerId) {
        swfobject.removeSWF(thePlayerId);
        var tmp=document.getElementById(theWrapper);
        if (tmp) { tmp.innerHTML = "<div id=" + thePlaceholder + "></div>"; }
    }
    function createPlayer1(file, name , div, width) {
        var flashvars = {
            resizing:"true"
        }
        var params = {
            allowfullscreen:"true",
            allowscriptaccess:"always",
            wmode:"transparent"
        }
        var attributes = {
            id:name,
            name:name
        }
        swfobject.embedSWF("/design/atc/flash/"+file, div, width, "333", "8", false, flashvars, params, attributes);
    }
    function initPlayer1(theFile, width) {
        deletePlayer('wrapper2', 'carteVenir', 'player1');
        createPlayer1(theFile,'player1','carteVenir', width );
    }
    function createPlayer2(file, name , div) {
        fileid = file+".flv";
        imageid = file+".flv_capture";
        filename = document.getElementById(fileid).value;
        imagename = document.getElementById(imageid).value;
        var flashvars = {
            file:filename,
            image:imagename,
            resizing:"true"
        }
        var params = {
            allowfullscreen:"true",
            allowscriptaccess:"always",
            wmode:"transparent"
        }
        var attributes = {
            id:name,
            name:name
        }
        swfobject.embedSWF("/design/atc/flash/player.swf", div, "494", "328", "9.0.115", false, flashvars, params, attributes);
    }
    function initPlayer2(theFile) {
        deletePlayer('wrapper2', 'video', 'player2');
        createPlayer2(theFile,'player2','video' );
    }
});
if(!ie6){
$(window).load(function (){ 

	 DrawBackground(); 
	$(".ongletContent").not(":first").hide(); 
});
}
function DrawBackground()
{
	//$(".ongletContent").backgroundCanvasPaint(blocCanvas); 
	//$(".blocEspace").backgroundCanvasPaint(blocCanvas); 
	//$(".blocRecherche").backgroundCanvasPaint(blocCanvas);  
	//$("#sommaire .bloc").backgroundCanvasPaint(blocCanvasRound);

}

// creation des dÃ©gradÃ©s
function blocCanvasRound(context, width, height, canvas, $canvas, $canvasDiv, $content, $element )
{
		var options = {x:0, height: height, width: width, radius:5,   border: 0 };
		var backgroundGradient = context.createLinearGradient(0, 0, 0, height);
		backgroundGradient.addColorStop(0 ,'#ffffff');
		backgroundGradient.addColorStop(1, '#e9e9e9');
		context.fillStyle = "#b2b2b2";

		// Draw the blue border rectangle
		$.canvasPaint.roundedRect(context,options);

		// Draw the gradient filled inner rectangle
		options.border = 1;
		context.fillStyle = backgroundGradient;
		$.canvasPaint.roundedRect(context,options);
}
function blocCanvas(context, width, height, canvas, $canvas, $canvasDiv, $content, $element ) 
{
		var options = {x:0, height: height, width: width, radius:0, radiusBL: 5,radiusBR: 5,  border: 0 };
		var backgroundGradient = context.createLinearGradient(0, 0, 0, height);
		backgroundGradient.addColorStop(0 ,'#ffffff');
		backgroundGradient.addColorStop(1, '#e2e2e2');
		context.fillStyle = "#b2b2b2";
		
		// Draw the blue border rectangle 
		$.canvasPaint.roundedRect(context,options);
		
		// Draw the gradient filled inner rectangle
		options.border = 1;
		context.fillStyle = backgroundGradient; 
		$.canvasPaint.roundedRect(context,options);
}

// Création des arrondis des blocs
if(!ie6){
$(function() {
	//$("#F_droite h1").corner("10px top");
	$("#actualite").corner("7px");
	//$("#lang").corner("5px");
	//$("#envie .bloc").corner("7px");
	//$("#meteo").corner("7px");
	//$("#espace").corner("7px");
	//$("#search").corner("7px");
	//$(".blocRegion").corner("5px");
	$(".onglet").corner("5px top");
	$(".smallOnglet").corner("5px top");
	//$(".map").corner("5px top");
	//$(".message").corner("5px");
	//$("#sommaire .bloc").corner("5px top");
	$("#onglet1").corner("5px top");
	$("#resa").corner("7px");
	//$("#Search").corner("7px");
	$(".arrondi").corner("5px");
	$(".infoPage").corner("5px");
	$(".itemsActu").corner("5px");
	
	$(".boutonContent").corner("5px");
});
}


//Accordion menu droit
$(function () {
	$('ul.drawers').accordion({
		active: true, 
		header: 'div.drawer-handle', 
		alwaysOpen: false,
		selectedClass: 'open',
		navigation: true, 
		autoHeight: false,
		event: 'click'
	});
});

$(document).ready(
    function(){
        if($("#spanLeft").length > 0){
            $("#spanLeft").css("margin","10px");
            $("#actRight").hide();
            $("#spanLeft").html('<div id="actRight" class="action rightFloat">'+$("#actRight").html()+'</div>'+$("#spanLeft").html());
            //$("#spanLeft #actRight").css("height", $("#spanLeft").css("height"));
            debord = parseInt($("#spanLeft").css("height")) - parseInt($("#spanLeft #actRight img:first").css("height")) - 10;
            $("#spanLeft #actRight").css("padding-top",debord);
        }
});


function valider(form)
{
	var i = 0;
	var msg = "";
	var dateArrivee = form.elements['dateArrivee'].value;
	var dateDepart = form.elements['dateDepart'].value;
	var nbrpersonne = form.elements['inputNbrPersonneFormResa'].value;

	if (dateArrivee.length<2)
		{msg += "Merci de saisir une  date d\'arriv\351e. \n";i++;}

	if (dateDepart.length<2)
		{msg += "Merci de saisir une  date de d\351part. \n";i++;}

	if (nbrpersonne.length==0 || nbrpersonne==0)
		{msg += "Merci de saisir le nombre de personnes. \n";i++;}


	if (i>=1)
		{alert(msg);return false;}
	return true;
}

function validerHotel(form)
{
	var i = 0;
	var msg = "";
	var dateDebut = form.elements['dateDebut'].value;
	var dateFin = form.elements['dateFin'].value;
	var nbPers = form.elements['nbPers'].value;

	if (dateDebut.length<2)
		{msg += "Merci de saisir une  date d\'arriv\351e. \n";i++;}

	if (dateFin.length<2)
		{msg += "Merci de saisir une  date de d\351part. \n";i++;}

         
	if (nbPers.length==0)
		{msg += "Merci de saisir le nombre de personnes. \n";i++;}


	if (i>=1)
		{alert(msg);return false;}
	return true;
}

