/****
 Global vars
*******/
var IS_IE = document.all && window.print && !window.opera && ( !document.compatMode || /MSIE 6/.test(navigator.userAgent) || (document.compatMode && document.compatMode=="BackCompat"));

var log = function(arg) {
	if(window.console)
		return console.log(arg)
	else return alert(arg)
}


/* INIT MOOTOOLS  */
// les 2 fonctions swapImg et unSwapImg n&eacute;cessittent d'avoir 
// 2 img appell&eacute;es img1.jpg et img1_over.jpg ds le même dossier
// s'utilise : onmouseover="swapImg(this)" sur la balise img
/** 
 * @param {Object} cible
 */
//addEvent('scroll',placeBottomNav);
//addEvent('resize',placeBottomNav);
var fx555;
addEvent('domready',function(){
			addTools();
			//searchInput();
			$('discoverUL').style.visibility= 'hidden';
			$('registerUL').style.visibility= 'hidden';
			$('toolsUL').style.visibility= 'hidden';
			correctPNG();
			var fx = new Fx.Styles('discoverIMG', {duration:400, wait:false});
			var fx2 = new Fx.Styles('discoverUL', {duration:400, wait:false});
			var fx5 = new Fx.Styles('registerIMG', {duration:400, wait:false});
			var fx6 = new Fx.Styles('registerUL', {duration:400, wait:false});
			var fx3 = new Fx.Styles('toolsIMG', {duration:400, wait:false});
			var fx4 = new Fx.Styles('toolsUL', {duration:400, wait:false});
			/*var fx555 = new Fx.Styles($('ranks'), {duration:400, wait:false});
			fx2.start({	'opacity': 0 });
			fx4.start({ 'opacity':0	});
			var test = function(){
				if ($('ranks').getStyle('opacity')==1){
					fx555.start({ 'opacity':0 });
				}else{
					fx555.start({ 'opacity':1 });
				}
			}
			test.periodical(500); */
		
			//
			$('discover').addEvent('mouseenter', function(e){
				e = new Event(e);
				fx.start({'opacity': 0});
				fx2.start({ 'opacity': 1});
				e.stop();
			})
			$('discover').addEvent('mouseleave', function(e){
				e = new Event(e);
				fx.start({'opacity': 1});
				fx2.start({'opacity': 0});
				e.stop();
			})
			
			$('register').addEvent('mouseenter', function(e){
				e = new Event(e);
				fx5.start({'opacity': 0});
				fx6.start({'opacity': 1});
				e.stop();
			})
			$('register').addEvent('mouseleave', function(e){
				e = new Event(e);
				fx5.start({'opacity': 1});
				fx6.start({'opacity': 0});
				e.stop();
			})
			
			$('tools').addEvent('mouseenter', function(e){
				e = new Event(e);
				fx3.start({'opacity': 0});
				fx4.start({'opacity': 1});
				e.stop();
			})
			$('tools').addEvent('mouseleave', function(e){
				e = new Event(e);
				fx3.start({'opacity': 1});
				fx4.start({'opacity': 0});
				e.stop();
			})
			//up();
			// positionement de la nav pour ie6
			if(IS_IE){
			//setInterval(placeBottomNav, 20);
			ie6_li_hover('discoverUL', 'ie_hover');
			ie6_li_hover('toolsUL', 'ie_hover');
			ie6_li_hover('registerUL', 'ie_hover');
			}
			
		});
/* //  INIT MOOTOOLS */

/*  ****************************   fonctions fix IE6  *****************************/
/* 
* permet de simuler l'evt CSS ul li:hover {}
* se lance sur le onload, et prends en param:
* ul : id de l'ul parent des li
* classname : le nom de la classe à appliquer
*/
function ie6_li_hover(ul, classname){
 var listLI = $(ul).childNodes;
 for (i=0; i<listLI.length;i++){
		listLI[i].onmouseover = function (){
				this.setAttribute("className", classname);
			}
		listLI[i].onmouseout = function (){
				this.setAttribute("className","");
			}
 }

}
function placeBottomNav(){
		if (IS_IE){
			//alert($('footer_gradient').style)
			$('footer_gradient').style.top = document.documentElement.scrollTop+document.documentElement.clientHeight-$('footer_gradient').offsetHeight;
			$('footer_gradient').style.zIndex = 90;
			$('footerbar').style.top = document.documentElement.scrollTop+document.documentElement.clientHeight-$('footerbar').offsetHeight;
			$('footerbar').style.zIndex = 100;
			}
		}

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i];
		 //alert(img);
         var imgName = img.src.toUpperCase()
		 
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG" && img.className.indexOf('PNG') != -1 )
         {
			//alert("img.className="+img.className);
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='crop');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}



function popup(e, page, name, args){
/*	log(e);
	log(page);
	log(name);
	log(args);*/
	var name = name;
	if (e){
		if (e.preventDefault) {
		  e.preventDefault();
		} 
		else {
		e.returnValue = false;
		}
	}
	//name = name.replace(\(/é|/-))
	//log(name);
	var bla = name.indexOf("e-Strat");
	var bli = name.indexOf("Slider")
	if ( bla != -1){
		if ( bli  != -1){
		name = "Slider";
		}
		else {
		name = "Video";
		}
	}
	//log(name);
	args += " ,resizable=1";
	window.open(page, name, args);
}

function addTools(){
	var a = document.getElementsByTagName("h3");
	//log(a);
	for (i=0;i<a.length;i++){
		var clas = a[i].getAttribute('className') || a[i].getAttribute('class');
		if(clas == 'section'){
			//log(clas)
			a[i].id = 'section';
		}
	}
	//log($('section'));
	//log($('webTools'));
	setTimeout(function(){if($('section') && $('webTools')){$('webTools').injectBefore("section")};}, 50);
	
	

}
//
/**
 * fonction de mis à jour auto des input
 * onclick -> l'input se vide
 * onblur -> si l'input est vide, il reprend sa valeur par défaut
 * input exception : mettre noClear="true" comme attribut de la balise
 * fonction autonome; supprimer ds initialisation() si plus utile
 *  */
function searchInput (){
	var cible = document.getElementsByTagName('input');
	for (i=0;i<cible.length;i++){
		//console.log(cible[i].name)
		//console.log(cible[i].i)
		var noClear = cible[i].getAttribute("noClear");
		if(!noClear){
			cible[i].onfocus = clearInput;
			cible[i].onblur = resetInput;
		}
	}
}
function clearInput (){
	if (this.value==this.defaultValue)
		this.value = "";
}
function resetInput (sender){
	if(this.value == ""){
		this.value = this.defaultValue;
		//calcul(this);
	}
}
