// Dean Edwards/Matthias Miller/John Resig
var called = 0;
function init() {
	// quit if this function has already been called
	if (arguments.callee.done) {
		
		var d = document;
		var b = d.getElementById("body");
		var images = b.getElementsByTagName("img");
		for (var i=0; i<images.length; i++) {
			var img = images[i];
			roundImage(img);
		}		
		return;
	}

	// flag this function so we don't do the same thing twice
	arguments.callee.done = true;

	// kill the timer
	if (_timer) clearInterval(_timer);

	// do stuff	
	mailtos();
	attencion();
	if (this.ie) {
		if (document.body.clientWidth < 1000) {
			var important = document.getElementById("important");
			important.style.display = "none";
		}
		window.onscroll = function() {
			document.getElementById("important").style.top = document.documentElement.scrollTop + (document.documentElement.clientHeight - 242) + "px";
		}
	}
	//document.body.style.display = "none";
	//document.body.style.display = "";
};

/* for Mozilla/Opera9 */
if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", init, false);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
	this.ie = 1;
	document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
	var script = document.getElementById("__ie_onload");
	script.onreadystatechange = function() {
		if (this.readyState == "complete") {
			init(); // call the onload handler
		}
	};
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
	var _timer = setInterval(function() {
		if (/loaded|complete/.test(document.readyState)) {
			init(); // call the onload handler
		}
	}, 10);
}

/* for other browsers */
window.onload = init;


// JavaScript Document
function getElementsByClassName(clsName) 
{ 
	var arr = new Array(); 
	var elems = document.getElementsByTagName("*");
	var elem;
	for ( var cls, i = 0; ( elem = elems[i] ); i++ )
	{
		if ( elem.className == clsName )
		{
			arr[arr.length] = elem;
		}
	}
	return arr;
}

function roundImage(img) {
	var d = document;
	//var img = this;
	if (img.alt != "Captcha" && img.className.indexOf("notRound") == -1) {
		var parent = img.parentNode;
		//
		var roundImage = d.createElement("span");
		roundImage.className = "roundImage " + img.className;
		roundImage.style.width = img.width + "px";
		roundImage.style.height = img.height + "px";
		//
		var tl = d.createElement("span");
		tl.className = "corner_tl";
		tl.style.backgroundColor = "transparent";
		//
		var tr = d.createElement("span");
		tr.className = "corner_tr";
		//
		var br = d.createElement("span");
		br.className = "corner_br";
		//
		var bl = d.createElement("span");
		bl.className = "corner_bl";
		
		var tmp = img.cloneNode(true);
		
		roundImage.appendChild(tmp);
		br.appendChild(bl);
		tr.appendChild(br);
		tl.appendChild(tr);
		roundImage.appendChild(tl);
		
		parent.replaceChild(roundImage, img);	
		
		/*
		var roundImage = document.createElement("span");
		roundImage.className = "roundImage " + img.className;
		roundImage.style.width = img.width + "px";
		roundImage.style.height = img.height + "px";
		
		var top = document.createElement("span");
		top.className = "top";
		var bottom = document.createElement("span");
		bottom.className = "bottom";
		
		var b1 = document.createElement("b");
		b1.className = "b1";
		var b2 = document.createElement("b");
		b2.className = "b2";
		var b3 = document.createElement("b");
		b3.className = "b3";
		var b4 = document.createElement("b");
		b4.className = "b4";
		var b5 = document.createElement("b");
		b5.className = "b5";
		
		top.appendChild(b1);
		top.appendChild(b2);
		top.appendChild(b3);
		top.appendChild(b4);
		top.appendChild(b5);
		
		bottom.appendChild(b5.cloneNode(false));
		bottom.appendChild(b4.cloneNode(false));
		bottom.appendChild(b3.cloneNode(false));
		bottom.appendChild(b2.cloneNode(false));
		bottom.appendChild(b1.cloneNode(false));
		
		var tmp = img.cloneNode(false);
		
		roundImage.appendChild(top);
		roundImage.appendChild(tmp);
		roundImage.appendChild(bottom);
		
		parent.replaceChild(roundImage, img);
		*/
	}
}

function mailtos() {
	var d = document;
	var emails = getElementsByClassName("emailAddress");
	//
	if (emails) {
		for (var i=0; i<emails.length; i++) {
			var email = emails[i];
			var str = email.firstChild.nodeValue;
			var a = document.createElement("a");
			while (str.indexOf(" ") != -1) {
				str = str.replace(" ", "");
			}
			str = str.replace("(at)", "@");
			while (str.indexOf("(piste)") != -1) {
				str = str.replace("(piste)", ".");
			}

			var txt = document.createTextNode(str);
			a.setAttribute("href", "mailto:" + str);
			a.appendChild(txt);
			email.removeChild(email.firstChild);
			email.appendChild(a);
		}
	}
}
function attencion() {
	var d = document;
	var attencions = getElementsByClassName("attencion");
	//
	for (var i=0; i<attencions.length; i++) {
		var attencion = attencions[i];
		var parent = attencion.parentNode;
		//
		var tl = d.createElement("div");
		tl.style.background = "rgb(219,221,222) url(tl.gif) no-repeat 0 0";
		//
		var tr = d.createElement("div");
		tr.style.background = "transparent url(tr.gif) no-repeat 100% 0";
		tr.style.height = "100%";
		//
		var br = d.createElement("div");
		br.style.background = "transparent url(br.gif) no-repeat 100% 100%";
		br.style.height = "100%";
		//
		var bl = d.createElement("div");
		bl.style.background = "transparent url(bl.gif) no-repeat 0 100%";
		bl.style.height = "100%";
		
		var tmp = attencion.cloneNode(true);
		tmp.style.background = "none";
		tmp.style.margin = "0";
		
		bl.appendChild(tmp);
		br.appendChild(bl);
		tr.appendChild(br);
		tl.appendChild(tr);
		
		parent.replaceChild(tl, attencion);	
	}
}
/*
function showGame() {
	var d = document;
	var flash = d.getElementById("flash");
	flash.style.display = "block";
	
	flash.style.top = document.documentElement.scrollTop + "px";
	flash.style.height = document.documentElement.clientHeight + "px";
	flash.onclick = function() {
		//hideGame();
	}
}
function hideGame() {
	var d = document;
	var flash = d.getElementById("flash");	
	flash.style.display = "none";
}*/
/*
window.onload = function () {	
	roundImages();
	mailtos();
	attencion();
	if (String(window.onscroll) != 'undefined') {
		if (document.body.clientWidth < 1000) {
			var important = document.getElementById("important");
			important.style.display = "none";
		}
		window.onscroll = function() {
			document.getElementById("important").style.top = document.documentElement.scrollTop + (document.documentElement.clientHeight - 242) + "px";
		}
	}
	
	var game = document.getElementById("flashGame");
	game.onclick = function() {
		showGame();
		return false;
	}
	var b = document.body;
	//b.style.display = "none";
	//b.style.display = "";
	b.style.position = "absolute";
	b.style.position = "static";
}*/