
//******************************************
//				autolabel.js				
//			by Cameron Gaut, 2006			
//				www.modcam.com				
//
//******************************************/	

/*
Description: Automatically searches for all text boxes with values and converts their values into grayed
text that disappears when the input receives focus. If the user has not typed anything and switches the
focus to another input, the default value will re-appear. To use this script, upload to your web site
and link to it in the <head> area.

if the auto-label feature does not work, change your body tag to <body onload="labelFields()">

<script language="JavaScript" type="text/javascript" src="autolabel.js"></script>

If you have dynamically generated fields, convert them to labeled fields with "initField(FIELD_NAME)"
Enjoy!

HF: Modified it to only include the fields that have class "graytext"


*/

Event.observe(window, 'load', function() {
	labelFields();
	initialiseMenu();
	switchimg();
	switchimg_menu();
	switchRight();	
	printPage();
//	scroll1.scroll();
});
function labelFields() {
	if (!document.getElementsByTagName){ return; }
	var allfields = $$('.graytext')
	for (var i=0; i<allfields.length; i++){ 	// loop through all input tags and add events
		initField(allfields[i]);
	}
}
function initField(field) {
	if (field) { //prevent misfire
		var graycolor = "#888";
		if ((field.type == "text" || field.type == "textarea") && (field.value != null)) {	// include text boxes, exclude empty ones
			field.style.color = graycolor;
			field.graytext = field.value;
			field.onfocus = function () {
				if (this.value==this.graytext){
					this.style.color="#000";
					this.value="";
				} else {
					this.select();
				}
			}
			field.onblur = function () {
				if (this.value=="") {
					this.style.color=graycolor;
					this.value=this.graytext;
				}
			}
		}
	}
}

// =======================================================
//  effet pour le menu product
// =======================================================
function switchimg()
{
 	var imgs,i;
 	imgs=document.getElementsByTagName('img');
 	for(i=0;i<imgs.length;i++)
 	{
  		if(/menumenu/.test(imgs[i].className))
  		{
   		imgs[i].onmouseover=function(){roll(this);};
   		imgs[i].onmouseout=function(){roll(this);}; 
  		}
 	}
}

function switchimg_menu()
{
 	var imgs,i;
 	imgs=document.getElementsByTagName('img');
 	for(i=0;i<imgs.length;i++)
 	{
  		if(/divisions/.test(imgs[i].className))
  		{
   		imgs[i].onmousedown=function(){roll(this);};
  		}
 	}
}

function roll(o)
{
 	var src,ftype,newsrc, picName, picName_id;
	// récuperer le src de l'image, et trouver extension de fichier
 	src = o.src;
 
 	ftype = src.substring(src.lastIndexOf('.'), src.length);
 
	// vérifions si le src comporte déjà la chaîne '_on' et si c'est le cas, supprimons-la
 	if(/_on/.test(src))
 	{
  		newsrc = src.replace('_on','');
	
		//pour nom de lautre image
 	//	picName = src.substring(src.lastIndexOf('/')+1, src.lastIndexOf('_'));

	//	picName_id = picName +'1';
	//	newsrc2 = src.replace('_on'+ftype, '1'+ftype);
	//	document.getElementById(picName_id).src = newsrc2;
	
 	}else{
		// sinon, ajoutons '_on' au src
  		newsrc = src.replace(ftype, '_on'+ftype);
	
		//pour nom de lautre image
 		//picName = src.substring(src.lastIndexOf('/')+1, src.lastIndexOf('.'));
		//picName_id = picName +'1';
	//	newsrc2 = src.replace(ftype, '1_on'+ftype);
	//	document.getElementById(picName_id).src = newsrc2;
 	}
 	o.src = newsrc;
}

// =======================================================
//  effet de rollover sur images de la colonne de droite - news -
// =======================================================
function switchRight(){
	var divs1, divs2, i;
 	
	divs1=document.getElementsByClassName('rel_grad1');
	divs2=document.getElementsByClassName('rel_grad2');
	
 	for(i=0;i<divs1.length;i++)
 	{
  			divs1[i].onmouseover=function(){
					this.setAttribute("class", "rel_selected");
					this.setAttribute("className", "rel_selected");
			}
				divs1[i].onmouseout=function(){
						this.setAttribute("class", "rel_grad1");
						this.setAttribute("className", "rel_grad1");
			}
 	}
	
	for(i=0;i<divs2.length;i++)
 	{
  			divs2[i].onmouseover=function(){
					this.setAttribute("class", "rel_selected");
					this.setAttribute("className", "rel_selected");
			}
			divs2[i].onmouseout=function(){
					this.setAttribute("class", "rel_grad2");
					this.setAttribute("className", "rel_grad2");
			}
 	}
}

// =======================================================
//  for the print this page tag
// =======================================================
function printPage(){
	var printTag;
	printTag = document.getElementById('print');
	if (printTag) printTag.onclick=function(){window.print();};
}
// =======================================================
//  for the scrolling logos
// =======================================================

function scrollObject(main, width, height, direct, pause, speed, textAlignement) {
  var self = this;
  this.main = main;
  this.width = width;
  this.height = height;
  this.original_direct = direct;
  this.direct = direct;
  this.pause = pause;
  this.speed = Math.max(1.001, Math.min((direct == "up" || direct == "down") ? height : width, speed));
  this.block = new Array();
  this.blockprev = this.offset = 0;
  this.blockcurr = 1;
  this.mouse = false;
  this.scroll = function() {
	if (!document.getElementById) return false;
	this.main = document.getElementById(this.main);
	while (this.main.firstChild) this.main.removeChild(this.main.firstChild);
	this.main.style.overflow = "hidden";
	this.main.style.position = "relative";
	this.main.style.width = this.width + "px";
	this.main.style.height = this.height + "px";
	for (var x = 0; x < this.block.length; x++) {
	  var table = document.createElement('table');
		  table.cellPadding = table.cellSpacing = table.border = "0";
		  table.style.position = "absolute";
		  table.style.left = table.style.top = "0px";
		  table.style.width = this.width + "px"; 
		  table.style.height = this.height + "px";
		  table.style.overflow = table.style.visibility = "hidden";
		var tbody = document.createElement('tbody');
		  var tr = document.createElement('tr');
			var td = document.createElement('td');
		if	(textAlignement == "center"){
			td.style.textAlign = 'center';
		}
		else
		{td.style.textAlign = 'left';}
				td.innerHTML = this.block[x];
			  tr.appendChild(td);
			tbody.appendChild(tr);
		  table.appendChild(tbody);
	  this.main.appendChild(this.block[x] = table);
	}
	if (this.block.length > 1) {
	  this.main.onmouseover = function() { self.mouse = true; }
	  this.main.onmouseout = function() { self.mouse = false; }
	  setInterval(function() {
				self.scrollOne();
		  }, this.pause);
		} 
		this.block[this.blockprev].style.visibility = "visible";
  }
  this.stepForward = function() {
		self.direct = self.original_direct;
		self.scrollOne();
	}
  this.stepBackward = function() {
		switch (self.original_direct) {
			case 'up':
				self.direct = 'down';
				break;
			case 'down':
				self.direct = 'up';
				break;
			case 'left':
				self.direct = 'right';
				break;
			case 'right':
				self.direct = 'left';
				break;
		}
		self.scrollOne();	}
	this.scrollOne = function() {
		if (!self.offset && self.scrollLoop()) self.block[self.blockcurr].style.visibility = "visible";
	}
  this.scrollLoop = function() {
	if (!this.offset) {
	  if (this.mouse) return false;
	  this.offset = (this.direct == "up" || this.direct == "down") ? this.height : this.width;
	} else this.offset = Math.floor(this.offset / this.speed);
	if (this.direct == "up" || this.direct == "down") {
	  this.block[this.blockcurr].style.top = ((this.direct == "up") ? this.offset : -this.offset) + "px";
	  this.block[this.blockprev].style.top = ((this.direct == "up") ? this.offset - this.height : this.height - this.offset) + "px";
	} else {
	  this.block[this.blockcurr].style.left = ((this.direct == "left") ? this.offset : -this.offset) + "px";
	  this.block[this.blockprev].style.left = ((this.direct == "left") ? this.offset - this.width : this.width - this.offset) + "px";
	}
	if (!this.offset) {
	  this.block[this.blockprev].style.visibility = "hidden";
	  this.blockprev = this.blockcurr;
	  if (++this.blockcurr >= this.block.length) this.blockcurr = 0;
	} else setTimeout(function() { self.scrollLoop(); }, 30);
	return true;
  }
}
