$j = jQuery.noConflict();

//Remplacement des polices
Cufon.replace('.AvenirLT',{ fontFamily: 'Avenir LT 55 Roman' });
Cufon.replace('#menu-principal li a',{ fontFamily: 'Avenir LT 95 Black', fontWeight: 'normal' });
Cufon.replace('#menu-principal ul li a',{ fontFamily: 'Avenir LT 85 Heavy', fontWeight: 'normal' });
Cufon.replace('#resa span',{ fontFamily: 'Avenir LT 95 Black', fontWeight: 'normal' });
Cufon.replace('.home .portail .colPrincipale h1',{ fontFamily: 'Avenir LT 85 Heavy', fontWeight: 'normal' });
Cufon.replace('.home .valcenis .colPrincipale h1',{ fontFamily: 'Avenir LT 65 Medium', fontWeight: 'normal' });
Cufon.replace('.home .termignon .colPrincipale h1',{ fontFamily: 'Avenir LT 65 Medium', fontWeight: 'normal' });
Cufon.replace('.home .aussois .colPrincipale h1',{ fontFamily: 'Avenir LT 65 Medium', fontWeight: 'normal' });
Cufon.replace('.interieur .colPrincipale h1.componentheading',{ fontFamily: 'Avenir LT 35 Light', fontWeight: 'normal' });
Cufon.replace('.interieur .colPrincipale h1',{ fontFamily: 'Avenir LT 35 Light', fontWeight: 'normal' });
Cufon.replace('.interieur .colPrincipale h2',{ fontFamily: 'Avenir LT 55 Roman', fontWeight: 'normal' });
Cufon.replace('.contentpane_chapo h3',{ fontFamily: 'Avenir LT 95 Black', fontWeight: 'normal' });
Cufon.replace('.colD h3',{ fontFamily: 'Avenir LT 65 Medium', fontWeight: 'normal' });
Cufon.replace('.blocD a',{ fontFamily: 'Avenir LT 35 Light', fontWeight: 'normal' });
Cufon.replace('#article-home h3',{ fontFamily: 'Avenir LT 65 Medium', fontWeight: 'normal' });


Shadowbox.init();
$j(document).ready(function(){
	Cufon.now();
	

	
	/*  MENU PRINCIPAL  */
	$j('#menu-principal').superfish({ 
				delay:       500,                            // one second delay on mouseout 
				animation:   {height:'show'},  				// fade-in and slide-down animation 
				speed:       'fast',                          // faster animation speed 
				autoArrows:  false,                           // disable generation of arrow mark-up 
				dropShadows: false                            // disable drop shadows 
	});
	
    // On empêche le navigateur de suivre le lien sur les rubriques : 
    $j(".item65 > a").click( function () { return false; }); 
    $j(".item66 > a").click( function () { return false; }); 
    $j(".item67 > a").click( function () { return false; }); 
    $j(".item68 > a").click( function () { return false; }); 
    $j(".item69 > a").click( function () { return false; }); 
    $j(".item70 > a").click( function () { return false; }); 

    $j(".item229 > a").click( function () { return false; }); 
    $j(".item235 > a").click( function () { return false; }); 
    $j(".item258 > a").click( function () { return false; }); 
    $j(".item259 > a").click( function () { return false; }); 
    $j(".item260 > a").click( function () { return false; }); 
    $j(".item261 > a").click( function () { return false; }); 

    $j(".item182 > a").click( function () { return false; }); 
    $j(".item192 > a").click( function () { return false; }); 
    $j(".item215 > a").click( function () { return false; }); 
    $j(".item216 > a").click( function () { return false; }); 
    $j(".item217 > a").click( function () { return false; }); 
    $j(".item218 > a").click( function () { return false; }); 

    $j(".item139 > a").click( function () { return false; }); 
    $j(".item149 > a").click( function () { return false; }); 
    $j(".item172 > a").click( function () { return false; }); 
    $j(".item173 > a").click( function () { return false; }); 
    $j(".item174 > a").click( function () { return false; }); 
    $j(".item175 > a").click( function () { return false; }); 

	/* shadowbox visite virtuelle */
	//bonheur des pistes
	$j('.item148 a').attr('rel','lightbox;width=788;height=578');	
	$j('.item148 a').attr('target','_blank');
	$j('.item127 a').attr('rel','lightbox;width=788;height=578');
	$j('.item127 a').attr('target','_blank');
	//la combe
	$j('.item266 a').attr('rel','lightbox;width=425;height=494');
	$j('.item266 a').attr('target','_blank');
	$j('.item128 a').attr('rel','lightbox;width=425;height=494');
	$j('.item128 a').attr('target','_blank');
	//les sports
	$j('.item280 a').attr('rel','lightbox;width=740;height=550');
	$j('.item280 a').attr('target','_blank');
	$j('.item281 a').attr('rel','lightbox;width=740;height=550');
	$j('.item281 a').attr('target','_blank');


	/*  ACTUALITES  */
	//$j("div.latestnews").codaSlider()
	var actus_i = 0; 

	$j("#actustotal").html($j("#sliderActus .leading").length); 

	$j("#actusright").click(function (i) 
	{ 
			if(actus_i >= $j("#sliderActus .leading").length - 1)
			   actus_i = 0; 
			else
			  actus_i++; 
			crawlleading("sliderActus", actus_i); 
			return false; 
	}); 

	 $j("#actusleft").click(function (i) 
	 { 
			if(actus_i <= 0 )
			  actus_i = $j("#sliderActus .leading").length - 1; 
			else
			  actus_i--;
			crawlleading("sliderActus", actus_i); 
			return false; 
	}); 

	//defilement des actualités....   
	var nb = $j('#sliderActus .leading').length;
	if ( nb > 1 ) 
	{
		setInterval( "slideSwitch()", 6000 );
	}



	/*  FORMULAIRE DE RESERVATION  */
	//requetes ajax combobox
	$j('#opti_debut').change(function() {
		$j.ajax({
		 type: "GET",
		 url: "/php/ajax/affStation.php",
		 data: {opti_debut: $j('#opti_debut').val(), 
				opti_fin: $j('#opti_fin').val(),
				pers: $j('#pers').val(),
				lang: $j('#lang').val()
				},
		 beforeSend :function(){$j("#loading").fadeIn(200);},
		 success: function(data){
		   $j('#lieu').html(data);
		   $j('#opti_fin').removeAttr('disabled');
		   $j('#pers').removeAttr('disabled');
		   $j('#lieu').removeAttr('disabled');
		   //alert(data);
		 },
		 complete : function(){$j("#loading").fadeOut(200);}
		});
	});
	
	$j('#opti_fin').change(function() {
		$j.ajax({
		 type: "GET",
		 url: "/php/ajax/affStation.php",
		 data: {opti_debut: $j('#opti_debut').val(), 
				opti_fin: $j('#opti_fin').val(),
				pers: $j('#pers').val(),
				lang: $j('#lang').val()
				},
		 beforeSend :function(){$j("#loading").fadeIn(200);},
		 success: function(data){$j('#lieu').html(data);},
		 complete : function(){$j("#loading").fadeOut(200);}
		});
	});

	$j('#pers').change(function() {
		$j.ajax({
		 type: "GET",
		 url: "/php/ajax/affStation.php",
		 data: {opti_debut: $j('#opti_debut').val(), 
				opti_fin: $j('#opti_fin').val(),
				pers: $j('#pers').val(),
				lang: $j('#lang').val()
				},
		 beforeSend :function(){$j("#loading").fadeIn(200);},
		 success: function(data){$j('#lieu').html(data);},
		 complete : function(){$j("#loading").fadeOut(200);}
		});
	});

 	$j(".cf_datetime").datepicker();



});

	//fonction slider actualités
	function crawlleading(obj, compteur)
	{
		$j("#" + obj).css("display", "none");
		$j("#" + obj + " .leading").each(function (i) 
		{ 
		  if(i == compteur) 
			{ 
			  $j(this).attr("class", "leading active actu");
			  $j("#actusactive").html(compteur + 1); 
			}else
			{
			  $j(this).attr("class", "leading actu");
			}
		});
		$j("#" + obj).css("display", "block");
	}
	
	//Actualités défilantes
	function slideSwitch() {
		var $active = $j('#sliderActus .active');
		//alert($active.attr('id'));
		
		if ( $active.length == 0 ) $active = $j('#sliderActus  .leading:last');
	
		var $next =  $active.next().length ? $active.next() : $j('#sliderActus .leading:first');
		var quel = $next.attr('id').substring(5, $next.attr('id').length); //alert (quel);
	
		$active.addClass('last-active');
	
		$next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 700, function() {
				$active.removeClass('active last-active');
			});
		
		$j("#actusactive").html(quel); 
	
	}

//Boite a outils (taille des carcteres, favoris)
var prefsLoaded = false;
var defaultFontSize =100;
var currentFontSize = defaultFontSize;

function revertStyles(){

	currentFontSize = defaultFontSize;
	changeFontSize(0);

}

function toggleColors(){
	if(currentStyle == "White"){
		setColor("Black");
	}else{
		setColor("White");
	}
}

function changeFontSize(sizeDifference){
	currentFontSize = parseInt(currentFontSize) + parseInt(sizeDifference * 5);

	if(currentFontSize > 220){
		currentFontSize = 220;
	}else if(currentFontSize < 60){
		currentFontSize = 60;
	}

	setFontSize(currentFontSize);
};

function setFontSize(fontSize){
	var stObj = (document.getElementById) ? document.getElementById('main') : document.all('main');
	if(document.getElementById('main') != undefined) document.getElementById('main').style.fontSize = fontSize + '%';

	//alert (document.body.style.fontSize);
};


function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
};

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
};

window.onload = setUserOptions;

function setUserOptions(){
	if(!prefsLoaded){

		cookie = readCookie("fontSize");
		currentFontSize = cookie ? cookie : defaultFontSize;
		setFontSize(currentFontSize);

		prefsLoaded = true;
	}

}

window.onunload = saveSettings;

function saveSettings()
{
  createCookie("fontSize", currentFontSize, 365);
}
function favoris(url, title) {
if ( navigator.appName != 'Microsoft Internet Explorer' )
{ window.sidebar.addPanel(title,url,""); }
else { window.external.AddFavorite(url,title); } }
