function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();

jQuery.timer = function (interval, callback)
{
 var interval = interval || 100;

	if (!callback)
		return false;
	
	_timer = function (interval, callback) {
		this.stop = function () {
			clearInterval(self.id);
		};
		
		this.internalCallback = function () {
			callback(self);
		};
		
		this.reset = function (val) {
			if (self.id)
				clearInterval(self.id);
			
			var val = val || 100;
			this.id = setInterval(this.internalCallback, val);
		};
		
		this.interval = interval;
		this.id = setInterval(this.internalCallback, this.interval);
		
		var self = this;
	};
	
	return new _timer(interval, callback);
 };
 
function sndReq(action,lang,url) {
    var oriurl=url;
	if(url==1)url='/html/produkt_detail.php?grundid='+action+'&withoutright=1&lang='+lang;
	else if(url==2)url='/html/in_detail.php?anzeigen_id='+action+'&lang='+lang;
	else if(url==3)url='/html/ge_detail.php?anzeigen_id='+action+'&lang='+lang;
	else if(url==4)url='/html/h_lieferprogramm.php?h='+action+'&lang='+lang;
	else url='/html/cnh_detail.php?cnh='+action+'&lang='+lang;
	ladebalken();
	http.open('get', url, true);
    http.onreadystatechange = handleResponse;
    http.send(null);
	window.setTimeout('initBubble()',1000);
	
	//if(oriurl==1){pause(200);initBubble();}
}

function handleResponse() {
    if(http.readyState == 4 && document.getElementById('profilboxDetails')){
        //content
		var response = http.responseText;
		// prep objects
		var objProfilbox = document.getElementById('profilbox');
		var objSkyscraperdiv = document.getElementById('skyscraperdiv');
		var objProfilboxDetails = document.getElementById('profilboxDetails');
		var objgreylayer = document.getElementById('greylayer');
		var objladebalken = document.getElementById('ladebalken');
		var arrayPageSize = getPageSize();
		var arrayPageScroll = getPageScroll();
		// center profilbox  and make sure that the top and left values are not negative
		// and the content  placed outside the viewport
		var profilboxTop = (arrayPageScroll[1] + 30);
		var profilboxLeft = ((arrayPageSize[0] - 20 - 900) / 2);
		objProfilbox.style.top = (profilboxTop < 0) ? "0px" : profilboxTop + "px";
		objProfilbox.style.left = (profilboxLeft < 0) ? "0px" : profilboxLeft + "px";
		objProfilboxDetails.style.width = 900 + 'px';
		objProfilboxDetails.style.height = 500 + 'px';
		objProfilboxDetails.style.overflow = 'auto';
		
			// Hide select boxes as they will 'peek' through the image in IE
			selects = document.getElementsByTagName("select");
			for (i = 0; i != selects.length; i++) {
					selects[i].style.visibility = "hidden";
			}
		
		objProfilboxDetails.innerHTML = response;
		// A small pause between the image loading and displaying is required with IE,
			// this prevents the previous image displaying for a short burst causing flicker.
			if (navigator.appVersion.indexOf("MSIE")!=-1){
				pause(250);
			} 
	
		
		//objProfilbox.style.display = 'block';
		objSkyscraperdiv.style.display = 'none';
		objgreylayer.style.display = 'block';
		$("#profilbox").show("slow");
		// After image is loaded, update the overlay height as the new image might have
		// increased the overall page height.
		arrayPageSize = getPageSize();	
    }
}
			
function hideProfilbox()
{
	// get objects
	//objProfilbox = document.getElementById('profilbox');
	objSkyscraperdiv = document.getElementById('skyscraperdiv');
	objgreylayer = document.getElementById('greylayer');
	objladebalken = document.getElementById('ladebalken');
	objProfilboxDetails = document.getElementById('profilboxDetails');
	
	// hide profilbox
	//objProfilbox.style.display = 'none';
	//objProfilboxDetails.style.display = 'none';
	objgreylayer.style.display = 'none';
	objladebalken.style.display = 'none';
	objProfilboxDetails.innerHTML = "";	
	$("#profilbox").hide("slow");
	// make select boxes visible
	selects = document.getElementsByTagName("select");
    for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
	objSkyscraperdiv.style.display = 'block';
	// disable keypress listener
	document.onkeypress = '';
}

function initProfilbox()
{
	
	if (!document.getElementsByTagName){ return; }
	//var anchors = document.getElementsByTagName("a");

	// loop through all anchor tags
	//for (var i=0; i<anchors.length; i++){
		//var anchor = anchors[i];

		//if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "lightbox")){
			//anchor.onclick = function () {showLightbox(this); return false;}
		//}
	//}

	// the rest of this code inserts html at the top of the page that looks like this:
	//
	// <div id="profilbox">
	//		<a href="#" onclick="hideProfilbox(); return false;" title="Click anywhere to close">close</a>
	//		<div id="profilboxDetails">
	//			CONTENT
	//		</div>
	// </div>
	
	var objBody = document.getElementsByTagName("body").item(0);
	
	// create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	objOverlay.style.display = 'none';
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0';
	objOverlay.style.left = '0';
	objOverlay.style.zIndex = '60';
 	objOverlay.style.width = '100%';
	objBody.insertBefore(objOverlay, objBody.firstChild);
	
	// create profilbox  div, same note about styles as above
	var objProfilbox = document.createElement("div");
	objProfilbox.setAttribute('id','profilbox');
	objProfilbox.style.display = 'none';
	objProfilbox.style.position = 'absolute';
	objProfilbox.style.zIndex = '102';	
	objBody.insertBefore(objProfilbox, objBody.firstChild);

	// create details div, a container for the caption and keyboard message
	var objProfilboxDetails = document.createElement("div");
	objProfilboxDetails.setAttribute('id','profilboxDetails');
	objProfilbox.appendChild(objProfilboxDetails);
}

addLoadEvent(initProfilbox);	// run initProfilbox  onLoad
