$j = jQuery.noConflict();
//Remplacement des polices
Cufon.replace('.rapunzel',{ fontFamily: 'Rapunzel' });
//Cufon.replace('#bloc-article-home h3',{ fontFamily: 'Rapunzel' });

$j(document).ready(function(){

	Cufon.now();
	Shadowbox.init();
		
	//smoothscroll pour les ancres plus étapes de la carto
	$j('a[href*=#]').live('click', function() {
	  //if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
		 var $target = $j(this.hash);
		 $target = $target.length && $target
		 || $j('[id=' + this.hash.slice(1) +']');
		 if ($target.length) {
		  var targetOffset = $target.offset().top;
		  $j('html,body').animate({scrollTop: targetOffset}, 1000);
		  return false;
		 }
	   //}
	});	
	
	//rollover sur le menu des routes en bas de page
	$j('#menu-routes a').hover( function () {
		$j(this).css({'opacity':'0.2'});
		$j(this).animate({ 
			opacity: 1
		  }, 1000 );
	});

	
	// initialize tooltip
	$j("#main_content img[title]").tooltip({
	
	   // tweak the position
	   position: "top right",
	   offset: [10, -40],
	   
	   // use the "slide" effect
	   effect: 'slide'
	
	});

	/**************  CARTOGRAPHIE  *******************/
	//moteur de recherche carto
	$j('.titreForm a').click( function () {
		$j('#formCircuit').slideToggle();
	});
	
    // On cache les sous-themes, et on ouvre celui qui est actif 
    $j(".formCarto div").hide(); 
	if ($j("#themes a:visible").hasClass('active')) { 
		//$j('#formCircuit').show();
		var quel = $j("#themes a:visible").attr('id'); 
		quel = quel.substring(6, quel.length); //alert(quel);
		$j("#list_"+quel).show(); 
	} else { 
		$j('#formCircuit').hide();
		$j("#themes a:first").addClass('active');
		$j("#list_1").show(); 
	}
	
	$j('#themes a').click(function () {
		$j(".formCarto div").hide(); 
		var quel = $j(this).attr('id'); 
		quel = quel.substring(6, quel.length); //alert(quel);
		$j("#list_"+quel).fadeIn(500); 
		$j("#themes a").removeClass('active');
		$j(this).addClass('active');
	});
	
	$j(".chk-pictos").click(function() //carto CIRCUITS
	{
		var idSousThem = $j(this).val();
		var idThem = $j(this).attr('rel');
		
		if($j(this).is(':checked'))
		{
			$j.ajax({
				  url: "/php/carte-interactive/ajax/add-marker-carto.ajax.php",
				  type: "POST",
				  dataType:"script",
				  data: ({idSousThem : idSousThem, idThem:idThem, idCircuit:$j('#idCircuit').val(), Itemid:$j('#Itemid').val(), idObjet:''}),
				  beforeSend :function(){$j("#loading").fadeIn(200);},
				  complete : function(){$j("#loading").fadeOut(200);}
			});
		}
		else
		{
			//alert(aMarkers.valueOf());
			removeMarkers (idSousThem);	
		}
	});

	$j(".chk-pictosSite").click(function() // carto SITES REMARQUABLES
	{
		var idSousTyp = $j(this).val();
		var idTyp = $j(this).attr('rel');
		if (premiereFois == true) { 
			removeMarkers('tous'); // on supprime tous les markers existants
			premiereFois = false; 
		}
		
		if($j(this).is(':checked'))
		{
			$j.ajax({
				  url: "/php/carte-interactive/ajax/add-marker-cartoSite.ajax.php",
				  type: "POST",
				  dataType:"script",
				  data: ({idSousTyp : idSousTyp, idTyp:idTyp, idRoute:$j('#idRoute').val(), Itemid:$j('#Itemid').val()}),
				  beforeSend :function(){$j("#loading").fadeIn(200);},
				  complete : function(){$j("#loading").fadeOut(200);}
			});
		}
		else
		{
			//alert(aMarkers.valueOf());
			removeMarkers (idSousTyp);	
		}
	});

	/****************************************************/
	
	
	//trier le tableau par colonnes (page partenaires)
	$j("#tab1").tablesorter();
	$j("#tab2").tablesorter();
	$j("#tab3").tablesorter();
	$j("#tab4").tablesorter();

});



//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); } }




