
function geo() {
	if (!document.getElementsByTagName) // Check for browser support
			return false;
	if (rot13) // Initiate ROT13 only if needed
		var map = rot13init(); 
	var tooltip_js_on = '';
	var tooltip_js_off = '';
	var links = document.getElementsByTagName('a'); // Get all anchors
	function geo_decode(anchor) { // function to recompose the orginal address
		var href = anchor.getAttribute('href');
		if (href != null) {
			var address = href.replace(/.*contact\/([a-z0-9._%-]+)\+([a-z0-9._%-]+)\+([a-z.]+)/i, '$1' + '@' + '$2' + '.' + '$3');
			var linktext = anchor.innerHTML; // IE Fix
			if (href != address) {
				anchor.setAttribute('href','mailto:' + (rot13 ? str_rot13(address,map) : address)); // Add mailto link	
				anchor.innerHTML = linktext; // IE Fix
			}
		}
	}
	for (var l = 0 ; l < links.length ; l++) { // Loop through the anchors
		var anchor = links[l];
		var href = anchor.getAttribute('href');
		if (href != null) {
			var address = href.replace(/.*contact\/([a-z0-9._%-]+)\+([a-z0-9._%-]+)\+([a-z.]+)/i, '$1' + '@' + '$2' + '.' + '$3');
			var linktext = anchor.innerHTML; // IE Fix
			if (href != address) {
				anchor.setAttribute('href','mailto:' + (rot13 ? str_rot13(address,map) : address)); // Add mailto link	
				anchor.innerHTML = address; // IE Fix
			}	

			links[l].onclick = function() { // Encode links when clicked
				geo_decode(this);
			}
			links[l].onmouseover = function() { // Display tooltip when links are hovered
				if (this.getAttribute('title') == tooltip_js_off) { // Set custom tooltip if specified
					this.setAttribute('title',tooltip_js_on);
					geo_decode(this); // Encode links when hovered (so that the address appears correctly in the browser's status bar)
				}
			}
		}
	}
}

var rot13 = 0;

function rot13init() {
	var map = new Array();
	var s = "abcdefghijklmnopqrstuvwxyz";
	for (var i = 0 ; i < s.length ; i++)
		map[s.charAt(i)] = s.charAt((i+13)%26);
	for (var i = 0 ; i < s.length ; i++)
		map[s.charAt(i).toUpperCase()] = s.charAt((i+13)%26).toUpperCase();
	return map;
}

function str_rot13(a,map) {
	var s = "";
	for (var i = 0 ; i < a.length ; i++) {
		var b = a.charAt(i);
		s += (b>='A' && b<='Z' || b>='a' && b<='z' ? map[b] : b);
	}
	return s;
}


function controlValueOnFocus(control) {
	c = $(control);
	if (c.val() == c.defaultValue) {
		c.val() = '';
	}
}

function controlValueOnBlur(control) {
	if (control.value == '') {
		control.value = control.defaultValue;
	}
}

function submitSearch() {
	if ( (document.search.term.value != 'Rechercher...') && (document.search.term.value !='Search...') ) {
		document.search.submit();
	}
}

/*
window.addEvent('domready', function(){
	geo();

	$$('input.text').each(function(el){
		el.onfocus = function() {
			controlValueOnFocus(this);
		},
		el.onblur = function() {
			controlValueOnBlur(this);
		}
	});
});
*/

function submitForm( id ) {
	form = $('#' + id + ' form');
	if (form) {
		var options = { target: '#' + id };
		form.ajaxSubmit(options);
	}
}

function control() {
	if ( (page_id == '/accueil') || (page_id == 'accueil') ) {
		$('#bottom_1').css('background-position', '-227px -252px' );
	}
	if (page_id == 'historique') {
		$('#bottom_2').css('background-position', '-225px -252px' );
	}
	if (page_id == 'chauffage') {
		$('#bottom_3').css('background-position', '-215px -252px' );
		$('#top_3').css('background-position', '-215px -147px' );
	}
	if (page_id == 'commercial') {
		$('#bottom_5').css('background-position', '-348px -252px' );
		$('#top_5').css('background-position', '-348px -147px' );
	}
	if (page_id == 'cardlock') {
		$('#bottom_5').css('background-position', '-348px -252px' );
		$('#top_5').css('background-position', '-348px -147px' );
	}
	if (page_id == 'lubrifiants') {
		$('#bottom_6').css('background-position', '-453px -252px' );
		$('#top_6').css('background-position', '-458px -147px' );
	}
	if (page_id == 'stations') {
		$('#bottom_7').css('background-position', '-618px -252px' );
		$('#top_7').css('background-position', '-618px -147px' );
	}
}


$(document).ready(function(){
	/* Decrypt mails */
	geo();
	control();
	
	$('a.lightbox').lightBox();
	
	$('#menu-1').mouseover(function() {
		$('#bottom_1').css('background-position', '-227px -252px' );
		control(); });
	$('#menu-2').mouseover(function() {
		$('#bottom_2').css('background-position', '-225px -252px' );
		control(); });
	$('#menu-3').mouseover(function() {
		$('#bottom_3').css('background-position', '-215px -252px' );
		$('#top_3').css('background-position', '-215px -147px' ); control(); });
	$('#menu-4').mouseover(function() {
		$('#bottom_5').css('background-position', '-348px -252px' );
		$('#top_5').css('background-position', '-348px -147px' ); control(); });
	$('#menu-5').mouseover(function() {
		$('#bottom_5').css('background-position', '-348px -252px' );
		$('#top_5').css('background-position', '-348px -147px' ); control(); });
	$('#menu-6').mouseover(function() {
		$('#bottom_6').css('background-position', '-453px -252px' );
		$('#top_6').css('background-position', '-458px -147px' ); control(); });
	$('#menu-7').mouseover(function() {
		$('#bottom_7').css('background-position', '-618px -252px' );
		$('#top_7').css('background-position', '-618px -147px' ); control(); });

	$('#menu-1').mouseout(function() {
		$('#bottom_1').css('background-position', '-227px -105px' );
		control(); });
	$('#menu-2').mouseout(function() {
		$('#bottom_2').css('background-position', '-225px -105px' );
		control(); });
	$('#menu-3').mouseout( function() {
		$('#bottom_3').css('background-position', '-215px -105px' );
		$('#top_3').css('background-position', '-215px 0px'    ); control(); });
	$('#menu-4').mouseout( function() { 
		$('#bottom_5').css('background-position', '-348px -105px' );
		$('#top_5').css('background-position', '-348px 0px'    ); control(); });
	$('#menu-5').mouseout( function() { 
		$('#bottom_5').css('background-position', '-348px -105px' );
		$('#top_5').css('background-position', '-348px 0px'    ); control(); });
	$('#menu-6').mouseout( function() { 
		$('#bottom_6').css('background-position', '-453px -105px' );
		$('#top_6').css('background-position', '-458px 0px'    ); control(); });
	$('#menu-7').mouseout( function() { 
		$('#bottom_7').css('background-position', '-618px -105px' );
		$('#top_7').css('background-position', '-618px 0px'    ); control(); });
	

});


