
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('bandeau').offsetHeight;
				contentHeight += document.getElementById('menu').offsetHeight;
				contentHeight += document.getElementById('marge_pieddepage').offsetHeight;
				
				var droiteHeight = document.getElementById('partie_droite').offsetHeight;
				var gaucheHeight = document.getElementById('partie_gauche').offsetHeight;
				if(droiteHeight > gaucheHeight) contentHeight += droiteHeight;
				else contentHeight += gaucheHeight;
				
				var footerElement = document.getElementById('pieddepage');
				var footerHeight  = footerElement.offsetHeight;
				
				if (windowHeight - (contentHeight + footerHeight) >= 0) {
					footerElement.style.position = 'absolute';
					//footerElement.style.top = (windowHeight - footerHeight) + 'px';
					footerElement.style.top = (contentHeight + footerHeight) + 'px';
				}
				else {
					footerElement.style.position = 'static';
				}
			}
		}
	}
}

// fonction ajax pour les actu
$.actualisation = 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) { $('#actu_'+id).html(c); } );
	$(elt).attr("href", "#conteneur");
}


$.fn.hoverClass = function(c) {
	return this.each(function(){
		$(this).hover( 
			function() { $(this).addClass(c);  },
			function() { $(this).removeClass(c); }
		);
	});
};

$(document).ready(function(){
	SimpleSwapSetup();
	//
	// fonction pour gérer le hover avec IE
	//
	$("#menu_rubriques li").hover(
		function(){ $("ul", this).show(); }, 
		function() { $("ul", this).hide(); } 
	);
	if (document.all) {
		$("#menu_rubriques li").hoverClass ("sfhover");
	}
});

function SimpleSwap(el,img1,img2,event) {
	if( $(el).parents('li').attr('class') != 'ui-tabs-selected' ) {
		if( event=='over' ) el.src = img2;
		else el.src = img1;
	}
}

var tabs = new Array();
function SimpleSwapSetup(){
  var x = document.getElementsByTagName("img");
  for (var i=0;i<x.length;i++){
    var oversrc = x[i].getAttribute("oversrc");
    if (!oversrc) continue;
      
    // preload image
    // comment the next two lines to disable image pre-loading
    x[i].oversrc_img = new Image();
    x[i].oversrc_img.src=oversrc;
	var img = new Object();
	img.ref = x[i];
	img.oversrc = oversrc;
	img.origsrc = x[i].getAttribute("origsrc");
	tabs.push( img );
	$(x[i]).click(function() {
		for(var j in tabs) {
			if( $(tabs[j].ref).parents('li').attr('class')=='ui-tabs-selected' ) {
				//alert( tabs[j].origsrc +' - '+ tabs[j].oversrc );
				tabs[j].ref.src = tabs[j].origsrc;
			}
		}
	});
    // set event handlers
    //x[i].onmouseover = new Function("SimpleSwap(this,'over');");
    //x[i].onmouseout = new Function("SimpleSwap(this,'out');");
    // save original src
	//for (var j in x[i]) if(j=='src' || j=='oversrc' || j=='origsrc') alert( j + " - " + x[i][j] );
    //x[i].setAttribute("origsrc",x[i].src);
  }
}
