// Adaptation Pierre Dallier -PRC Informatique -29/02/2000
// Site des Puces Nautiques


var ns4 = (document.layers)? true:false;
var ie4 = (document.all)? true:false;
var v4  = (ns4 || ie4 || navigator.appName == "Netscape")? true:false;
var Lbourse, Lemploi,Lvendre, LPuce

function erreur()
{
}

window.onerror = erreur;

function open_ag()
{
	//fenetre=window.open("http://www.toto.com",'AG','width=660,height=350,resizable=no,scrollbars=no');
}
function init()
{
	if (v4)
	{	
		Lbourse = new initLayer("Lbourse");
		Lbourse.slideInit();
	
		Lemploi = new initLayer("Lemploi");
		Lemploi.slideInit();
		
		Lvendre = new initLayer("Lvendre");
		Lvendre.slideInit();

		LPuce = new initLayer("Puce");
	
	}
}

function hide_all()
{
	Lbourse.hide();
	Lemploi.hide();
	Lvendre.hide();

}

function initLayer(id)
{
	if (ns4)
	{
		this.css = document.layers[id];
		this.ref = document.layers[id].document;
		this.x = this.css.left;
		this.y = this.css.top;
	}
	else if (ie4) 
	{
		this.css = document.all[id].style;
		this.ref = document;
		this.x = this.css.pixelLeft;
		this.y = this.css.pixelTop;
	}

	this.obj = id + "DynLayer";
	eval(this.obj + "=this");

	this.moveTo = LayerMoveTo;
	this.moveBy = LayerMoveBy;
	this.hide = LayerHide;
	this.show = LayerShow;
	this.slideInit = LayerSlideInit;
}

function LayerMoveTo(x,y) 
{
	this.x = x;
	this.css.left = this.x;
	this.y = y;
	this.css.top = this.y;
}

function LayerMoveBy(x,y)
{
	this.moveTo(this.x+x,this.y+y);
}

function LayerShow() 
{
	if (ns4) this.css.visibility = "show";
	else if (ie4) this.css.visibility = "visible";
}

function LayerHide() 
{
	if (ns4) this.css.visibility = "hide";
	else if (ie4) this.css.visibility = "hidden";
}

function LayerSlideInit()
{
	this.slideTo = LayerSlideTo;
	this.slideStart = LayerSlideStart;
	this.slide = LayerSlide;
}

function LayerSlideTo(startx, starty, endx,endy,inc,speed)
{
	hide_all();
	this.moveTo(startx, starty);

	if (endx==null) endx = this.x;
	if (endy==null) endy = this.y;

	var distx = endx-this.x;
	var disty = endy-this.y;

	this.show();
	this.slideStart(endx,endy,distx,disty,inc,speed);
}

function LayerSlideStart(endx,endy,distx,disty,inc,speed)
{
	if (this.slideActive) return;
	if (!inc) inc = 10;
	if (!speed) speed = 20;

	var num = Math.sqrt(Math.pow(distx,2) + Math.pow(disty,2))/inc;

	if (num==0) return;

	var dx = distx/num;
	var dy = disty/num;

	this.slideActive = true;
	this.slide(dx,dy,endx,endy,num,1,speed);
}

function LayerSlide(dx,dy,endx,endy,num,i,speed)
{
	if (!this.slideActive) return;

	if (i++ < num) {
		this.moveBy(dx,dy);
		if (this.slideActive) 
			setTimeout(this.obj+".slide("+dx+","+dy+","+endx+","+endy+","+num+","+i+","+speed+")",speed);
	}
	else {
		this.slideActive = false;
		this.moveTo(endx,endy);
	}
}

function movePuce(layer, x, y)
{
	LPuce.ref.im_puce.src='img/puce.gif';
	LPuce.moveTo(x, y);
	LPuce.show();
	layer.show();
}

function recadre()
{
	if (ns4)
		document.location.replace(document.location);
}

function aleatoire()
{
	return Math.round(4*Math.random() + 1);
}
