if(window.navigator.appName.toLowerCase().indexOf("netscape") == -1)
{
	window.attachEvent("onload", AddLogoLink);
	window.attachEvent("onload", InitPopUpInfo);
}
else
{
	// Netscape
	window.addEventListener("load", AddLogoLink, true);
	window.addEventListener("load", InitPopUpInfo, true); 
}

// Link telia logo to startpage
function AddLogoLink()
{
	var logo = document.getElementById("telia_logo");
	if(logo)
	{
		logo.onclick = function()
		{
			window.location.href = "http://www.telia.se";
		}
		// window.scrollTo(0,0);
	}
}



// FAQ expander
function ShowContent(contentAnchor)
{
	var contentBlock = contentAnchor.parentNode.getElementsByTagName("div")[0];

	if(contentBlock.style.display == "block")
	{
		contentAnchor.className = "blockAnchor";
		contentBlock.style.display = "none";
	}
	else
	{
		contentAnchor.className = "blockAnchorExpanded";
		contentBlock.style.display = "block";
	}
	
	return false;
}



// Content tab menu
document.observe("dom:loaded", function() {
	$$('ul.contentMenu li a').each(function(element) {
		Event.observe(element, 'click', function(event) {
			Event.stop(event);
			$$('ul.contentMenu li.current').each(function(element) {
				element.removeClassName('current');
			});
			element.up().addClassName('current');
			
			var target = element.readAttribute('href');
			var targetAnchor = target.substring(target.indexOf('#')+1, target.length);
			var anchors = $$('a[name]');
			
			anchors.each(function(element) {
				if (targetAnchor == element.readAttribute('name')) {
					element.next('div.contentSection').addClassName('current');
				}
				else {
					element.next('div.contentSection').removeClassName('current');
				}
			});
		});
	});
	
	var tabNumber = Number(parent.document.URL.toQueryParams().tab);
	if(!isNaN(tabNumber) && (tabNumber > 0) && (tabNumber <= $$('ul.contentMenu li').length)) {
		$$('ul.contentMenu li.current').each(function(element) {
			element.removeClassName('current');
		});
		$$('ul.contentMenu li')[tabNumber-1].addClassName('current');
		
		var target = $$('ul.contentMenu li')[tabNumber-1].firstDescendant().readAttribute('href');
		var targetAnchor = target.substring(target.indexOf('#')+1, target.length);
		var anchors = $$('a[name]');
		
		anchors.each(function(element) {
			if (targetAnchor == element.readAttribute('name')) {
				element.next('div.contentSection').addClassName('current');
			}
			else {
				element.next('div.contentSection').removeClassName('current');
			}
		});
	}
});



// Popuplink-function
function InitPopUpInfo()
{
	InitObjects(document.links);
	InitObjects(document.images);
}

function InitObjects(objects)
{
	var documentLinks = objects;
	var popupLinks = new Array();

	for(i=0; i<documentLinks.length; i++)
	{
		if(documentLinks[i].className.indexOf("popupInfo") != -1)
			popupLinks.push(documentLinks[i]);
	}
	
	if(popupLinks.length > 0)
	{
		CreatePopupLayer();
	}
	else
	{
		return;
	}
	
	for(i=0; i<popupLinks.length; i++)
	{
		var popupInfoLayer = document.getElementById("popupInfoLayer");
		
		popupLinks[i].onmousemove = function(e)
		{
			if(this.active != true)
			{
				popupInfoLayer.style.visibility = "visible";
				var popupContent = document.getElementById("popupInfoText");
				
				popupContent.innerHTML = this.title;
				this.title = "";
			}
			
			if(window.navigator.appName.toLowerCase().indexOf("internet explorer") == -1)
			{
				popupInfoLayer.style.left = (e.pageX - 40) + "px";
				popupInfoLayer.style.top = (e.pageY - popupInfoLayer.clientHeight) + "px"; 
			}
			else
			{
				getMouseXY(e);
			
				// Lokalt?
				//popupInfoLayer.style.left = (window.event.x - 40 + window.parent.document.documentElement.scrollLeft) + "px";
				//popupInfoLayer.style.top = (window.event.y - 5 + window.parent.document.documentElement.scrollTop - popupInfoLayer.clientHeight) + "px";
				//popupInfoLayer.style.left = (window.event.x - 40 + document.body.scrollLeft) + "px";
				//popupInfoLayer.style.top = (window.event.y - 5 + document.body.scrollTop - popupInfoLayer.clientHeight) + "px";

				//popupInfoLayer.style.left = (mousex - 40 + window.parent.document.documentElement.scrollLeft) + "px";
				//popupInfoLayer.style.top = (mousey - 5 - popupInfoLayer.clientHeight + window.parent.document.documentElement.scrollTop) + "px";
				
				popupInfoLayer.style.left = (mousex - 40 + window.parent.document.documentElement.scrollLeft) + "px";
				popupInfoLayer.style.top = (mousey - 5 + window.parent.document.documentElement.scrollTop - popupInfoLayer.clientHeight) + "px";


			}	
		
			this.active = true;
		}

		popupLinks[i].onmouseout = function()
		{
			var popupContent = document.getElementById("popupInfoText");
			this.title = popupContent.innerHTML;
			popupInfoLayer.style.visibility = "hidden";
			this.active = false;
		}
		
//		popupLinks[i].onclick = function()
//		{
//			return false;
//		}
	}
	
}



function CreatePopupLayer()
{
	var popupInfoLayer = document.createElement("div");
	popupInfoLayer.id = "popupInfoLayer";
	popupInfoLayer.style.position = "absolute"; 
	popupInfoLayer.style.visibility = "hidden"; 
	popupInfoLayer.style.width = "272px"; 
	popupInfoLayer.innerHTML = "<img src=\"/images/popuptop.png\" style=\"width:272px; height:10px;\" class=\"pngfix\"/><div id=\"popupInfoText\" style=\"background-image:url(/images/popupmiddle.png); color:#ffffff; padding-left:11px; padding-right:14px; font-size:11px;\" class=\"pngfix\"></div><img src=\"/images/popupbottom.png\" style=\"width:272px; height:42px;\" class=\"pngfix\" />";
	document.body.appendChild(popupInfoLayer);

}


var mousex = 0;
var mousey = 0;
var algor = 0;

function getMouseXY(e) // works on IE6,FF,Moz,Opera7
{ 
  if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us the event)

  if (e)
  { 
    if (e.pageX || e.pageY)
    { // this doesn't work on IE6!! (works on FF,Moz,Opera7)
      mousex = e.pageX;
      mousey = e.pageY;
      algor = '[e.pageX]';
      if (e.clientX || e.clientY) algor += ' [e.clientX] ';
    }
    else if (e.clientX || e.clientY)
    { // works on IE6,FF,Moz,Opera7
			// Lokalt?
      mousex = e.clientX + document.body.scrollLeft;
      mousey = e.clientY + document.body.scrollTop;
      algor = '[e.clientX]';
      if (e.pageX || e.pageY) algor += ' [e.pageX] ';
    }  
  }
}
