// ----------------- Test if loaded in frames ------------------------------ 

if (parent.frames.length != 0) {
   top.location.replace(window.location.href);   
}

// ----------------- Cookies functions ------------------------------

function getCookieVal (offset) {  
  var endstr = document.cookie.indexOf (";", offset);  
  if (endstr == -1)    
    endstr = document.cookie.length;  
  return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {  
  var arg = name + "=";  
  var alen = arg.length;  
  var clen = document.cookie.length;  
  var i = 0;  
  while (i < clen) {    
    var j = i + alen;    
    if (document.cookie.substring(i, j) == arg)      
      return getCookieVal (j);    
    i = document.cookie.indexOf(" ", i) + 1;    
    if (i == 0) break;   
  }  
  return null;
}

function SetCookie (name, value) {  
  var argv = SetCookie.arguments;  
  var argc = SetCookie.arguments.length;  
  var expDays = 30;
  var exp = new Date(); 
  exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
  var path = (argc > 3) ? argv[3] : null;  
  var domain = (argc > 4) ? argv[4] : null;  
  var secure = (argc > 5) ? argv[5] : false;  
  document.cookie = name + "=" + escape (value) + ((exp == null) ? "" : ("; expires=" + exp.toGMTString())) + "; path=/" + ((secure == true) ? "; secure" : "");
}

function DeleteCookie (name) {  
  var exp = new Date();  
  exp.setTime (exp.getTime() - 100000);  
  var cval = GetCookie (name);  
  document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

// ----------------- Language switching ------------------------------

function switchLanguage(fromLanguage, toLanguage) {
	var url = location.href.toLowerCase();
	var url1, url2, url3, url4;
	
	if (toLanguage == "en") {   // si vers en et si news de 2007 (pas traduites) >>> switch to "news.asp" 
		if (url.indexOf("news_2007") != -1) {
			url = url.substring(0, url.indexOf("_2007")) + url.substring(url.indexOf(".asp"), 99);
		}
	}
	
	switch (fromLanguage) {
	case "nl":
		url1 = "/vastgoed/";
		url2 = "/vastgoed-brussel/";
		url3 = "/woning/";
		url4 = "/brussel/";	
		url5 = "/nl_";
		break
	case "fr": 
		url1 = "/immobilier/";
		url2 = "/immobilier-bruxelles/";
		url3 = "/logements/";
		url4 = "/bruxelles/";	
		url5 = "/fr_";
		break
	case "en": 
		url1 = "/real-estate/";
		url2 = "/real-estate-brussels/";
		url3 = "/housing/";
		url4 = "/brussels/";			
		url5 = "/en_";		
		break
	}

	switch (toLanguage) {
	case "en":
		url = url.replace(url1, "/real-estate/");
		url = url.replace(url2, "/real-estate-brussels/");
		url = url.replace(url3, "/housing/");
		url = url.replace(url4, "/brussels/");	
		url = url.replace(url5, "/fr_");			
		break
	case "nl":
		url = url.replace(url1, "/vastgoed/");
		url = url.replace(url2, "/vastgoed-brussel/");
		url = url.replace(url3, "/woning/");
		url = url.replace(url4, "/brussel/");	
		url = url.replace(url5, "/nl_");			
		break
	case "fr": 
		url = url.replace(url1, "/immobilier/");
		url = url.replace(url2, "/immobilier-bruxelles/");
		url = url.replace(url3, "/logements/");
		url = url.replace(url4, "/bruxelles/");		
		url = url.replace(url5, "/fr_");					
		break
	}
	
	url = url.replace("/" + fromLanguage + "/", "/" + toLanguage + "/");
	SetCookie("language", toLanguage);	
	location.href = url;
}

// ----------------- Stylesheet switching ------------------------------

function setActiveStyleSheet(title) {
  activeStyleSheet(title);
  SetCookie("AltCSS", title);
}

function activeStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

window.onload = function(e) {
}

window.onunload = function(e) {
}

var cookie = GetCookie("AltCSS");
var title = cookie;
if (cookie == null || cookie == "null") title = getPreferredStyleSheet();
activeStyleSheet(title);


//------------------------------------------< old switchimage.js>--------------- 


// JavaScript Document
function switchPage(typePage){
	
	switch (typePage)
		{
		case 'MA':
			switchDataFile("../top_pictures/0/",24);
			break; 
		case 'EN':
			switchDataFile("../top_pictures/EE/",15);
			break; 
		case '00':
			switchDataFile("../top_pictures/0/",24);
			break; 
		case 'SD':
			switchDataFile("../top_pictures/SD/",24);
			break;
		case 'RE':
			switchDataFile("../top_pictures/RE/",15);
			break; 
		case 'IN':
			switchDataFile("../top_pictures/IN/",15);
			break; 
		default: alert('Page type non définie');
		} 
	
}

function switchDataFile(pathFile,nbPhotos)		
{
	//-----------------------------------------
	var varArray = new Array();
 
	varArray["img1"] = "idImg_01"
	varArray["img2"] = "idImg_02"
	varArray["filename"] = pathFile
	varArray["width"] = 780
	varArray["height"] = 126
	varArray["bgcolor"] = "FFF" 
	varArray["opc"] = 0
	varArray["vitesse"] = 4000
	varArray["vtsVisible"] = 0.008
	varArray["indImg"] = 0
	varArray["maxImg"] = nbPhotos//ImgArray.length
 
	var obj1 = new Oimage(varArray);
	obj1.init();
	obj1.start();

}


		
		
function getObject(objectId) {
    // cross-browser function to get an object'skill style object given its
    if(document.getElementById && document.getElementById(objectId)) 
	{
	// W3C DOM
//	alert("FF")
	return document.getElementById(objectId);
    } 
	else if (document.all && document.all(objectId)) 
	{
//	alert("IE")		
	// MSIE 4 DOM
	return document.all(objectId);
    } 
	else 
	{
	return false;
    }
} // getStyleOb

function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject

//-----------------------------------------------
//		Déclaration de l’objet Oimage 
//-----------------------------------------------

var Oimage = function(vars){
	
		this.I = new Array();
		this.v = vars;
		
		this.init = function(){//initialisation des images
			 for (i=0; i<=(this.v["maxImg"] - 1); i++){
				 this.I[i] = this.v["filename"] + (i+1) +".jpg"
//				 alert(this.I[i])
			 }
			 //css div image 1
			this.rnd();
 			var img=getObject(this.v["img1"]);

			var newImage = "url("+this.I[this.v["indImg"]]+")";
			img.style.backgroundImage  = newImage;			
			
			img.style.width = this.v["width"] + "px";
			img.style.height = this.v["height"] + "px";
			img.style.position = "relative";
			img.style.backgroundColor = "#" + this.v["bgcolor"] + "";
			img.style.backgroundRepeat = "no-repeat";
			
			 //css div image 2			
 			img=getObject(this.v["img2"]);
			newImage = "url("+this.I[this.v["indImg"]]+")";
			img.style.backgroundImage  = newImage;
			img.style.width = this.v["width"] + "px";
			img.style.height = this.v["height"] + "px";
			img.style.position = "relative";
			img.style.backgroundColor = "#" + this.v["bgcolor"] + "";
			img.style.backgroundRepeat = "no-repeat";

			var newImage = "url("+this.I[this.v["indImg"]]+")";
			img.style.backgroundImage  = newImage;

				
		}
		
		this.start = function(){
			var monContexte = this;
			setTimeout(function (){monContexte.defilImg();},this.v["vitesse"])
		}

		this.rnd = function(){
			var value = Math.round(Math.random()*(this.v["maxImg"]-1));
			while (value == this.v["indImg"]){
				var value = Math.round(Math.random()*(this.v["maxImg"]-1));
			}			
			this.v["indImg"]= value
		}

		this.invisible = function (){

			var cur=getObject(this.v["img2"]);
			this.v["opc"] -= parseFloat(this.v["vtsVisible"]);
			cur.style.opacity = this.v["opc"];
			cur.style["filter"] = "Alpha(opacity="+(this.v["opc"]*100)+")";
			if (cur.style.opacity>0) {
				var monContexte = this;
				setTimeout(function (){monContexte.invisible();},10)
			}
			else {
				var monContexte = this;
				setTimeout(function (){monContexte.defilImg();},this.v["vitesse"])
			}

		}
	
		this.defilImg = function (){

			var imgOject = getObject(this.v["img2"]);
//			this.v["indImg"] += 1;//ici remplacer par le random
			this.rnd();
			if ((this.v["indImg"])> this.v["maxImg"] - 1) this.v["indImg"] = 0;
			//passer à l'image suivente
			var newImage = "url("+this.I[this.v["indImg"]]+")";
			imgOject.style.backgroundImage  = newImage;
//			alert(this.v["indImg"])
			this.visible();
		}			
		
		this.visible = function(){

			var cur=getObject(this.v["img2"]);
			this.v["opc"] += parseFloat(this.v["vtsVisible"]);
			cur.style.opacity = this.v["opc"];
			cur.style["filter"] = "Alpha(opacity="+(this.v["opc"]*100)+")";
			if (cur.style.opacity<1) {
				var monContexte = this;				
				setTimeout(function (){monContexte.visible();},10);	
			}
			else{
				var monContexte = this;
				setTimeout(function (){monContexte.invisible();},10)
				var imgOject = getObject(this.v["img1"]);
				var imgSuivente = this.v["indImg"] //+ 1
				if ((imgSuivente)> this.v["maxImg"] - 1) imgSuivente = 0
				//image suivente
				var newImage = "url("+this.I[imgSuivente]+")";
				imgOject.style.backgroundImage  = newImage;
			}
	}
}

//			declaration de l'objet opacite image


//Script utilisé dans main.asp pour faire 
//fondre les images au passage de la souri

var varArray
function SetVar(i){
	
	if (varArray == null) varArray = new Array();
	
	if (varArray[i] == null) 
		varArray[i] = new SwitchOpacity('img'+i+'');
	}
		
var SwitchOpacity = function(imgId){


	this.id = imgId
	this.opc = 1;
	this.raport = 0.05;
	this.vitesse = 50
	this.show;
	this.hide;

	this.init = function(){
//			alert(this.id)
/*		this.opc = 1;
		this.raport = 0.05;
		this.vitesse = 10*/
//		alert(this.raport)
		clearTimeout (this.show);
		clearTimeout (this.hide);
		this.MouseOver();
	 }
			 
	this.MouseOver = function (){

		this.opc -= this.raport;
		this.vitesse -= 1
		var cur=getObject(this.id);
		cur.style.opacity = this.opc;
		cur.style["filter"] = "Alpha(opacity="+(this.opc*100)+")";
		if (this.opc > 0.5) {
				var monContexte = this;
				this.show = setTimeout(function (){monContexte.MouseOver();},this.vitesse)
			}
//		else{clearTimeout (this.show);}			
	}


	this.MouseOut = function (){

		this.opc += this.raport;
		this.vitesse += 1
		var cur=getObject(this.id);
		cur.style.opacity = this.opc;
		cur.style["filter"] = "Alpha(opacity="+(this.opc*100)+")";
		clearTimeout(this.show);
		if (this.opc <= 1) {
				var monContexte = this;
				setTimeout(function (){monContexte.MouseOut();},this.vitesse)
			}
		else{clearTimeout (this.hide);}
	}


}
//------------------------ Cookie mailing HTML ---------------------


