var DSTORE_WEBSERVICE_BASEURL = "http://dstore.divino.de/restapi?Version=200812&AccessKeyID=12C710614770A21F23F966D8058F4CE534A7549A";
var TimeOut = new Object();

// siehe => http://docs.jquery.com/Using_jQuery_with_Other_Libraries
jQuery.noConflict();

jQuery(document).ready(function(){
	jQuery('#ProductLayer').mouseover(function(){
		clearTimeout(hideProductTimeOut);
	});
	
	jQuery('#ProductLayer').mouseout(function(){
		HideProductsLayer();
	});
	
	jQuery('#ProductLayer').click(function(){
		HideProductsLayer();
	});
});


// MousePosition in einem Objekt speichern
var	position=new Object();

var docEl = (
	typeof document.compatMode != "undefined" 
	&& 
	document.compatMode        != "BackCompat"
)? "documentElement" : "body";

function init_mousemove() 
{
	if(document.layers)
	{
		document.captureEvents(Event.MOUSEMOVE);
	}
	document.onmousemove =	dpl_mouse_pos;
} // function init_mousemove()

function dpl_mouse_pos(e) 
{
    // position where mousemove fired
    var xPos    =  e? e.pageX : window.event.x;
    var yPos    =  e? e.pageY : window.event.y;

	// Abstand in Pixel des MousePointers zum sichtbaren Browserbereich
	YOffset = jQuery(document).scrollTop();
	position.yy=yPos-YOffset;
	    
    // display position
	position.x=xPos;
	position.y=yPos;

    if (document.layers)
    { 
    	routeEvent(e);
    }
} // function dpl_mouse_pos(e) 

function markFields(ids, className) {
	var idArray = ids.split("¶");
	for(var i = 0; i < idArray.length; i++) {
		document.getElementById(idArray[i]).className = className;
	} // for(var i = 0; i < idArray.length; i ++)
} // function markFields()

//NewsSlideshow Funktionen
var i=0;
var slidesArray = new Array();
var slidesIconOnArray = new Array();
var slidesIconOffArray = new Array();
var elements=0;
var next=true;

function initSlideshow(PostingsCount) {
	if(document.getElementById('SlideshowElement1')){
		elements=PostingsCount;  	
	 	a=1;
	 	while(a <= elements){
	 		slidesArray.push('SlideshowElement'+a);
	 		slidesIconOnArray.push('SlideshowIconOn'+a);
	 		slidesIconOffArray.push('SlideshowIconOff'+a);
	 		a++;
	 	}
	 	startSlideshow();	
	} else {
		setTimeout('initSlideshow('+PostingsCount+')', 1000);
	}
}
function startSlideshow(){
	slideshow = setInterval('nextSlideshowElement()', 5000);
}
function restartSlideshow(){
	startSlideshow();
}
function stopSlideshow(){
	window.clearInterval(slideshow);
}

function nextSlideshowElement() {
	Effect.Fade(slidesArray[i], {duration:0.5,from:1.0,to:0.0});
	Effect.Fade(slidesIconOnArray[i], {duration:0.5,from:1.0,to:0.0});
  i++;
  if(i==elements){ i=0; }
  Effect.Appear(slidesArray[i], {duration:0.5,from:0.0,to:1.0});
  Effect.Appear(slidesIconOnArray[i], {duration:0.5,from:0.0,to:1.0});	
}
function showSlideshowElement(j) {
	j=j-1;
	Effect.Fade(slidesArray[i], {duration:0.5,from:1.0,to:0.0});
	Effect.Fade(slidesIconOnArray[i], {duration:0.5,from:1.0,to:0.0});
	i=j;
	if(i==elements){ i=0; }
  Effect.Appear(slidesArray[j], {duration:0.5,from:0.0,to:1.0});
  Effect.Appear(slidesIconOnArray[j], {duration:0.5,from:0.0,to:1.0});	
}
function showDiv(divID){
	Effect.Appear(divID, {duration:0.5,from:0.0,to:1.0});		
}
function hideDiv(divID){
	Effect.Fade(divID, {duration:0.0,from:1.0,to:0.0});	
}


//Function showDivPopUp
var openDivID = "";
var tmpTimeOut = 1;
function showDivPopUp(divName,divID,divCount){
	if(openDivID!="" && openDivID!=divName+divID){
		Effect.Fade(openDivID, {duration:0.0,from:1.0,to:0.0});
	}
	if(openDivID=="" || openDivID!=divName+divID){
		Effect.Appear(divName+divID, {duration:0.5,from:0.0,to:1.0});
	}
	openDivID = divName+divID;
	a=1;
	while(a <= divCount){
		if(openDivID!=divName+a){
			Effect.Fade(divName+a, {duration:0.0,from:1.0,to:0.0});
		}
		a++;
	}	
}
function hideDivPopUp(){
	Effect.Fade(openDivID, {duration:0.0,from:1.0,to:0.0});
	openDivID = "";
}

//Funktion um Overlays anzuzeigen
//Inclusive Blockiervariable
var lastProductOverlayID = '';
var productOverlayTimeout;
var ProductOverlayBlock = false;
function appearProductOverlay(divID)
{
	clearTimeout(productOverlayTimeout);
	productOverlayTimeout = setTimeout('appearProductOverlayTimed("'+divID+'")',100);
}
function clearAppearProductOverlayTimeout()
{
	clearTimeout(productOverlayTimeout);
}
function appearProductOverlayTimed(divID)
{
	if(ProductOverlayBlock == false)
	{
		ProductOverlayBlock = true;
		if(lastProductOverlayID!='')
		{
			var div = document.getElementById(lastProductOverlayID);
			div.style.display = 'none';
		}
		lastProductOverlayID = divID;
		var div = document.getElementById(divID);
		new Effect.Appear(div, {duration: 0.3, from: 0.5, to: 1.0,
						afterFinish: 
							function() 
							{
								ProductOverlayBlock = false;								
							} 
					});
	} 
	return false;
}
function hideProductOverlay(divID)
{
	clearAppearProductOverlayTimeout();
	var div = document.getElementById(divID);
	div.style.display = 'none';
	return false;
}
function showProductOverlay(divID)
{
	var div = document.getElementById(divID);
	if(div.style.display != 'block')
		div.style.display = 'block';
	return false;
}

function artikelDrehen(){
	divFront=document.getElementById('frontside');
	divBack=document.getElementById('backside');
	if(divFront.style.display=="none"){
		Effect.Fade(divBack, {duration:0.0,from:1.0,to:0.0});
		Effect.Appear(divFront, {duration:0.0,from:0.0,to:1.0});
	}
	if(divBack.style.display=="none"){
		Effect.Fade(divFront, {duration:0.0,from:1.0,to:0.0});
		Effect.Appear(divBack, {duration:0.0,from:0.0,to:1.0});	
	}
}

function openPopup(url, PopupName, width, height) {
	popup = window.open(url, PopupName, 'width=' + width + ',height=' + height + ',scrollbars=yes,toolbar=no,location=no,menubar=no,resizable=yes');
	popup.focus();
}


function blindDownDiv(elementId) {
	elementObj = document.getElementById(elementId);
	new Effect.BlindDown(elementObj);
}
function blindUpDiv(elementId) {
	elementObj = document.getElementById(elementId);
	new Effect.BlindUp(elementObj);
}


var LastTreeNodeID = 0;
function ShowProductByTreeNodeID()
{
	if (tnid != LastTreeNodeID && tnid != 0)
	{	
		LastTreeNodeID = tnid;
	
		var ProductLayer = document.getElementById('ProductLayer');
		
		try
		{
		
			if (position.yy > 350)
			{
				ProductLayer.style.left = (position.x-175)+"px";
				ProductLayer.style.top = (position.y-350)+"px";
				ProductLayer.style.height="350px";
			}
			else
			{
				ProductLayer.style.left = (position.x-175)+"px";
				ProductLayer.style.top = (position.y+10)+"px";
				ProductLayer.style.height="350px";
			}
		}
		catch(e)
		{
			// Wenn die Seite noch nicht geladen ist gibt es noch keine
			// MousePos und dann darf das Overlay noch nicht angezeigt werden.
			return true;
		}
		
		var LayerContent = document.getElementById('LayerContent');
		LayerContent.style.display="none";
		
		var Uhr = document.getElementById('Uhr');
		Uhr.style.display="";
		Uhr.style.paddingTop="120px";
		Uhr.style.paddingBottom="120px";
		Uhr.style.paddingLeft="145px";
	
		Effect.Appear(ProductLayer, {duration:0.5,from:0.0,to:1.0});
	
		// daten senden
		jQuery.get
		(
			DSTORE_WEBSERVICE_BASEURL+'&Operation=SearchItems&Template=Product_Popup&TreeNodeID='+tnid+'&XSLTs=divinoStandardTransformation&Format=json&jsonp_callback=?',
			{
			},
			gotItemData,
			'jsonp'
		);
		
		
		
	}
} // function getItemData()


var tnid = 0;
var func = '';
var hideProductTimeOut = '';

function ShowProductLayers(TreeNodeID)
{
	clearTimeout(hideProductTimeOut);
	tnid = TreeNodeID;
	func = setTimeout('ShowProductByTreeNodeID()', 500);
}

function HideProductsLayer()
{
	clearTimeout(func);
	hideProductTimeOut = setTimeout('_hideProductsLayer()', 100);
}

function _hideProductsLayer()
{
	document.getElementById('ProductLayer').style.display='none';
	LastTreeNodeID = 0;
}


function gotItemData(json)
{
	var Vintage = document.getElementById('Vintage');
	var Vintage2 = document.getElementById('Vintage2');
	
	try
	{
		var VintageData = json.Result.Item.Vintage.$;
		if(VintageData != '')
		{
			Vintage.innerHTML = utf8_decode(VintageData);
			Vintage2.innerHTML = utf8_decode(VintageData);
		}
		else
		{
			Vintage.innerHTML = '';
			Vintage2.innerHTML = '';
		}
	}
	catch(e)
	{
		Vintage.innerHTML = '';
		Vintage2.innerHTML = '';
	}
		
		
	try
	{
		var LabelBig = document.getElementById('LabelBig'); 
		LabelBig.innerHTML = utf8_decode(json.Result.Item.LabelBig.$);
	}
	catch(e)
	{
		LabelBig.innerHTML = '';
	}

	
	try
	{
		var LabelSmall = document.getElementById('LabelSmall'); 
		LabelSmall.innerHTML = utf8_decode(json.Result.Item.LabelSmall.$);
	}
	catch(e)
	{
		LabelSmall.innerHTML = '';
	}
	
	var Trenner = false;
	var PictureTable = '';
	var PictureTableHead = '<table align="left" border="0" cellspacing="1" cellpadding="1"><tr align="center">';
	var PictureTableFoot = '</tr></table>';
	var PictureTable1 = '';
	var PictureTable2 = '';
	var PictureTable3 = '';
	var PictureTable4 = '';
	var PictureTable5 = '';
	 
	try
	{
		if (json.Result.Item.ProductionMethod.$ != 'Balsamessig' && json.Result.Item.ProductionMethod.$.substr(0,6) != 'Oliven')
		{
			PictureTable1 = '<td align="center" valign="top" style="width:65px;" id="t1"><img style="background: #FFFFFF;" class="product" src="'+json.Result.Item.ProductionMethod["@LinkToBinary"]+'"/></td>';
			Trenner=true;
		}
	}
	catch(e)
	{
		PictureTable1 = '';
	}
	
	try
	{
		if (Trenner == true)
		{
			PictureTable2 = '<td style="background: url(http://www.divino.de/customGates/resources/binaries/backgrounds/bg_verticale_trennlinie.png) repeat-y;"></td><td align="center" valign="top" style="width:65px;"><img style="background: #FFFFFF;" class="product" src="'+json.Result.Item.Trait["@LinkToBinary"]+'"/></td>';
		}
		else
		{	
			PictureTable2 = '<td align="center" valign="top" style="width:65px;" id="t2"><img style="background: #FFFFFF;" class="product" src="'+json.Result.Item.Trait["@LinkToBinary"]+'"/></td>';
		}
		Trenner = true;
	}
	catch(e)
	{
		PictureTable2 = '';
	}
	
	try
	{
		if (Trenner == true)
		{
			PictureTable3 = '<td style="background: url(http://www.divino.de/customGates/resources/binaries/backgrounds/bg_verticale_trennlinie.png) repeat-y;"></td><td align="center" valign="top" style="width:65px;"><img style="background: #FFFFFF;" class="product" src="'+json.Result.Item.Storage["@LinkToBinary"]+'"/></td>';
		}
		else
		{	
			PictureTable3 = '<td align="center" valign="top" style="width:65px;" id="t3"><img style="background: #FFFFFF;" class="product" src="'+json.Result.Item.Storage["@LinkToBinary"]+'"/></td>';
		}
		Trenner = true;
	}
	catch(e)
	{
		PictureTable3 = '';
	}

	try
	{
		if (Trenner == true)
		{
			if (json.Result.Item.Country.$ != 'Probierpakete' && json.Result.Item.ProductionMethod.$ != 'Balsamessig' && json.Result.Item.ProductionMethod.$.substr(0,6) != 'Oliven')
				PictureTable4 = '<td style="background: url(http://www.divino.de/customGates/resources/binaries/backgrounds/bg_verticale_trennlinie.png) repeat-y;"></td><td align="center" valign="top" style="width:65px;"><img style="background: #FFFFFF;" class="product" src="'+json.Result.Item.Country["@LinkToBinary"]+'"/></td>';
		}
		else
		{	
			if (json.Result.Item.Country.$ != 'Probierpakete' && json.Result.Item.ProductionMethod.$ != 'Balsamessig' && json.Result.Item.ProductionMethod.$.substr(0,6) != 'Oliven')
				PictureTable4 = '<td align="center" valign="top" style="width:65px;" id="t4"><img style="background: #FFFFFF;" class="product" src="'+json.Result.Item.Country["@LinkToBinary"]+'"/></td>';
		}
		Trenner = true;
	}
	catch(e)
	{
		PictureTable4 = '';
	}
	
	
	try
	{
		if (Trenner == true)
		{
			PictureTable5 = '<td style="background: url(http://www.divino.de/customGates/resources/binaries/backgrounds/bg_verticale_trennlinie.png) repeat-y;"></td><td align="center" valign="top" style="width:65px;"><img style="background: #FFFFFF;" class="product" src="'+json.Result.Item.WinegrowerSize["@LinkToBinary"]+'"/></td>';
		}
		else
		{	
			PictureTable5 = '<td align="center" valign="top" style="width:65px;" id="t5"><img style="background: #FFFFFF;" class="product" src="'+json.Result.Item.WinegrowerSize["@LinkToBinary"]+'"/></td>';
		}
		Trenner = true;
	}
	catch(e)
	{
		PictureTable5 = '';
	}
	
	if (PictureTable1 != '' || PictureTable2 != '' || PictureTable3 != '' || PictureTable4 != '' || PictureTable5 != '')
	{
		PictureTable = PictureTableHead;
		PictureTable += PictureTable1;
		PictureTable += PictureTable2;
		PictureTable += PictureTable3;
		PictureTable += PictureTable4;
		PictureTable += PictureTable5;
		PictureTable += PictureTableFoot;
		document.getElementById('PictureTable').innerHTML = PictureTable;	
	}
	else
	{
		document.getElementById('PictureTable').innerHTML = PictureTable;
	}

	try
	{
		var Details = document.getElementById('Details');
		var ProductInfo = json.Result.Item.ProductInfo.$;
		ProductInfo = Trim(ProductInfo);
		
		var Absaetze = ProductInfo.split('\n');
		Details.innerHTML = utf8_decode(Absaetze[0]);
	}
	catch(e)
	{
		Details.innerHTML = '';
	}


	
	try
	{
		var Winegrower = document.getElementById('Winegrower'); 
		Winegrower.innerHTML = utf8_decode(json.Result.Item.Winegrower.$);
	}
	catch(e)
	{
		Winegrower.innerHTML = '';
	}


	var PricesHTML = '<table border="0" cellspacing="0" cellpadding="0">';
	
	
	try
	{
		var SingleVariantTreeNodeID = json.Result.Item.Variants.Variant["@TreeNodeID"];
		var SingleVariantPrice = json.Result.Item.Variants.Variant.Verkaufspreis_EUR.$
		SingleVariantPrice = PreisFormat(SingleVariantPrice);
		var SingleVariantPackage = json.Result.Item.Variants.Variant.PackageSize.$
		
		PricesHTML = PricesHTML + '<tr><td><span class="lucida size_popup_facts color_black">'+utf8_decode(SingleVariantPackage)+':</span></td>';
		PricesHTML = PricesHTML + '<td align="left" style="padding-left:5px; padding-right:3px;"><span class="lucida size_popup_facts color_red">&euro;</span></td>';
		PricesHTML = PricesHTML + '<td align="right"><span class="lucida size_popup_facts color_red">'+SingleVariantPrice+'</span></td></tr>';
		PricesHTML = PricesHTML + '</table>';
		
		var Prices = document.getElementById('Prices'); 
		Prices.innerHTML = PricesHTML;
	}
	catch(e)
	{
		SingleVariantTreeNodeID = 0;
	}

	if (SingleVariantTreeNodeID == 0)
	{
		for (var VariantID in json.Result.Item.Variants.Variant)
		{
			if (VariantID >= 0)
			{	
				var Preis = json.Result.Item.Variants.Variant[VariantID].Verkaufspreis_EUR.$;
				FPreis = PreisFormat(Preis);
				if (FPreis != '0,00')
				{	
				
					var PackageSize = utf8_decode(json.Result.Item.Variants.Variant[VariantID].PackageSize.$)
					var FlaschenPreis = '';
				
					// Flaschenpreis
					if (PackageSize.substr(0,3) == '6er')
					{
						var FlaschenPreis = '&nbsp;(pro Flasche &euro; '+PreisFormat(Preis/6)+')';
					}
					
					// Flaschenpreis
					if (PackageSize.substr(0,3) == '12e')
					{
						var FlaschenPreis = '&nbsp;(pro Flasche &euro; '+PreisFormat(Preis/12)+')';
					}
					
					// Literpreis
					if (PackageSize.substr(0,3) == 'Ein')
					{
						var Ergebnis = PackageSize.match(/\([0-9]{1}[\,]?[0-9]{0,3}l\)/);

						if (Ergebnis)
						{
							var Ergebnis2 = Ergebnis[0].match(/[0-9]{1}[\,]?[0-9]{0,3}/);
							
							if (Ergebnis2)
							{
								var Divisor = parseFloat(Ergebnis2[0].replace(',','.'));
								var LiterPreis = Preis*(1/Divisor);
								var FlaschenPreis = '&nbsp;(Preis pro Liter &euro; '+PreisFormat(LiterPreis)+')';
							} // if (Ergebnis2)
						} // if (Ergebnis)
					} // if (PackageSize.substr(0,3) == 'Ein')
					
					PricesHTML = PricesHTML + '<tr><td><span class="lucida size_popup_facts color_black">'+utf8_decode(json.Result.Item.Variants.Variant[VariantID].PackageSize.$)+':</span></td>';
					PricesHTML = PricesHTML + '<td align="left" style="padding-left:5px; padding-right:3px;"><span class="lucida size_popup_facts color_red">&euro;</span></td>';
					PricesHTML = PricesHTML + '<td align="right"><span class="lucida size_popup_facts color_red">'+FPreis+'</span></td>';
					PricesHTML = PricesHTML + '<td><span class="lucida size_popup_facts">'+FlaschenPreis+'</span></td></tr>';
				}
			}	
		}
		PricesHTML = PricesHTML + '</table>';	
		var Prices = document.getElementById('Prices'); 
		Prices.innerHTML = PricesHTML;
	} // if (SingleVariantTreeNodeID <= 0)	
		
	var Uhr = document.getElementById('Uhr');
	Uhr.style.display="none";
	
	var LayerContent = document.getElementById('LayerContent');
	LayerContent.style.display="";

} // function gotItemData(json)

function PreisFormat(zahl) 
{
    wert = parseInt(zahl * 1000);
    wert = wert / 1000;
    wert = wert.toFixed(2);
    return wert.replace(/\./,',');
    
} // function PreisFormat(zahl) 

function checkBrowserName(name){   
	var agent = navigator.userAgent.toLowerCase();  

	if (agent.indexOf(name.toLowerCase())>-1) 
	{   
		return true;   
	}   
	return false;   
}

function utf8_decode(utftext) 
{
	utftext = unescape(utftext);


	// Ganz toll alle Browser brauchen kein Decode... nur der IE mal wieder
	if(checkBrowserName('MSIE 6'))
	{   
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}
		
		i=0;
		var iestring ='';
		while ( i < string.length ) 
		{
			c = string.charCodeAt(i);
		
			if (c == 248)
				iestring += '&szlig;';
			else if (c == 240)
				iestring += '&Eacute;';
			else
				iestring += String.fromCharCode(c);

			i++;
		}
		
		return iestring;
	}
	else
		return utftext;
}
function textareaMaxLength(textareaElement,maxLength){
	if(textareaElement.value.length > maxLength)
		textareaElement.value=textareaElement.value.substring(0,maxLength)
}
 
function Trim(s) 
{
	// Remove leading spaces and carriage returns
	while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
	{ 
		s = s.substring(1,s.length); 
	} // while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
     
   	// Remove trailing spaces and carriage returns
 	while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
	{ 
		s = s.substring(0,s.length-1); 
	} // while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
   	return s;
}

function showDeselect(TableID)
{
	var NaviTable = document.getElementById(TableID);
	TablePos = getAbsoluteElementPosition(NaviTable);
	clearTimeout(TimeOut[TableID]);

	var elem = jQuery('#'+TableID+' .deleteFilter');
	if(elem.length > 0)
	{
		elem.css('display', '');
	}
	
	if (
		TableID == 'ProductionMethod' && ProductionMethod == true
		||
		TableID == 'Region' && Region == true
		||
		TableID == 'Anlass' && Anlass == true
		||
		TableID == 'Country' && Country == true
		||
		TableID == 'Rebsorte' && Rebsorte == true
		)
	{
		if (jQuery('#removeDiv').css('display') == 'none')
		{
			jQuery('#removeDiv').css('top',TablePos.y+'px');
			jQuery('#removeDiv').css('left',TablePos.x+130+'px');
			jQuery('#removeDiv').css('display','');
			jQuery('#removeLink').attr('href',FilterUrl+'&remove='+TableID);
		} // if (jQuery('#removeDiv').css('display') == 'none')
	} // if (TableID == 'ProductionMethod' && ProductionMethod == true ||
	else
		jQuery('#removeDiv').css('display','none');
} // function showDeselect(TableID)

function hideCross(ID)
{
	var elem = jQuery('#'+ID+' .deleteFilter');
	if(elem.length > 0)
	{
		elem.css('display', 'none');
	}
	//jQuery('#removeDiv').css('display','none');
}

function hideDeselect(ID)
{
	TimeOut[ID] = setTimeout('hideCross("'+ID+'")',300);
}

function getAbsoluteElementPosition(element)
{
	var elem=element,tagname="",x=0,y=0;

	while ((typeof(elem)=="object")&&(typeof(elem.tagName)!="undefined"))
	{
		y+=elem.offsetTop;     /* Offset des jeweiligen Elements addieren */
		x+=elem.offsetLeft;    /* Offset des jeweiligen Elements addieren */
		tagname=elem.tagName.toUpperCase(); /* tag-Name ermitteln, Grossbuchstaben */

		if (tagname=="BODY")
			elem=0;

		if (typeof(elem)=="object")
			if (typeof(elem.offsetParent)=="object")
				elem=elem.offsetParent;
	}

	position=new Object();
	position.x=x;
	position.y=y;
	return position;
} // function getAbsoluteElementPosition(element)
