// Browser check
var ie5 = document.all&&document.getElementById;
var ns6 = document.getElementById&&!document.all;

// Colors for image mouse-over - might become obsolete
var newColor = '#D8242D';
var oldColor = '#ffffff';

// Change the look of image
function focusImage(pic_name,pic_src) {
	document[pic_name].src = pic_src;
	document[pic_name].style.borderColor = newColor;
}

// Change back the look of image
function blurImage(pic_name,pic_src) {
	document[pic_name].src = pic_src;
	document[pic_name].style.borderColor = oldColor;
}

// Open new window
function winPopUp(URL,name,width,height) {
	width = width+20;
	height = height+27;
	window.open(URL,name,'width='+width+',height='+height+',screenX=100,screenY=100,top=100,left=100');
}

/*
*	Script that displays the menu for www.alight.dk
*	Written by mads@nordholm.dk
*/

function drawMenu() {
	var menuStyle = "font-size: 10px; font-weight: bold";
	document.write(
		"<div id='menu' style='position: absolute; visibility: visible; top: 64px; right: 10px;' class='menulinks'>"+
		"<img id='mp1' src='images/spacer.gif'><a href='#' onmouseover='showMenu(0)' style='"+menuStyle+"'>ABOUT ALIGHT</a>"+
		"<img id='mp2' src='images/spacer.gif'><a href='#' onmouseover='showMenu(1)' style='"+menuStyle+"'>PRODUCTS & SERVICES</a>"+
		"<img src='images/spacer.gif'><a href='index.htm?id=6' style='"+menuStyle+"'>APPLICATIONS</a>"+
		"<img id='mp3' src='images/spacer.gif'><a href='#' onmouseover='showMenu(2)' style='"+menuStyle+"'>PEOPLE IN ALIGHT</a>"+
		"<img src='images/spacer.gif'><a href='index.htm?id=9' style='"+menuStyle+"'>INVESTORS</a>"+
		"<img src='images/spacer.gif'><a href='index.htm?id=10' style='"+menuStyle+"'>IN THE PRESS</a>"+
		"<img id='mp4' src='images/spacer.gif'><a href='#' onmouseover='showMenu(3)' style='"+menuStyle+"'>CONTACT</a>"+
		"</div>"
		);
}
drawMenu();

// Set variables;
var subItems = new Array(
					// About Alight
					"<a href='index.htm?id=1' class='dropItem'>Profile</a>"+
					"<a href='index.htm?id=2' class='dropItem'>History</a>",
					// Our Technology
					"<a href='index.htm?id=3' class='dropItem'>Products</a>"+
					"<a href='index.htm?id=4' class='dropItem'>License</a>"+
					"<a href='index.htm?id=5' class='dropItem'>PBG Technology</a>",
					// People in Alight
					"<a href='index.htm?id=7' class='dropItem'>Management</a>"+
					"<a href='index.htm?id=8' class='dropItem'>The Board</a>",
					// Contact
					"<a href='index.htm?id=11' class='dropItem'>Jobs</a>"+
					"<a href='index.htm?id=12' class='dropItem'>Our office</a>"
					);
function drawSubs() {
	for(var n=0;n<subItems.length;n++) {
		var divStart = "<div id='sub"+n+"' style='position: absolute; visibility: hidden; top: 84px'>";
		document.write(
			divStart+
			subItems[n]+
			"</div>"
			);
	}
}
drawSubs();

function hideMenu() {
	for(var n=0;n<subItems.length;n++) {
		var sub = document.getElementById('sub'+n);
		sub.style.visibility = 'hidden';
	}
}

function showMenu(which) {
	hideMenu();
	var n = which + 1;
	var sub = document.getElementById("sub"+which);
	if(n<4) {
		var pic = document.getElementById('mp'+n);
		sub.style.left = pic.offsetLeft + pic.offsetParent.offsetLeft - 2;
	} else if(n==4) {
		sub.style.right = 10;
	}
	sub.style.visibility = 'visible';
}

/*
*	Then for creating some content for the pages
*	Written by mads@nordholm.dk
*/

// Function for extracting information from a URL-string
function getArgs() {
	var args = new Object();
	var query = location.search.substring(1);		// Get query string
	var pairs = query.split(",");					// Break at comma
	for(var i=0;i<pairs.length;i++) {
		var pos = pairs[i].indexOf("=");			// Look for "name=value"
		if(pos==-1) continue;						// If not found skip
		var argname = pairs[i].substring(0,pos);	// Extract the name
		var value = pairs[i].substring(pos+1);		// Extract the value
		args[argname] = unescape(value);			// Store as a property
	}
	return args;									// Return the object
}

// Function for displaying the content layer
function drawContent() {
	var args = getArgs();
	var id = (args.id) ? args.id : 0 ;
	var text = pageContents[id];
	document.write(
		"<div id='content' style='position: absolute; visibility: hidden; top: 125px; left: 0px; height: 50%; width: 100%; border: 0px solid #000; overflow: auto'>"+
		text+
		"</div>"
		);
}
drawContent();

// Function for adjusting the page items
function positionContent() {
	// Get the objects needed
	var top_table = document.getElementById('top_table');
	var content_cell = document.getElementById('content_cell');
	var catch_cell = document.getElementById('catch_cell');
	var ruler_cell = document.getElementById('ruler_cell');
	var bottom_cell = document.getElementById('bottom_cell');
	var bottom_table = document.getElementById('bottom_table');
	var content = document.getElementById('content');
	// First adjust the height of the content cell
	var winHeight = (ie5) ? document.body.clientHeight : window.innerHeight ;
	var newContentHeight = winHeight-(top_table.offsetHeight+catch_cell.offsetHeight+ruler_cell.offsetHeight+bottom_cell.offsetHeight);
	content_cell.style.height	= newContentHeight;
	// Then adjust the height of the content layer
	var new_height = content_cell.offsetHeight-30;
	content.style.height=new_height;
	content.style.visibility = 'visible';
	bottom_table.style.visibility = 'visible';
	// If we are on the frontpage then position the frontpage logo
	var args = getArgs();
	if(args.id==0 || !args.id) {
		var front_pic = document.getElementById('front_pic');
		var padding = (content_cell.offsetHeight / 2) - (front_pic.offsetHeight / 2) - 40;
		content.style.paddingTop = (padding<0) ? 0 : padding ;
	}
	// Positioning the subs
	var topPad = document.getElementById('linealstk4').offsetParent.offsetParent.offsetTop + (document.getElementById('linealstk4').offsetHeight / 2);
	for(var n=0;n<subItems.length;n++) {
		var div = document.getElementById('sub'+n);
		topPadAd = topPad - div.offsetHeight / 2 + 2;
		div.style.top = topPadAd;
	}
}