
	/*############### GENERIK & HACKS ###############*/

	/* Copyright Robert Nyman, http://www.robertnyman.com (little change by Clément Noterdaem - form-at.be)
	 ex: elements = getElementsByAttribute(document.body, "*", "id");
	*/
	document.getElementsByAttribute = function(oElm, strTagName, strAttributeName, strAttributeValue) {
		if (!document.getElementsByAttribute) { return new Array(); }
		var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
	    var arrReturnElements = new Array();
	    var oAttributeValue = (typeof strAttributeValue != "undefined")? new RegExp("(^|\\s)" + strAttributeValue + "(\\s|$)") : null;
	    var oCurrent;
	    var oAttribute;
	    for(var i=0; i<arrElements.length; i++){
	        oCurrent = arrElements[i];
	        oAttribute = oCurrent.getAttribute(strAttributeName);
	        if(typeof oAttribute == "string" && oAttribute.length > 0){
	            if(typeof strAttributeValue == "undefined" || (oAttributeValue && oAttributeValue.test(oAttribute))){
	                arrReturnElements.push(oCurrent);
	            }
	        }
	    }
	    return arrReturnElements;
	}
		
	/* If needed:
	 http://simon.incutio.com/archive/2003/03/25/getElementsBySelector 
	*/

	/*var titlelements = document.getElementsByAttribute(document.body, "*", "title");
	for (var i=0; i<titlelements.length; i++) {
		var curtitle = titlelements[i].getAttribute("title");
		alert(curtitle);
	}*/
	
	/*############### VARS ##########################*/
	
	var kalert_showing = 0;
	var kalert_showing_time;
	var kalert_closing_time;
	var spoilers = [];
	var leadImgTimeout;
	var switchbuffertime;
	var togglebuffertime;
	
	/*############### FUNCTIONALITIES ###############*/
	
	function Disappear(element_id, FXduration) {
		if (!FXduration) var FXduration = 2.0;
		new Effect.Parallel(
			[ new Effect.SlideUp(element_id, {sync:true}), 
			  new Effect.Fade(element_id, {sync:true}) ], 
			{ duration: FXduration }
		);
	}
	function Appear(element_id, FXduration, FXtransparancy) {
		if (!FXduration) var FXduration = 2.0;
		if (!FXtransparancy) var FXtransparancy = 0.8;
		new Effect.Parallel(
			[ new Effect.SlideDown(element_id, {sync:true}), 
			  new Effect.Appear(element_id, {sync:true, from:0.0, to:FXtransparancy}) ], 
			{ duration:FXduration }
		);
	}
	function BlindAppear(element_id, FXduration, FXtransparancy) {
		if (!$(element_id)) return false;
		$(element_id).style.display = 'none';
		window.setTimeout("$('"+element_id+"').style.display='block'", 5000);
		if (!FXduration) var FXduration = 0.7;
		if (!FXtransparancy) var FXtransparancy = 1.0;
		new Effect.Appear(element_id, {from:0.0, to:FXtransparancy, duration:FXduration});
	}
	function kalert(msg, bgstyle) {
		/*if (!$("kmsg")) {
			var oBody = document.getElementsByTagName("body").item(0);
			var oKmsg = document.createElement("div");
			oKmsg.setAttribute('id', 'kmsg');
			oKmsg.style.display = 'none';
			oKmsg.onclick = function() { kalert_close(1); return false; }
			oKmsg.onmouseover = function() { Element.setOpacity(this.id, 1.0); return false; }
			oKmsg.onmouseout = function() { Element.setOpacity(this.id, 0.8); return false; }
			oBody.appendChild(oKmsg);
		}*/
		if (!$("kmsg")) return false;
		if (kalert_showing && kalert_showing==1) { window.setTimeout("kalert('"+msg+"', '"+bgstyle+"');", 500); return false; }
		kalert_showing = 1;
		if (kalert_showing_time) clearTimeout(kalert_showing_time);
		if (kalert_closing_time) clearTimeout(kalert_closing_time);
		if (msg) $("kmsg").innerHTML = '<div>'+msg+'</div>';
		if (bgstyle) $("kmsg").style.background = bgstyle;
		Appear("kmsg");
		kalert_closing_time = window.setTimeout("kalert_close()", 8000);
		kalert_showing_time = window.setTimeout("kalert_showing=0", 2100);
	}
	function kalert_close() {
		if (!$("kmsg")) return false;
		if (kalert_showing && kalert_showing==1) { window.setTimeout("kalert_close();", 500); return false; }
		kalert_showing = 1;
		if (kalert_showing_time) clearTimeout(kalert_showing_time);
		if (kalert_closing_time) clearTimeout(kalert_closing_time);
		new Effect.Highlight('kmsg');
		Disappear('kmsg');
		kalert_showing_time = window.setTimeout("kalert_showing=0", 2100);
	}
	function leadImgHover(el, text, num) {
		if (!num) num = 0;
		if (leadImgTimeout) clearTimeout(leadImgTimeout);
		if (switchbuffertime) clearTimeout(switchbuffertime);
		var hp_lead_img = document.getElementsByClassName("hp_lead_img");
		for (var i=0; i<hp_lead_img.length; i++) {
			if (hp_lead_img[i].id == el) Element.setOpacity(hp_lead_img[i].id, 1);
			else Element.setOpacity(hp_lead_img[i].id, 0.5);
		}
		var posoffsets = Position.cumulativeOffset($(el));
		var story_pos = Position.cumulativeOffset($('hp_lead_story'));
		$('hp_lead_story').innerHTML = '<p>'+text+'</p>';
		var queue = Effect.Queues.get('hp_lead_story_queue');
		queue.each(function(e){e.cancel()});
		new Effect.Move($('hp_lead_story'), {x:((num*153)), y:0, mode:'absolute', duration:1, queue: {position:'end', scope:'hp_lead_story_queue', limit:2} });
		toggleRounded('hide', num);
	}
	function leadImgOut(el, num, status) {
		if (status && status=='timeout') {
			if (hplead_firstintrotext) $('hp_lead_story').innerHTML = '<p>'+hplead_firstintrotext+'</p>';
			var hp_lead_img = document.getElementsByClassName("hp_lead_img");
			for (var i=0; i<hp_lead_img.length; i++) {
				Element.setOpacity(hp_lead_img[i].id, 1);
			}
		} else {
			leadImgTimeout = setTimeout("leadImgOut('"+el+"', "+num+", 'timeout')", 3000);
		}
		switchbuffertime = setTimeout("toggleRounded('show', "+num+"); new Effect.Move($('hp_lead_story'), {x:0, y:0, mode:'absolute', duration:1});", 600);
	}
	function rate(rating) {
		if (!rating) return false;
		rating = parseInt(rating, 10);
		if (rating<0 || rating>5) return false;
		if (!$("rating")) return false;
		document.forms["akocommentform"].elements["user_rating"].value = rating;
		if ($("current_rating")) $("current_rating").style.width = (rating*14)+'px';
	}
	function showSpoiler(element) {
		if (!element || !element.nextSibling) return false;
		spoiler_content_id = element.nextSibling.id;
		if (!spoilers[spoiler_content_id] || spoilers[spoiler_content_id]==0) {
			var confirmspoiler = confirm('Etes-vous vraiment sûr de vouloir lire ce spoiler? ;-)');
			if (confirmspoiler) {
				Appear(spoiler_content_id, 1.0, 1.0);
				spoilers[spoiler_content_id] = 1;
			}
		} else {
			Disappear(spoiler_content_id);
			spoilers[spoiler_content_id] = 0;
		}
	}
	function showRounded(el_id) {
		if (el_id) {
			if ($(el_id) && $(el_id).firstChild.firstChild.firstChild.className == 'roundedOverlay') {
				$(el_id).firstChild.firstChild.firstChild.style.display = 'block';
			}
		} else {
			var roundedelements = document.getElementsByClassName("rounded_tiny_white");
			for (var i=0; i<roundedelements.length; i++) {
				var roundedDiv = document.createElement("div");
				roundedDiv.style.position = 'relative';
				roundedDiv.style.display = 'block';
				roundedDiv.style.width = roundedelements[i].offsetWidth+'px';
				roundedDiv.style.zIndex = 75;
				roundedelements[i].parentNode.insertBefore(roundedDiv, roundedelements[i]);
				
				var roundedOverlay = document.createElement("div");
				roundedOverlay.setAttribute('id', 'roundedOverlay'+i);
				roundedOverlay.className = 'roundedOverlay';
				roundedOverlay.style.display = 'block';
				roundedOverlay.style.position = 'absolute';
				roundedOverlay.style.width = roundedelements[i].offsetWidth+'px';
				roundedOverlay.style.height = roundedelements[i].offsetHeight+'px';
				roundedOverlay.style.background = 'url(images/br_tiny_white.gif) no-repeat right bottom';
				roundedOverlay.style.zIndex = 76;
				roundedDiv.appendChild(roundedOverlay);
				
				var roundedTopRight = document.createElement("div");
				roundedTopRight.style.width = roundedelements[i].offsetWidth+'px';
				roundedTopRight.style.height = '4px';
				roundedTopRight.style.background = 'url(images/tr_tiny_white.gif) no-repeat right top';
				roundedTopRight.style.zIndex = 77;
				roundedOverlay.appendChild(roundedTopRight);
				
				var roundedBottomLeft = document.createElement("div");
				roundedBottomLeft.style.width = '4px';
				roundedBottomLeft.style.height = roundedelements[i].offsetHeight+'px';
				roundedBottomLeft.style.background = 'url(images/bl_tiny_white.gif) no-repeat left bottom';
				roundedBottomLeft.style.zIndex = 78;
				roundedTopRight.appendChild(roundedBottomLeft);
				
				var roundedTopLeft = document.createElement("div");
				roundedTopLeft.style.width = '4px';
				roundedTopLeft.style.height = '4px';
				roundedTopLeft.style.background = 'url(images/tl_tiny_white.gif) no-repeat 0 0';
				roundedTopLeft.style.zIndex = 79;
				roundedBottomLeft.appendChild(roundedTopLeft);
			}
		}
	}
	function hideRounded(el_id) {
		if ($(el_id) && $(el_id).firstChild.firstChild.firstChild.className == 'roundedOverlay') {
			$(el_id).firstChild.firstChild.firstChild.style.display = 'none';
		}
	}
	function hoverLinks(el) {
		var links = el.getElementsByTagName('a');
		for (var i=0; i<links.length; i++) {
			links[i].style.textDecoration = 'underline';
			if (links[i].firstChild && links[i].firstChild && links[i].firstChild.tagName == 'IMG') links[i].firstChild.style.border = '1px solid #38699C';
			if (links[i].firstChild && links[i].firstChild.firstChild && links[i].firstChild.firstChild.tagName == 'IMG') {
				links[i].firstChild.style.border = 'none';
				links[i].firstChild.firstChild.style.border = '1px solid #38699C';
			}
		}
	}
	function unhoverLinks(el) {
		var links = el.getElementsByTagName('a');
		for (var i=0; i<links.length; i++) {
			links[i].style.textDecoration = 'none';
			if (links[i].firstChild && links[i].firstChild.tagName == 'IMG') links[i].firstChild.style.border = '1px solid white';
			if (links[i].firstChild && links[i].firstChild.firstChild && links[i].firstChild.firstChild.tagName == 'IMG') {
				links[i].firstChild.style.border = 'none';
				links[i].firstChild.firstChild.style.border = '1px solid white';
			}
		}
	}
	function hoverLinkClick(el) {
		var links = el.getElementsByTagName('a');
		document.location.href = links[0];
	}
	function tab(num) {
		var el = 'hp_tab_content_'+num;
		if (!$(el)) return false;
		for (a=0; a<4; a++) {
			if ($('hp_tab_'+a)) {
				$('hp_tab_'+a).className = 'none';
			}
		}
		var tabs = document.getElementsByTagName('div');
		for (var i=0; i<tabs.length; i++) {
			if (/_tab_content_/.test(tabs[i].id)) {
				var thisplay = Element.getStyle(tabs[i], 'display');
				if (thisplay != 'none') {
					tabs[i].style.display = 'none';
				}
				if (tabs[i].id == el) {
					tabs[i].style.display = 'inline';
					$('hp_tab_'+num).className = 'tab_active';
				}
			}
		}
	}
	function updateSort(el) {
		if (!$(el.id)) return false;
		$('input_'+el.id).value = Sortable.serialize(el.id);
	}
	function submitExpress() {
		if (document.forms['kid_form_express']) {
			new Ajax.Updater('kid_express', 'kid.php', {method:'post', parameters:Form.serialize(document.forms['kid_form_express']), onComplete:function(){kalert('Merci, réponse enregistrée ;-)', 'green');}});
		}
	}
