/*
 *	Automenu - 21/07/2006
 *	copyright (c) Bestofmedia - infos-du-net.com
 *	Auteur : Frantz Gauthier
 * 	Description : gestion de l'affichage des sous-menu
 *	Require : prototype.js
 */

Automenu = Class.create();

Automenu.prototype = {
	pile: new Array(),
	initialize: function(button) {
		Automenu.prototype.pile.push(this);
		this.button = button;
		this.parent = button.parentNode;
		this.idMenu = 'sousMenu-' + this.parent.id;

		this.menuFlag = false;

		this.parent.style.paddingRight = '30px';
		this.button.style.display = 'block';

		Event.observe(this.button, 'click', this.toggleMenu.bindAsEventListener(this));
		Event.observe(this.idMenu, 'mouseover', this.openMenu.bindAsEventListener(this));
	},
	openMenu: function(e) {
		//Effect.Appear(this.idMenu, {duration: 0.3});
		this.closeOther();
		Element.show(this.idMenu);
		this.menuFlag = true;
		Event.observe(this.idMenu, 'mouseout', this.closeMenu.bindAsEventListener(this));
	},
	closeMenu: function(e) {
		//Effect.Fade(this.idMenu, {duration: 0.2});
		Element.hide(this.idMenu);
		this.menuFlag = false;
	},
	toggleMenu: function(e) {
		this.menuFlag ? this.closeMenu() : this.openMenu();
	},
	closeOther: function() {
		for (i=0; i < Automenu.prototype.pile.length; i++) {
			if(Automenu.prototype.pile[i].button != this.button && Automenu.prototype.pile[i].menuFlag) Automenu.prototype.pile[i].closeMenu();
		}
	}
 }

Event.observe(window,'load', function() {
	var automenus = $('menu-header').getElementsByClassName('automenu-button');

	for(var i=0; i < automenus.length; i++)
	{
		new Automenu(automenus[i]);
	}
});


 /*
  * OpenRight - 01/08/2006
  */

  OpenRight = Class.create();

  OpenRight.prototype = {
  	initialize: function(id, content, end) {
  		this.box = $(id);
  		this.width = Element.getDimensions(id).width;
  		this.initialWidth = this.width;
  		this.content = content;
  		this.end = end;
  		this.currentlyAction = 'undefined';
  	}
  	,
  	open: function() {
  		if(this.width < this.end) {
  			this.width += 32;
  			this.box.style.width = this.width+'px';
  		} else {
  			window.clearInterval(this.pe);
  			$(this.content).style.display = 'block';
  		}
  	},
  	close: function() {
  		if (this.width > this.initialWidth){
  			this.width -= 32;
  			this.box.style.width = this.width+'px';
  		} else {
  			window.clearInterval(this.pe);
  		}
  	},
  	pOpen: function() {
  		this.currentlyAction = 'open';
  		if(this.pe) { window.clearInterval(this.pe) }
  		//Effect.Appear(this.content);
  		this.pe = window.setInterval(this.open.bind(this), 50);
  	},
  	pClose: function() {
  		this.currentlyAction = 'close';
  		if(this.pe) { window.clearInterval(this.pe) }
  		//Effect.Fade(this.content, {duration: 0.3});
  		$(this.content).style.display = 'none';
  		this.pe = window.setInterval(this.close.bind(this), 50);
  	},
  	switchMe: function() {
  		if(this.currentlyAction == 'undefined' || this.currentlyAction == 'close')
  		{
  			this.pOpen()
  		} else {
  			this.pClose();
  		}
  	}
  }


//=== Begin : Filtre des Actus ==========================
/*
 * Recharge les actualit?s
 */

var error = false;

 function reloadActu(idscat){
	var scats = document.getElementsByName('supercats');
	var supercats = Array();
	var url = '';
	var j=0;
	for ( i=0; i < scats.length; i++ ) {
		if(scats[i].checked){
			url +='&supercats['+ j +']=' + scats[i].value;
			supercats[j] = i;
			j++;
		}
	}
	if (url == ''){
		last_scat = document.getElementById(idscat);
		last_scat.checked = true;
		url = 'supercats[0]=' + last_scat.value;
	}
	displayLoadingImg();
	var options = {
				method : 'get',
				parameters : url,
				onComplete : displayActu,
				onFailure: function(transport) {
			        alert("Une erreur a &eacute;t&eacute; rencontr&eacute;.");
			        hideLoadingImg();
			        error = true;
			      },
				asynchronous : true
	};
	var req = new Ajax.Request('ajax_listing_actus_categ.php', options);

}

function displayActu(obj){
	if(!error){
	document.getElementById('listing-actus').innerHTML = obj.responseText;
	hideLoadingImg();
	}
}

function displayLoadingImg(){
	var div = document.getElementById('listing-actus-loadimage');
	Effect.Appear(div);
}


function hideLoadingImg(){
	var div = document.getElementById('listing-actus-loadimage');
	Effect.Fade(div);
}

//=== End : Filtre des Actus ==========================

/**
 * D?code une cha?ne
 */
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
function decode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

   do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = keyStr.indexOf(input.charAt(i++));

      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;

      output = output + String.fromCharCode(chr1);

      if (enc3 != 64) {
         output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
         output = output + String.fromCharCode(chr3);
      }
   } while (i < input.length);

   document.write(output);
}


/*
 * Gestion des panneaux ? onglets
 */

 function switchTab(elm, stub) {
    stub = $(stub)
    var classe = elm.className;
    if (classe.indexOf('selectedTab') != -1) {
      return;
    } else {
      var tabHead = document.getElementsByClassName('tabHead', stub)[0];
      var onglets = tabHead.getElementsByTagName('a');
      for (i = 0; i < onglets.length; i++ )
      {
        var classInfo = onglets[i].className;
        var selectedPos = classInfo.indexOf(' selectedTab');
        if (selectedPos != -1) {
          onglets[i].className = classInfo.slice(0, selectedPos);
        }
      }
      elm.className += ' selectedTab';

      var tabs = document.getElementsByClassName('tabs', stub)[0];
      var ongletsCorps = tabs.getElementsByTagName('li');
      for (i = 0; i < ongletsCorps.length; i++ )
      {
        var classInfo =  ongletsCorps[i].className;
        if (classInfo != classe && classInfo.indexOf('tab') != -1) {
          ongletsCorps[i].style.display = 'none';
        } else {
          ongletsCorps[i].style.display = 'block';
        }
      }
      elm.blur();
      return false;
    }
  }

/*
 * Gestion de l'impression
 */

 function imprimer() {
 	this.window.print();
 }

 /*
  * zoom images dossier
  */

function zoom(path) {
	var zoom=window.open(path,"zoom","menubar=no,toolbar=no,statusbar=no,scrollbars=yes,resizable=yes")
}

/*
 * show hide #blockMonIDN #MonIDN-MesDiscussions bloc
 */

toggleMonIdn = 1;

function callBackMonIdn() {
	elem = document.getElementById("showHideMesDiscussions");
 if (toggleMonIdn==0) {
 	toggleMonIdn = 1;
		elem.className = 'up';
	}
	else {
		toggleMonIdn= 0;
		elem.className = 'down';
	}
}

function showHideMonIDNBlock () {
	Effect.toggle('MonIDN-MesDiscussions',   'slide'  , {duration:1,afterFinish:callBackMonIdn} );
}


/*
 *
 */

 Event.observe(window,'load', function() {
	if ($('transparentL_id') && document.body.appendChild)
	{
		document.body.appendChild($('transparentL_id'));
	}

});
