/*
	Javascript for iBlock
	*********************
*/
var iBlockIv;
var iBlock;

function delayShow()
{
	clearInterval(iBlockIv);
	iBlock.style.display = "block";
}


function prepIBlocks()
{
	var elms = dojo.query(".i");
	
	// Create iBlock div
	iBlock = document.createElement("div");
	var iBlockContent = document.createElement("div");
	var iBlockBottom = document.createElement("div");
	iBlock.id = "iBlock";
	iBlockContent.id = "iBlockContent";
	iBlockBottom.id = "iBlockBottom";
	iBlock.appendChild(iBlockContent);
	iBlock.appendChild(iBlockBottom);
	document.getElementsByTagName("body")[0].appendChild(iBlock);
	
	
	for (i = 0; i < elms.length; i++)
	{
		var currElm = elms[i];
		
		currElm.onmouseover = function()
		{
			if (this.className == "i loadProductSpecs")
			{
				showLayer(this);
				var productCode = this.getAttribute("productcode");
				var library = this.getAttribute("library");
				var cElm = dojo.query(".c",this)[0];
				var label = this.getAttribute("label");
				loadProductSpecificationInfo(productCode, library, cElm, label);
			}
			else
			{
				showLayer(this);
			}
		}
		
		currElm.onmouseout = function()
		{
			clearTimeout(iBlockIv);
		}
	}
	
	iBlock.onmouseout = function()
	{
		hideLayer();
		classBehaviour.utilities.showSelects();	// For IE 6
	}
	
	function showLayer(elm)
	{
		var xPos = findPos(elm).x;
		var yPos = findPos(elm).y;
		
		classBehaviour.utilities.hideSelects();	// For IE 6
		
		var contentsElm = dojo.query(".c", elm)[0];
		
		iBlockContent.innerHTML = contentsElm.innerHTML;
		
		iBlock.style.top = yPos + "px";
		iBlock.style.left = xPos + "px";

		// Check if the content has a header
		var headerElm = elm.getElementsByTagName("h3")[0];
		if (!headerElm)
		{
			iBlockContent.className = "noHeader";
		}
		else
		{
			iBlockContent.className = "";
		}
		
		iBlockIv = setTimeout("delayShow()",500);
	}
	
	function hideLayer()
	{
		iBlock.style.display = "none"
	}
	
	function findPos( oElement ) {
		if( typeof( oElement.offsetParent ) != 'undefined' ) {
			for( var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent ) {
			posX += oElement.offsetLeft;
			posY += oElement.offsetTop;
		}
		return {x:posX, y:posY};
		} else {
			return {x:oElement.x, y:oElement.y};
		}
	}
	
	function loadProductSpecificationInfo(code, keyword, elementId, label)
	{
	  iBlockContent.innerHTML += ' Even geduld aub..';
    
		dojo.xhrGet({
			url: "/product/specificatie_info/" + code + "/" + keyword + ".html",
			load: function(data)
			{
				dojo.byId(elementId).innerHTML = '<h3>'+label	+'</h3>'+data;
				var parentElm = elementId.parentNode;
				parentElm.className = "i"
				showLayer(elementId.parentNode);
			},
			error: function (data)
			{
				dojo.byId(elementId).innerHTML = 'De informatie kon niet worden opgehaald.';
			}
		});      
	}
}

dojo.addOnLoad(
	function(){ 
		prepIBlocks()
	}
);

