
function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function setFooter() {
	if (document.getElementById) {
		var windowHeight = getWindowHeight();
		var elt = document.getElementById('pieddepage');
		if (elt != null) {
			if (windowHeight > 0) {
				var contentHeight = document.getElementById('entete').offsetHeight;
				contentHeight += document.getElementById('contenant').offsetHeight;
				contentHeight += document.getElementById('marge_pieddepage').offsetHeight;
				
				var footerElement = document.getElementById('pieddepage');
				var footerHeight  = footerElement.offsetHeight;

				if (windowHeight - (contentHeight + footerHeight) >= 0) {
					footerElement.style.position = 'absolute';
					footerElement.style.top = (windowHeight - footerHeight) + 'px';
				}
				else {
					footerElement.style.position = 'static';
				}
			}
		}
	}
}

//
// fonction ajax pour les actu
//
$.ajax_actualites = function(elt, debut, id) {
	if($.browser.msie && $.browser.version>=6 && $.browser.version<7 ) setFooter();
	$.get(elt.href, { debut_page:debut, id_rubrique:id }, function (c) { $('#actualites').html(c); } );
	$(elt).attr("href", "#conteneur");
}

//
// fonction ajax pour la recherche de produits
//
$.ajax_produits = function(elt) {
	if($.browser.msie && $.browser.version>=6 && $.browser.version<7 ) setFooter();

	// :input is a macro that grabs all input types, select boxes
	// textarea, etc.
	var inputs = [];
	$(':input', elt).each(function() {
		inputs.push(this.name + '=' + escape(this.value));
	})
	
	// now if I join our inputs using '&' we'll have a query string
	jQuery.ajax({
		data: inputs.join('&'),
		url: elt.action,
		timeout: 2000,
		error: function() {
			console.log("Failed to submit");
		},
		success: function(c) { 
			$('#grandbloc_recherche_resultats').html(c);
		}
	})
	
}

$.fn.hoverClass = function(c) {
	return this.each(function(){
		$(this).hover( 
			function() { $(this).addClass(c);  },
			function() { $(this).removeClass(c); }
		);
	});
};

//
// ouvre la démo à partir d'un autre lien
//
function openDemo () {
	$('a.thickbox').eq(0).click();
	return false;
}

//
// fonction Google Analytics
//
var pageTracker = _gat._getTracker("UA-151331-1");
pageTracker._initData();
pageTracker._trackPageview();




$(document).ready(function(){
	//
	// fonction pour gérer le hover avec IE
	//
	$("#menu_bas_liste li").hover(
		function(){ $("ul", this).show(); }, 
		function() { $("ul", this).hide(); } 
	);
	if (document.all) {
		$("#menu_bas_liste li").hoverClass ("sfhover");
	}
	$("#menu_haut_liste li").hover(
		function(){ $("ul", this).show(); }, 
		function() { $("ul", this).hide(); } 
	);
	if (document.all) {
		$("#menu_haut_liste li").hoverClass ("sfhover");
	}
	//
	// pour le sitemap
	//
	$("#sitemap a").each(function(i){
		var nb_ul = $("ul", $(this).parent()).length;
		if( nb_ul > 0 ) {
			var ul = $("ul", $(this).parent());
			$(this).parent().append('<span></span>');
			var span = $("span", $(this).parent());
			span.addClass("collapsed");
			span.click(function(){
				ul.toggle();
				span.toggleClass("collapsed");
				span.toggleClass("expanded");
				if($.browser.msie && $.browser.version>=6 && $.browser.version<7 ) setFooter();
			});
		}
	});
	
});


function closeMap () {
	$("#sitemap ul").each(function(i){
		$(this).hide();
	});
	$("#sitemap li span").each(function(i){
		$(this).attr("class", "collapsed");
	});
	if($.browser.msie && $.browser.version>=6 && $.browser.version<7 ) setFooter();
}
function openMap () {
	$("#sitemap ul").each(function(i){
		$(this).show();
	});
	$("#sitemap li span").each(function(i){
		$(this).attr("class", "expanded");
	});
	if($.browser.msie && $.browser.version>=6 && $.browser.version<7 ) setFooter();
}