// ------------------------- REQUIRE :) ---------------------------------- //
if (navigator.userAgent.indexOf('Firefox') >= 0){//initialisation de la console (bug FF3);
	if( typeof console != 'undefined' ) console.log();
}
if (typeof Element == 'undefined') throw("tools.js requires prototype.js library");

// ------------------------- DEBUG VAR ---------------------------------- //
var db = function(myvar) {
   var varValue = 'DB (' + typeof myvar + ') :\n';
    if (typeof myvar == 'string' || typeof myvar == 'number') varValue = myvar;
    //else if (typeof myvar == 'object') return vd(myvar);
    else {
        for (var att in myvar) {
            if (typeof myvar[att] != 'function') // (bad prototype noise)
                varValue += '\t'+att + ' <'+typeof myvar[att]+'> ' + myvar[att]+'\n';
        }
    }
	if (typeof myvar == 'array') varValue += "\n"+myvar.inspect();
    if (navigator.userAgent.indexOf('Firefox') >= 0 && typeof console != 'undefined' && console.log) console.log(varValue); // DEV
    else nativeAlert(varValue);
};

// ------------------------- Rollover Image ---------------------------------- //
var RollOverImage = function(){
	var options = Object.extend({}, arguments[0] || {});
	if (!options.RollRech) options.RollRech = '';
	var RollRech = options.RollRech;
	
	$$(RollRech+'input[type=image]',RollRech+'img.rollover').each(
		function(e,index){
			var chemin = e.src;
			var pos_debut = chemin.lastIndexOf('/')+1;
			var pos_fin = chemin.lastIndexOf('.');
			var chemin_fichier = chemin.substring(0,pos_debut);
			var nom_fichier = chemin.substring(pos_debut,pos_fin);
			var ext_fichier = chemin.substr(pos_fin);
			if(!e.hasClassName('no_roll')){
				Event.observe(e, 'mouseover', function(){
					e.src = chemin_fichier+nom_fichier+'_on'+ext_fichier;
				});			 
				Event.observe(e, 'mouseout', function(){
					e.src = chemin_fichier+nom_fichier+ext_fichier;
				});
			}
		}
	);
};

// ------------------------- Focus Input ---------------------------------- //
var focusInput = function(){
	var input = $$('input[value!=""]');
	input.each( function(e,i){
		if((e.type=='text' || e.type=='password') && e.hasClassName('focusInput')){
			Event.observe(e, 'focus', function(evt){
				if(e.value==e.defaultValue)e.value='';
			});
			Event.observe(e, 'blur', function(evt){
				if(e.value=='')e.value=e.defaultValue;
			});
		}
	});
}
