function getObj(name){
  if (document.getElementById){
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all){
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
}


function getAbsoluteLeft(objectId){
	var x = (new getObj(objectId)).obj;
	xLeft = x.offsetLeft;
	while(x.offsetParent!=null){
		xParent = x.offsetParent;
		xLeft += xParent.offsetLeft;
		x = xParent;
	}
	return xLeft;
}

function getAbsoluteTop(objectId){
	var x = (new getObj(objectId)).obj;
	xTop = x.offsetTop;
	while(x.offsetParent!=null) {
		xParent = x.offsetParent;
		xTop += xParent.offsetTop;
		x = xParent;
	}
	return xTop;
}

function getWidth(objectId){
	return (new getObj(objectId)).obj.offsetWidth;
}

function getHeight(objectId){
	return (new getObj(objectId)).obj.offsetHeight;
}

function openPopupMarques (marque) {
	window.open("popup-marques/presentation-marques.htm?marque="+marque+"","popMarque","width=620,height=359,left=0,top=0,scrollbars=0");
}

function initFormEvents () {
	/*choixMarques.nosAutresMarques.onchange = function () {			
}*/
}

function valid( obj , divname )
{
	var divobj = new getObj(divname);
	if(divobj.obj!=null)
	{
		if( obj.value=='' )
		{
			divobj.style.display = 'inline';
		}
		else
		{
			divobj.style.display = 'none';						
		}
	}
	
}


function writeFlash(url,id,w,h,o){
      var tempFlashContent = '';
      var flashOptionsTab = new Array();
      flashOptionsTab = o.split('|');
      tempFlashContent += '<object id="'+id+'" type="application/x-shockwave-flash" data="'+url+'" width="'+w+'" height="'+h+'">\n';
      tempFlashContent += '\t<param name="movie" value="'+url+'" />\n';
      for(i=0; i<flashOptionsTab.length; i++){
            var tempParam = flashOptionsTab[i].split('#')[0];
            var tempValue = flashOptionsTab[i].split('#')[1];
            tempFlashContent += '\t<param name="'+tempParam+'" value="'+tempValue+'" />\n';
      }
      tempFlashContent += '</object>\n';
      document.write(tempFlashContent);

}

function OpenPopUpMark(urlRoot,markId){
window.open(''+urlRoot+'MarkDetails.aspx?markId='+markId+'','blank','toolbar=no,width=620,height=360')
}

function openFormDevis (baseurl,productid, dimensionid) {
					window.open(''+baseurl+''+'FormDevis.aspx?productid='+productid+'&dimensionid='+dimensionid+'',"popFormDevis","width=418,height=450,left=0,top=0,scrollbars=no,statusbar=no");
}


/***** 00 - autoRoll *****/
var onAdd="-1";
function autoRoll(Img,Event){
	if((!Img.onmouseout || Img.onmouseout == null) && Event == true) Img.onmouseout = function(){ autoRoll(Img) };
	imgExt = Img.src.substring(Img.src.lastIndexOf("."));
	imgName = Img.src.substring(0,Img.src.lastIndexOf(".")-2);
	imgOn = imgName+onAdd+imgExt;
	if(imgName.indexOf(onAdd) != -1) imgName = imgName.substring(0,imgName.length-onAdd.length);
	imgOff = imgName+"-0"+imgExt;
	if(Img.src.indexOf(onAdd) != -1) Img.src = imgOff;
	else Img.src = imgOn;
}

function autoRollEvents(){
	var imgTable = arguments[0].getElementsByTagName('img');
	for(var i=0; i<imgTable.length; i++){
		if(imgTable[i].src.indexOf(onAdd) == -1) imgTable[i].onmouseover = function(){autoRoll(this,true)};
	}
}

function navEvents(){
	autoRollEvents(document.getElementById("nav"));
}

/***** 00 - Variables *****/
var actURL = document.location.href;
var isOpera = (navigator.userAgent.indexOf('Opera') != -1)? true : false;
var isIE = (document.all && !isOpera && navigator.platform == "Win32")? true : false;
var isIE7 = (navigator.userAgent.indexOf('MSIE 7') != -1)? true : false ;
var isW2000 = (navigator.userAgent.indexOf('Windows NT 5.0') != -1)? true : false;

/***** 01 - Base *****/		
/**
Cibler un objet
-------------------
* Pour cibler une ID : _('id');
* Pour cibler plusieurs IDs : _('id1|id2|...|idn');
* Pour cibler un noeud enfant : _('tag',lvl);   >   _('tag1',lvl1,'tag2',lvl2,...,'tagn',lvln);
* Pour cibler une ID puis un noeud enfant : _('id','tag',lvl);   >   _('id','tag1',lvl1,'tag2',lvl2,...,'tagn',lvln);
* Pour cibler des TAG : _('tag',-1);
* Pour cibler une ID puis des TAG : _('id','tag',-1);
-------------------
* Retourne : Objet ou Array
**/
function _(){
	var r = 'document';
	if(arguments.length == 1){
		var d = arguments[0].split('|');
		if(d.length > 1){
			var t = new Array();
			for(var i=0; i<d.length; i++){
				t[t.length] = _(d[i]);					
			}
			return t;
		} else {
			r += '.getElementById(\''+arguments[0]+'\')';
		}
	} else {
		for(var i=0; i<arguments.length; i++){
			var p = i+1;
			if(typeof arguments[p] == 'string' && typeof arguments[i] != 'number' || p > arguments.length){
				r += '.getElementById(\''+arguments[i]+'\')';
			} else if(typeof arguments[p] == 'number'){
				r += (arguments[p] == -1)? '.getElementsByTagName(\''+arguments[i]+'\')' : '.getElementsByTagName(\''+arguments[i]+'\')['+arguments[p]+']';
			}
		}
	}
	return eval(r);
}

/**
Cibler des élément par leur class
-----------------------------------------
* Pour cibler un couple TAG / Class : __('tag','class');
* Pour cibler plusieurs TAG pour une class : __('tag1|tag2|...|tagn',class');
* Pour cibler un couple TAG / Class dans un élément ciblé: __('tag','class',_('id'));
* Pour cibler un couple TAG / Class dans un élément ciblé: __('tag','class',_('id','div',2));
-----------------------------------------
* Retourne : Array
**/
function __(){
	var p = (arguments[2])? arguments[2] : false;
	var c = new Array();
	var t = arguments[0].split('|');
	for(var i=0; i<t.length; i++){
		var e = (p)? p.getElementsByTagName(t[i]) : _(t[i],-1);
		for(var j=0; j<e.length; j++){
			var s = arguments[1].split('|');
			for(var k=0; k<s.length; k++){
				if(e[j].className == s[k] || e[j].className.indexOf(s[k]+' ') != -1 || e[j].className.indexOf(' '+s[k]) != -1){
					c[c.length] = e[j];
				}
			}
		}
	}
	return c;
}

/***** Scroller *****/
var scrollInter;
var scrollSpeed = 50;
var scrollDelta = 15;
var scrollActive;
function scrollClic(index,delta){
	var s = scrolls[index];
	delta = Math.round(delta/s.scale);
	if(delta > 0){
		if(s.cursor.offsetTop-delta > 0){
			s.cursor.style.top = s.cursor.offsetTop-delta+"px";
		} else {
			s.cursor.style.top = "0";
			clearInterval(scrollInter);
		}
	} else {
		if(s.cursor.offsetTop-delta < s.bar.offsetHeight-s.cursor.offsetHeight){
			s.cursor.style.top = s.cursor.offsetTop-delta+"px";
		} else {
			s.cursor.style.top = s.bar.offsetHeight-s.cursor.offsetHeight+"px";
			clearInterval(scrollInter);
		}
	}
	s.inscro.style.marginTop = -(Math.round(s.cursor.offsetTop*s.scale))+"px";
}

var mousey = null;
var oldAction = null;
function scrollDrag(e){
	if(!e) e = window.event;
	if(mousey != null){
		var s = scrollActive;
		delta = mousey-e.clientY;
		if(delta > 0){
			if(s.cursor.offsetTop-delta > 0){
				s.cursor.style.top = s.cursor.offsetTop-delta+"px";
			} else {
				s.cursor.style.top = "0";
				clearInterval(scrollInter);
			}
		} else {
			if(s.cursor.offsetTop-delta < s.bar.offsetHeight-s.cursor.offsetHeight){
				s.cursor.style.top = s.cursor.offsetTop-delta+"px";
			} else {
				s.cursor.style.top = s.bar.offsetHeight-s.cursor.offsetHeight+"px";
				clearInterval(scrollInter);
			}
		}
		s.inscro.style.marginTop = -(Math.round(s.cursor.offsetTop*s.scale))+"px";
	}
	mousey = e.clientY;
}

var scrolls = new Array();
function scroll(obj){
	
	this.mask = obj;
	this.index = scrolls.length;
	this.mask.id = "scroll"+this.index;
	this.inscro = obj.firstChild;
	this.ratio = obj.firstChild.offsetHeight/obj.offsetHeight;
	
	if(this.ratio > 1){
		
		/***** Tools - Start *****/
		// Track
		this.track = document.createElement("div");
		this.mask.appendChild(this.track);
		this.track.className = "track";
		// Button up
		this.up = document.createElement("div");
		this.track.appendChild(this.up)
		this.up.className = "up";
		// Button down
		this.down = document.createElement("div");
		this.track.appendChild(this.down);
		this.down.className = "down";
		// Bar + Cursor
		this.bar = document.createElement("div");
		this.cursor = document.createElement("div");
		this.incurs = document.createElement("div");
		this.cursor.appendChild(this.incurs);
		this.incurs.className = "incurs";
		this.bar.appendChild(this.cursor);
		this.cursor.className = "cursor";
		this.track.appendChild(this.bar);
		this.bar.className = "bar";
		
		this.hidden = document.createElement("input");
		this.hidden.setAttribute("type","hidden");
		this.mask.parentNode.appendChild(this.hidden);
		/***** Tools - End *****/
		
		/***** Tools style - Start *****/
		// Mask
		this.mask.style.overflow = "hidden";
		this.mask.style.position = "relative";
		// Cont
		this.inscro.style.paddingRight = "15px";
		this.inscro.style.width = (this.inscro.offsetWidth-15)+"px";
		// Track
		this.track.style.position = "absolute";
		this.track.style.top = "0";
		this.track.style.right = "0";
		this.track.style.height = this.mask.offsetHeight+"px";
		this.track.style.width = "15px";
		// Button up
		this.up.style.position = "absolute";
		this.up.style.top = "0";
		this.up.style.left = "0";
		this.up.style.width = this.track.offsetWidth+"px";
		this.up.style.height = this.track.offsetWidth+"px";
		this.up.index = this.index;
		// Button down
		this.down.style.position = "absolute";
		this.down.style.bottom = "0";
		this.down.style.left = "0";
		this.down.style.width = this.track.offsetWidth+"px";
		this.down.style.height = this.track.offsetWidth+"px";
		this.down.index = this.index;
		// Bar
		this.bar.style.position = "absolute";
		this.bar.style.top = this.track.offsetWidth+"px";
		this.bar.style.left = "0";
		this.bar.style.width = this.track.offsetWidth+"px";
		this.bar.style.height = (this.track.offsetHeight-(this.track.offsetWidth*2))+"px";
		// Cursor
		this.cursor.style.position = "absolute";
		this.cursor.style.top = "0";
		this.cursor.style.left = "0";
		this.cursor.style.width = this.track.offsetWidth+"px";
		var tmp = Math.floor((this.bar.offsetHeight*this.mask.offsetHeight)/this.inscro.offsetHeight);
		this.incurs.style.height = tmp+"px";
		this.incurs.index = this.index;
		/***** Tools style - End *****/
		
		this.scale = this.inscro.offsetHeight/this.bar.offsetHeight;
		
		/***** Events *****/
		this.up.onmousedown = function(){ clearInterval(scrollInter); scrollInter = setInterval("scrollClic("+this.index+","+scrollDelta+");",scrollSpeed); }
		this.up.onmouseup = this.up.onmouseout = function(){ clearInterval(scrollInter); }
		
		this.down.onmousedown = function(){ clearInterval(scrollInter); scrollInter = setInterval("scrollClic("+this.index+",-"+scrollDelta+");",scrollSpeed); }
		this.down.onmouseup = this.down.onmouseout = function(){ clearInterval(scrollInter); }
		
		this.incurs.onmousedown = function (){
			oldAction = document.onmousemove;
			scrollActive = scrolls[this.index];
			document.onmousemove = scrollDrag;
		}
		document.onmouseup = function(){
			document.onmousemove = oldAction;
			oldAction = null;
			mousey = null;
			if(scrollActive != null && !isIE){
				scrollActive.hidden.focus();
			}
		}
		
	}
	
	scrolls[scrolls.length] = this;
	
}

/***** Init *****/
function init(){
	if(_("nav")){
		navEvents();
	}
	
	// Scrolls
	var scrollsTab = __('div','scroll');
	for(var i=0; i<scrollsTab.length; i++){
		new scroll(scrollsTab[i]);
	}
	
}