function ajaxObject(url, callbackFunction) {  
	var that=this;        
	this.updating = false;  
	this.abort = function() {    
		if (that.updating) {      
			that.updating=false;      
			that.AJAX.abort();      
			that.AJAX=null;    
		}  
	}  
	this.update = function(passData,postMethod) {     
		if (that.updating) { 
			return false; 
		}    
		that.AJAX = null;                              
		if (window.XMLHttpRequest) {                    
			that.AJAX=new XMLHttpRequest();                  
		} else {                                        
			that.AJAX=new ActiveXObject("Microsoft.XMLHTTP");    
		}                                                 
		if (that.AJAX==null) {                                   
			return false;                                   
		} else {      
			that.AJAX.onreadystatechange = function() {          
				if (that.AJAX.readyState==4) {                       
					that.updating=false;                          
					that.callback(that.AJAX.responseText,that.AJAX.status,that.AJAX.responseXML);                  
					that.AJAX=null;                                                 
				}                                                            
			}                                                              
			that.updating = new Date();                                    
			if (/post/i.test(postMethod)) {        
				var uri=urlCall+'?'+that.updating.getTime();        
				that.AJAX.open("POST", uri, true);        
				that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");        
				that.AJAX.send(passData);      
			} else {        
				var uri=urlCall+'?'+passData+'&timestamp='+(that.updating.getTime());         
				that.AJAX.open("GET", uri, true);                                     
				that.AJAX.send(null);                                               
			}                    
			return true;                                                 
		}                                                		
	}  
	var urlCall = url;          
	this.callback = callbackFunction || function () { };
}
function openPopUp(){
	var height  =  (document.documentElement && document.documentElement.scrollHeight) ? document.documentElement.scrollHeight : (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight;
	var clientHeight  = (document.documentElement && document.documentElement.clientHeight) || window.innerHeight || self.innerHeight || document.body.clientHeight;
	var scrollTop =  (document.documentElement && document.documentElement.scrollTop) || window.pageYOffset || self.pageYOffset || document.body.scrollTop;

 	document.getElementById('popup').style.display = "block";
 	document.getElementById('blackLayer').style.display = "block";
 
	document.getElementById('blackLayer').style.height = height+'px';
 	document.getElementById('popup').style.top = (scrollTop+195)+((clientHeight-document.getElementById('popup').offsetHeight)/2)+'px';
 	
	
	
}
function closePopUp(){
	document.getElementById('blackLayer').style.display = "none";
	document.getElementById('popup').style.display = "none";
	document.getElementById("popup").innerHTML = "";
}
function setPopup(id){
	var car_AJAX = new ajaxObject('/includes/car_ajax.php');    
	car_AJAX .callback = function(responseText, responseStatus, responseXML) {
		document.getElementById("popup").innerHTML = responseText;
    };
	car_AJAX.update('id='+id,'GET');	
	openPopUp();
}
function MouseOverCarImage(id){
	document.getElementById('largeImage').src = 'http://pictures.autotrader.nl/servlet/media?id='+id+'&large=true';
}
function popUpCarImage(id,idImg){
	//largeImages array formed in initBigImageMapping template
	url = 'http://zoek.autotrader.nl/dslnl/cars_advertImages?id='+id+'&locale=dslnl.cars.1&currency=EUR&did=1002646&largeid='+idImg;
	var windowSize="width=340,height=340,top=0,left=0,resizable=yes,status=yes,toolbar=0,menubar=0,location=0,dependent=yes,scrollbars=yes";
	myWindow=window.open(url,"HighResolutionWindow",windowSize);
}
function addEvent(obj, evType, fn){ 
	 if (obj.addEventListener){ 
		obj.addEventListener(evType, fn, false); 
		return true; 
	} else if (obj.attachEvent){ 
		var r = obj.attachEvent("on"+evType, fn); 
		return r; 
	} else { 
		return false; 
	} 
}


addEvent(window, 'scroll', function(){
 if(document.getElementById('popup').style.display == "block")
	openPopUp();
})
						
						
						