// ========================================================
//              ===== images slider ====
// script: Gerard Ferrandez - Ge-1-doot - February 2008
// http://www.dhteumeuleu.com
// CC-BY-NC
// ========================================================
/* ==== slider nameSpace ==== */
var slider = function() {
	/* ==== private methods ==== */
	function getElementsByClass(object, tag, className) {
		var o = object.getElementsByTagName(tag);
		for ( var i = 0, n = o.length, ret = []; i < n; i++) {
			if (o[i].className == className) ret.push(o[i]);
		}
		if (ret.length == 1) ret = ret[0];
		return ret;
	}
	var slides = [];
	var S, S0, iW, iH, oP, oc, frm, NF, view, Z;
	var wh, ht, wr, r, mx, mn; 
	/* ==== animation loop ==== */
	var run = function () {
		Z += (mn - Z) * .5;
		view.calc();
		var i = NF;
		while (i--) slides[i].move();
	}
	/* ==== resize  ==== */	
	var resize = function () {
		wh = oc.clientWidth;
		ht = oc.clientHeight;
		wr = wh * iW;
		r  = ht / wr;
		mx = wh / NF;
		mn = (wh * (1 - iW)) / (NF - 1);
	}

	/* ==== Slide Constructor ==== */
	Slide = function (N) {
		this.N      = N;
		this.x0     = this.x1 = N * mx;
		this.v      = 0;
		this.loaded = false;
		this.cpt    = 0;
		this.start  = new Date();
		this.obj    = frm[N];
		this.txt    = getElementsByClass(this.obj, 'div', 'text');
		this.img    = getElementsByClass(this.obj, 'img', 'diapo');
		this.bkg    = document.createElement('div');
		this.bkg.className = 'backgroundText';
		this.obj.insertBefore(this.bkg, this.txt);
		if (N == 0) this.obj.style.borderLeft = 'none';
		this.obj.style.left = Math.floor(this.x0) + 'px';
		/* ==== mouse events ==== */
		this.obj.parent = this;
		this.obj.onmouseover = function() {
			this.parent.over();
			return false;
		}
	}
	/* ==== target positions ==== */
	Slide.prototype.calc = function () {
		for (var i = 0; i <= this.N; i++)
			slides[i].x1 = i * Z;
		for (var i = this.N + 1; i < NF; i++)
			slides[i].x1 = wh - (NF - i) * Z;
	}
	/* ==== HTML animation : move slides ==== */
	Slide.prototype.move = function() {
		var s = (this.x1 - this.x0) / S;
		/* ==== lateral slide ==== */
		if (this.N && Math.abs(s) > .5)
			this.obj.style.left = Math.floor(this.x0 += s) + 'px';
		/* ==== vertical text ==== */
		var v = (this.N < NF - 1) ? slides[this.N + 1].x0 - this.x0 : wh - this.x0;
		if (Math.abs(v - this.v) > .5) {
			this.bkg.style.top = this.txt.style.top = Math.floor(2 + ht - (v - Z) * iH * r) + 'px';
			this.v = v;
			this.cpt++;
		} else {
			if (!this.pro) {
				/* ==== adjust speed ==== */
				this.pro = true;
				var tps = new Date() - this.start;
				if(this.cpt > 1) {
					S = Math.max(2, (28 / (tps / this.cpt)) * S0);
				}
			}
		}
		if (!this.loaded) {
			if (this.img.complete) {
				this.img.style.visibility = 'visible';
				this.loaded = true;
			}
		}
	}
	/* ==== over ==== */
	Slide.prototype.over = function () {
		resize();
		view = this;
		this.start = new Date();
		this.cpt = 0;
		this.pro = false;
		this.calc();
	}
	/* ==== start script ==== */
	var init = function (oCont, speed, iw, ih, op) {
		S   = S0 = speed;
		iW  = iw;
		iH  = ih;
		oP  = op;
		oc  = document.getElementById(oCont);
		frm = getElementsByClass(oc, 'div', 'slide');
		NF  = frm.length;
		resize();
		for (var i = 0; i < NF; i++) 
			slides[i] = new Slide(i);
		view = slides[0];
		Z = mx;
		setInterval(run, 4);
	}
	/* ==== public methods ==== */
	return {
		init : init
	}
}();


function mycarousel_initCallback(carousel)
	{
		// Disable autoscrolling if the user clicks the prev or next button.
		carousel.buttonNext.bind('click', function() {
			carousel.startAuto(0);
		});

		carousel.buttonPrev.bind('click', function() {
			carousel.startAuto(0);
		});

		// Pause autoscrolling if the user moves with the cursor over the clip.
		carousel.clip.hover(function() {
			carousel.stopAuto();
		}, function() {
			carousel.startAuto();
		});
	};


jQuery().ready(function(){
	


	if (document.getElementById("mycarousel_hs")!=null)
	{
		jQuery('#mycarousel_hs').jcarousel({
			auto: 2,
			easing:null,
			wrap: 'last',
			initCallback: mycarousel_initCallback,
			scroll: 1
		});
	}
	
	if (document.getElementById("mycarousel_vendus")!=null)
	{
		jQuery('#mycarousel_vendus').jcarousel({
			auto: 2,
			easing:null,
			wrap: 'last',
			initCallback: mycarousel_initCallback,
			scroll: 1
		});
	}

	jQuery("#1, #2, #3").lavaLamp({
			fx: "backout",
			speed: 700
	});

	
});
function carte_handler () {
		if (document.getElementById('map_polygone').value!='') 
			document.getElementById('rech_carte').src = '../office2/acced-immobilier/catalog/images/carte_active.png';
		else
			document.getElementById('rech_carte').src = '../office2/acced-immobilier/catalog/images/carte.png';

	}
function delete_poly()
{
document.getElementById("map_polygone").value="";
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

