//*************************************************************************************************
// Geert Dekkers Web Studio 2006, 2007
// _menuBuilder.js
// Builds link menus
// 
//*************************************************************************************************
function buildMenu(linkID,posX,posY,pulldownName,listName,listItemName,cartName){
	
	var uniqueID = pulldownName;
	if($(uniqueID)){
		$('content').removeChild($(uniqueID));
	
		}
if(!$(uniqueID)){

	
	var contentPath = "index.php?p=";
	
	pulldownName = document.createElement("div");
	pulldownName.className = "pullDownMenu";
	pulldownName.title = "Klik om te sluiten";
	pulldownName.id = uniqueID;
	pulldownName.style.position = "absolute";
	pulldownName.style.top = (posY + 35) + "px";
	pulldownName.style.left = posX + "px";
	pulldownName.onclick = function(){removePulldown();};
	listName = document.createElement("ul");
	listName.className = "pulldownMenuList";
	$(linkID).title = cartName.items[0].lText;
	
	for (i=0;i<cartName.items.length;i++){
		listItemName = document.createElement("li");
		listItemName.className = "pulldownMenuListItem";
		var lText = document.createTextNode(cartName.items[i].lText);
		var a = document.createElement("a");
		a.href = contentPath + cartName.items[i].lLink;
		a.title = cartName.items[i].lTitle;
		a.className = "pulldownMenuListItemLink";
		a.appendChild(lText);
		listItemName.appendChild(a);
		listName.appendChild(listItemName);
	}
	
	pulldownName.appendChild(listName);
	$('content').appendChild(pulldownName);


	}else{
		
		$('content').removeChild($(uniqueID));
	
	}
	
	//setTimeout("removePulldown()",5000);
	
}


function removePulldown(){
	if($('a')){
		$('content').removeChild($('a'));
	}
}

function findPos(obj) {
	
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return [curleft,curtop];
}

// This function presents the contact menu
function showContactMenu(element){
	var tTextTelefoon = document.createTextNode("Telefoon: 024-360 54 52");
	var tTextTelefoonEmailLink = document.createTextNode("info@ippsy.nl");
	var a = document.createElement("a");
	a.href= "mailto:info@ippsy.nl";
	a.appendChild(tTextTelefoonEmailLink);
	var d1 = document.createElement("li");
	var d2 = document.createElement("li");
	d1.appendChild(tTextTelefoon);
	d2.appendChild(a);

	if(!$('contactMenu')){
		var d0 = document.createElement("ul");
		d0.id = "contactMenu";
		d0.appendChild(d1);
		d0.appendChild(d2);
		$(element).appendChild(d0);
	}else{
		$(element).removeChild($('contactMenu'));
	}
	
}

function buildCrumbsPath(cartName,linkNumber, itemNumber){
	//*****************************************
	// cartName string
	// linkNumber integer
	// itemNumber integer
	// returns HTML
	//*****************************************

	var n = document.createElement("a");
	n.name = linkNumber + 1;
	
	var d = document.createElement("div");
	d.className = "subheaderCrumbPath";
	var dText = document.createTextNode(linkTitles[linkNumber]);
	d.appendChild(dText);
	d.appendChild(n);
	var contentPath = "index.php?p=";
	
	var crumbsPath = document.createElement("div");
	crumbsPath.className = "crumbsPathMenu";
	crumbsPath.id = "crumbsPathMenu" + linkNumber;
	
	
	var listName = document.createElement("ul");
	listName.className = "crumbsPathList";
	
	for (i=0;i<cartName.items.length;i++){
		var listItemName = document.createElement("li");
		listItemName.className = "crumbsPathMenuListItem";
		var lArrow = document.createTextNode(" | ");
		var lText = document.createTextNode(cartName.items[i].lText);
		if (i != itemNumber){
		var a = document.createElement("a");
		a.href = contentPath + cartName.items[i].lLink;
		a.title = cartName.items[i].lTitle;
		a.className = "crumbsPathMenuListItemLink";
		a.appendChild(lText);
		listItemName.appendChild(lArrow);
		listItemName.appendChild(a);
		}else{
			listItemName.className = "crumbsPathMenuListItemNoLink";
			listItemName.appendChild(lArrow);
			listItemName.appendChild(lText);
		}
		
		listName.appendChild(listItemName);
	}
	
	crumbsPath.appendChild(d);
	crumbsPath.appendChild(listName);
	$('content_index_body').appendChild(crumbsPath);
	
	
	
}

function buildLink(cartNumber, item){
	var main = "index.php?p=";
	var cart = eval('cart' + cartNumber);
	location.href = main + cart.items[item].lLink;
	
}


function buildReferencePopup(posx, posy, element){

	element.style.top = (posx + 16) + "px";
	element.style.left = posy + "px";
	Effect.Appear(element);
}