function afficherOnglet(catid) {
	$(document).ready(function(){
		var divCible =  $('#ssonglet_'+catid);
		
		var DATA = "";
		
		// Action
		DATA += "action=afficherOnglet";
		
		// catid
		DATA += "&catidOnglet="+catid;		
		
		$.ajax({
		   type: "POST",
		   url: "commun_ajax.php",
		   data: DATA,
		   beforeSend: function(data){
			  	divCible.html('');
			},
		   success: function(data){
				divCible.html(data);
		   }
		});
	});		
}

function masquerOnglet(catid) {
	$(document).ready(function(){
		var divCible =  $('#ssonglet_'+catid);
		
		divCible.html('');
	});		
}

// Début script pour le menu horizontal déroulant 

fDomOffset = function( oObj, sProp )
{
 var iVal = 0;
 while (oObj && oObj.tagName != 'BODY') {
  eval('iVal += oObj.' + sProp + ';');
  oObj = oObj.offsetParent;
 }
 return iVal;
}

fSwapSelect = function( sId ) 
{ 
 oObj = document.getElementById(sId); 
 Top_Element  = fDomOffset(oObj, 'offsetTop'); 
 Left_Element  = fDomOffset(oObj, 'offsetLeft'); 
 Largeur_Element  = oObj.offsetWidth; 
 Hauteur_Element  = oObj.offsetHeight; 
 oSelects = document.getElementsByTagName('SELECT'); 
 if (oSelects.length > 0) { 
  for (i = 0; i < oSelects.length; i++) { 
   oSlt = oSelects[i]; 
   Top_Select = fDomOffset(oSlt, 'offsetTop'); 
   Left_Select = fDomOffset(oSlt, 'offsetLeft'); 
   Largeur_Select = oSlt.offsetWidth; 
   Hauteur_Select = oSlt.offsetHeight; 
   isLeft = false; 
   if ((Left_Element > (Left_Select - Largeur_Element)) && (Left_Element < (Left_Select + Largeur_Select))) { 
    isLeft = true; 
   } 
   isTop = false; 
   if ((Top_Element > (Top_Select - Hauteur_Element)) && (Top_Element < (Top_Select + Hauteur_Select))) { 
    isTop = true; 
   } 
   if (isLeft && isTop) { 
    sVis = (oObj.style.visibility == 'hidden') ? 'visible' : 'hidden'; 
    if (oSlt.style.visibility != sVis) {oSlt.style.visibility = sVis;} 
   } else { 
    if (oSlt.style.visibility != 'visible') {oSlt.style.visibility = 'visible';} 
   } 
  } 
 } 
} 

function ferme_autres_que(ongletID) {
	var a_afficher=document.getElementById('ssonglet_'+ongletID);
	var deb=document.getElementById('onglets');
	var divs=deb.getElementsByTagName('div');
	var reg=/ssonglet_(.*)/
	for(var i=0 ; i<divs.length ;i++) {
		var div = divs[i];
		if (div.id.match(reg) && div.id != a_afficher.id) {
			var m = div.id.match(reg);
			div.style.display='none';
			document.getElementById('ongletBit_'+m[1]).className='ongletBit';
		}
	}
}


function montre(ongletID) {
	document.getElementById('ongletBit_'+ongletID).className='ongletBit_over';
	if (document.getElementById('ssonglet_'+ongletID)) {
		var reg=/MSIE 6/;
		document.getElementById('ssonglet_'+ongletID).style.display='block';
		var contenuOnglet = document.getElementById('ssonglet_'+ongletID).innerHTML;
		if (contenuOnglet.length <= 1) {
			afficherOnglet(ongletID);
		}		
		ferme_autres_que(ongletID);
		if (navigator.appVersion.match(reg)) fSwapSelect('ssonglet_'+ongletID);
	}
}



var timeoutdiv=false ;
var t = 300;
function timeoutHide(ongletID)
{
	clearTimeout(timeoutdiv);
    timeoutdiv = setTimeout("hidediv('"+ongletID+"');",t );
}

function clearTime() {
	clearTimeout(timeoutdiv);
}

function hidediv(ongletID)
{ 
	if (document.getElementById('ssonglet_'+ongletID)){
		var reg=/MSIE 6/;
		 document.getElementById('ssonglet_'+ongletID).style.display='none';
		if (navigator.appVersion.match(reg)) fSwapSelect('ssonglet_'+ongletID);
	}
}

function montre(ongletID) {
	document.getElementById('ongletBit_'+ongletID).className='ongletBit_over';
	if (document.getElementById('ssonglet_'+ongletID)) {
		var reg=/MSIE 6/;
		document.getElementById('ssonglet_'+ongletID).style.display='block';
		var contenuOnglet = document.getElementById('ssonglet_'+ongletID).innerHTML;
		if (contenuOnglet.length <= 1) {
			afficherOnglet(ongletID);
		}		
		ferme_autres_que(ongletID);
		if (navigator.appVersion.match(reg)) fSwapSelect('ssonglet_'+ongletID);
	}
}

function montrer(ongletID) {
	if(document.getElementById('ssrayon_'+ongletID)){
		document.getElementById('ssrayon_'+ongletID).style.display='block';
		var a_afficher = document.getElementById('ssrayon_'+ongletID);
		var deb = document.getElementById('onglets');
		var divs = deb.getElementsByTagName('ul');
		var reg=/ssrayon_(.*)/;
		for(var i=0 ; i<divs.length ;i++) {
			var div = divs[i];
			if (div.id.match(reg) && div.id != a_afficher.id) {
				var m = div.id.match(reg);
				div.style.display='none';
			}
		}
	}	
	
	
}

//width et height Emulé par jequery pour IE8 et tous les autres navigateurs
/* (c) Evan Roberts - 7/10/2009
www.GoWFB.com - Wholesale Furniture Brokers
Everyone is free to use/mdoify this but please keep the copyright statement!
*/
function css_emulateMaxWidthHeight() {
	$('.ongletBit_content').each(function() {		
		if( $(this).css('max-width') != 'none' || $(this).css('max-height') != 'none' ) {

			max_width = $(this).css('max-width').replace(/[^0-9]/g, '');
			max_height = $(this).css('max-height').replace(/[^0-9]/g, '');		

			if( $(this).width() > max_width || $(this).height() > max_height ) {
				if( (max_width / $(this).width()) < (max_height / $(this).height()) ) {
					$(this).css('height', Math.round($(this).height() * (max_width / $(this).width())));
					$(this).css('width', max_width);
				} else {
					$(this).css('width', Math.round($(this).width() * (max_height / $(this).height())));
					$(this).css('height', max_height);
				}

			}
		}
	});
}

$(document).ready(function() {
	css_emulateMaxWidthHeight();
});

