/**
 * Fancy dropdown med <select> fallback
 *
 * @author Tommy Gildseth <tommy at apt no>
 * @version 1.0.0
 */
var timer = null;

function FancyDropDown( id ) {
	// Member variables
	this.objDropDown = null;
	this.arrValues = new Array();
	this.objList = null;
	this.objDDParent = null;
	this.objList = null;

	// Methods
	this.getValues = getValues;
	this.addValues = addValues;
	this.render = render;

	elem = document.getElementById(id);
	if ( elem ) {
		this.objDDParent = elem.parentNode;
		this.objDropDown = elem;
		this.objDropDown.style.display = 'none';
		this.getValues();
	}
}

function getValues( ) {
	if (this.objDropDown) {
		for(i = 0; this.objDropDown.options.length > i; ++i) {
			option = this.objDropDown.options[i];
			this.arrValues.push([option.text, option.value, option.title]);
		}
	}
}

function addValues( url, text, title ) {
	this.arrValues.push([text, url, title]);
}

function render( ) {
	strHTML = '';
	if (this.arrValues.length) {
		div = document.createElement('div');
		div.style.display = 'none';
		list = document.createElement('ul');
		div.onmouseout = function () { mouseOut(div); };
		div.onmousemove = mousemove;
		div.appendChild(list);
		val = this.arrValues;
		for(i = 0; this.arrValues.length > i; ++i) {
			if (val[i][1] != val[i][0] && val[i][1] != '') {
				li = document.createElement('li');
				link = document.createElement('a');
				link.href = val[i][1];
				link.target = val[i][2];
				link.appendChild(document.createTextNode(val[i][0]));
				li.appendChild(link);
				li.onmousemove = mousemove;
				list.appendChild(li);
			} else {
				span = document.createElement('span');
				text = document.createTextNode(val[i][0]);
				span.appendChild(text);
				span.onclick = function () { listOnclick(div); };
				span.onmouseover = function () { buttonHover(span); };
				span.onmouseout = function () { buttonUnHover(span); };
				this.objDDParent.replaceChild(span, this.objDropDown)
			}
		}
	}

	if (this.objDDParent) {
		this.objDDParent.appendChild(div);
	}
}

function buttonHover( span ) {
	span.className = 'hover';
}
function buttonUnHover( span ) {
	span.className = '';
}


function listOnclick( list ) {
	list.style.display = 'inline';
}


function mousemove() {
	clearTimeout(timer);
}

function mouseOut(id) {
	timer = setTimeout(function () { id.style.display = 'none'; }, 1000);
}

function go(url, target) {
	if (target == '_blank') {
		window.open(url)
	}
	else {
		document.location.href = url
	}
}

/* Noe julekampanje 27.11.2006 - Tommy Paulsen*/
function MM_openBrWindow(theURL,winName,features) 
{
	window.open(theURL,winName,features);
}

$(document).ready(function() {
	document.getElementById('headerSok').style.paddingRight = '120px'
	dd = new FancyDropDown('andreNettsteder');
	dd.render();
});