var enableCache = true;
var jsCache = new Array();
var ajaxObjects = new Array();

var shopObject = false;
var shopObject_iframe = false;
var shopObject_IE = false;
if (navigator.userAgent.indexOf('MSIE') >= 0)
	shopObject_IE = true;

function showContent(divId,objectIndex,url) {
	document.getElementById(divId).innerHTML = ajaxObjects[objectIndex].response;
	if(enableCache){
		jsCache[url] = 	ajaxObjects[objectIndex].response;
	}
	ajaxObjects[objectIndex] = false;

}

function loadContent(divId,url) {
	if(enableCache && jsCache[url]){
		document.getElementById(divId).innerHTML = jsCache[url];
		return;
	}
		
	var objectIndex = ajaxObjects.length;
	document.getElementById(divId).innerHTML = 'Eintrag wird geladen ...';
	ajaxObjects[objectIndex] = new sack();
	ajaxObjects[objectIndex].requestFile = url;
	ajaxObjects[objectIndex].onCompletion = function() { 
		showContent(divId,objectIndex,url); 
	};
	ajaxObjects[objectIndex].runAJAX();
	
}

function showEntry(uid,inputObj) {

	if (!shopObject) {
	
		shopObject = document.createElement('div');
		shopObject.style.position = 'absolute';
		shopObject.style.display = 'block';
		shopObject.id = 'shopObject';		
		document.body.appendChild(shopObject);
		
		var arrowDiv = document.createElement('div');
		arrowDiv.className = 'shopObject_arrow';
		arrowDiv.id = 'shopObject_arrow';
		shopObject.appendChild(arrowDiv);
		
		var contentDiv = document.createElement('div');
		contentDiv.className = 'shopObject_content';
		contentDiv.id = 'shopObject_content';
		shopObject.appendChild(contentDiv);

		
		if(shopObject_IE) {
			shopObject_iframe = document.createElement('<iframe frameborder="0">');
			shopObject_iframe.style.position = 'absolute';
			shopObject_iframe.border='0';
			shopObject_iframe.frameborder=0;
			shopObject_iframe.style.backgroundColor='#fff';
			shopObject_iframe.src = 'about:blank';
			shopObject_iframe.style.left = '0';
			shopObject_iframe.style.top = '0';
			contentDiv.appendChild(shopObject_iframe);
		}

			
	}
	
	shopObject.style.display='block';
	loadContent('shopObject_content','index.php?id=4605&type=555&tx_sdmarket_pi1[uid]='+uid);
	if(shopObject_IE){
		shopObject_iframe.style.width = shopObject.clientWidth + 'px';
		shopObject_iframe.style.height = shopObject.clientHeight + 'px';
	}

	positionEntry(inputObj);
}

function positionEntry(inputObj) {
	var leftPos = (getLeftPos(inputObj) + inputObj.offsetWidth);
	var topPos = getTopPos(inputObj);
	

	var tooltipWidth = document.getElementById('shopObject_content').offsetWidth +  document.getElementById('shopObject_arrow').offsetWidth; 

	shopObject.style.left = leftPos + 'px';
	shopObject.style.top = topPos + 'px';
	
}

function getTopPos(inputObj) {		
	var returnValue = inputObj.offsetTop;
	while((inputObj = inputObj.offsetParent) != null) {
		if(inputObj.tagName!='HTML')returnValue += inputObj.offsetTop;
	}
	return returnValue;
}

function getLeftPos(inputObj) {
	var returnValue = inputObj.offsetLeft;
	while((inputObj = inputObj.offsetParent) != null){
		if(inputObj.tagName!='HTML')returnValue += inputObj.offsetLeft;
	}
	return returnValue;
}

function hideEntry() {
	shopObject.style.display='none';
}

