//JS script for Joomla template
var siteurl = '';

// Added by lb
// If a div has the class "awrap" and contains exactly one link, expand the link to the whole div
function activ8awraps(){
	var awraps = $ES('div.awrap');
	// alert("Wrapping " + awraps.length + " divs with class coachintro");
	awraps.each(function(el,i){
		alinx =  $ES('a',el);
		if( alinx.length == 1) {
			// el.setStyle('background-color', '#FFFF00');
			// alert ("Link " + i + " points to " + alinx[0].href );
			var curlink = alinx[0].href;
			el.addEvent('click', function() {
				// alert('links to ' + alinx[0].href);
				document.location.href = curlink ;
			})
		};
	});
}


/* Window.onDomReady(function() { activ8awraps() } ); // Needs mootools 1.2 
Otherwise... */
window.addEvent ('load', function(e){
	var awraps = $ES('div.awrap');
	// alert("Wrapping " + awraps.length + " divs with class awrap");
	awraps.each(function(el,i){
		alinx =  $ES('a',el);
		if( alinx.length == 1) {
			// el.setStyle('background-color', '#FFFF00');
			// alert ("Link " + i + " points to " + alinx[0].href );
			var curlink = alinx[0].href;
			el.addEvent('click', function() {
				// alert('links to ' + alinx[0].href);
				document.location.href = curlink ;
			})
		};
	});
});

function fixIEPNG(el, bgimgdf, sizingMethod, type, offset){
	var objs = el;
	if(!objs) return;
	if ($type(objs) != 'array') objs = [objs];
	if(!sizingMethod) sizingMethod = 'crop';
	if(!offset) offset = 0;
	var blankimg = siteurl + 'images/blank.png';
	objs.each(function(obj) {
		var bgimg = bgimgdf;
		if (obj.tagName == 'IMG') {
			//This is an image
			if (!bgimg) bgimg = obj.src;
			if (!(/\.png$/i).test(bgimg) || (/blank\.png$/i).test(bgimg)) return;

			obj.setStyle('height',obj.offsetHeight);
			obj.setStyle('width',obj.offsetWidth);
			obj.src = blankimg;
			obj.setStyle ('visibility', 'visible');
			obj.setStyle('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+bgimg+", sizingMethod='"+sizingMethod+"')");
		}else{
			//Background
			if (!bgimg) bgimg = obj.getStyle('backgroundImage');
			var pattern = new RegExp('url\s*[\(\"\']*([^\'\"\)]*)[\'\"\)]*');
			if ((m = pattern.exec(bgimg))) bgimg = m[1];
			if (!(/\.png$/i).test(bgimg) || (/blank\.png$/i).test(bgimg)) return;
			if (!type)
			{
				obj.setStyle('background', 'none');
				//if(!obj.getStyle('position'))
				if(obj.getStyle('position')!='absolute' && obj.getStyle('position')!='relative') {
					obj.setStyle('position', 'relative');
				}

				//Get all child
				var childnodes = obj.childNodes;
				for(var j=0;j<childnodes.length;j++){
					if((child = $(childnodes[j]))) {
						if(child.getStyle('position')!='absolute' && child.getStyle('position')!='relative') {
							child.setStyle('position', 'relative');
						}
						child.setStyle('z-index',2);
					}
				}
				//Create background layer:
				var bgdiv = new Element('IMG');
				bgdiv.src = blankimg;
				bgdiv.width = obj.offsetWidth - offset;
				bgdiv.height = obj.offsetHeight - offset;
				bgdiv.setStyles({
					'position': 'absolute',
					'top': 0,
					'left': 0
				});

				bgdiv.className = 'TransBG';

				bgdiv.setStyle('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+bgimg+", sizingMethod='"+sizingMethod+"')");
				bgdiv.inject(obj, 'top');
				//alert(obj.innerHTML + '\n' + bgdiv.innerHTML);
			} else {
				obj.setStyle('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+bgimg+", sizingMethod='"+sizingMethod+"')");
			}
		}
	}.bind(this));

}

window.addEvent ('load', function(e){
	if (!$('ja-botsl2')) return;
	var divs = $ES('.moduletable',$('ja-botsl2'));
	var maxh = 0;
	divs.each(function(el, i){
		maxh < el.getStyle('height').toInt()?maxh=el.getStyle('height').toInt():'';
	});
	divs.each(function(el, i){
		el.setStyle('height', maxh);
	});
});

window.addEvent ('load', function(e){
	if (!$('panneaux')) return;
	var divs = $ES('.panneau',$('panneaux'));
	var maxh = 0;
	divs.each(function(el, i){
		maxh < el.getStyle('height').toInt()?maxh=el.getStyle('height').toInt():'';
	});
	divs.each(function(el, i){
		el.setStyle('height', maxh);
	});
});

switchFontSize=function(ckname,val){
	var bd = $E('BODY');
	switch (val) {
		case 'inc':
			if (CurrentFontSize+1 < 7) {
				bd.removeClass('fs'+CurrentFontSize);
				CurrentFontSize++;
				bd.addClass('fs'+CurrentFontSize);
			}
		break;
		case 'dec':
			if (CurrentFontSize-1 > 0) {
				bd.removeClass('fs'+CurrentFontSize);
				CurrentFontSize--;
				bd.addClass('fs'+CurrentFontSize);
			}
		break;
		default:
			bd.removeClass('fs'+CurrentFontSize);
			CurrentFontSize = val;
			bd.addClass('fs'+CurrentFontSize);
	}
	Cookie.set(ckname, CurrentFontSize,{duration:365});
}

