var xmlHttp = null;

function GetXmlHttpObject() {
	var objXMLHttp=null;
	if (window.XMLHttpRequest) {
		objXMLHttp=new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
}

var contactContent = '<form id="kontakt_send_besked" method="post" action="send_besked.php">\
	<div>\
		Send en besked til Design Concern A/S<br />\
		<br />\
		Emne<br />\
		<input type="text" name="subject" /><br />\
		Indhold<br />\
		<textarea name="body" cols="30" rows="5"></textarea><br />\
		<br />\
		<button type="submit">Send</button>\
	</div>\
</form>';

function getContact() {
	e = document.getElementById('underside_content_center');
	temp = e.innerHTML;
	e.innerHTML = contactContent;
	contactContent = temp;
}

/*---------------------------------------------------------------------------------------------------------------------*/

function headerInit() {
	headerFade = new Fader('headerFade', 'header1', 'header2', 50, 7000, 10, headerArray);
	setTimeout('headerFade.fade()', headerFade.timeWait);
}

function ImageList(random) {

	var images = new Array();
	var index = -1;

	this.add = function(imgPath) {
		images.push(imgPath);
	}

	this.next = function() {
		if (images.length > 1) {
			if (random) {
				do {
					next = Math.floor(Math.random() * images.length);
				} while (next == index);
				index = next;
			} else {
				index++;
				if (index >= images.length)
					index = 0;
			}
		}
		return images[index];
	}

	this.current = function() {
		return images[index];
	}
}

function Fader(faderName, divBottomName, divTopName, timeFade, timeWait, opacityStep, imgArray) {

	var name = faderName;

	this.timeFade = timeFade;
	this.timeWait = timeWait;
	this.opacityStep = Math.max(opacityStep, 1);

	var fadingUp = false;
	var opacity = 100;

	var images = new ImageList(true);
	for (var i = 1; i < imgArray.length; i++) {
		images.add(imgArray[i]);
	}

	var refDivBottom = document.getElementById(divBottomName);
	var refDivTop = document.getElementById(divTopName);

	refDivTop.style.backgroundImage = "url('" + images.next() + "')";
	refDivBottom.style.backgroundImage = "url('" + images.next() + "')";



	function replaceImage() {
		if (fadingUp) {
			refDivTop.style.backgroundImage = "url('" + images.next() + "')";
		} else
			refDivBottom.style.backgroundImage = "url('" + images.next() + "')";
	}

	this.fade = function() {
		if (opacity == 100 && fadingUp) {
			fadingUp = false;
			replaceImage();
			setTimeout(name + '.fade()', this.timeWait);
		}
		else if (opacity == 0 && !fadingUp) {
			fadingUp = true;
			replaceImage();
			setTimeout(name + '.fade()', this.timeWait);
		} else {
			opacity += (fadingUp) ? this.opacityStep : -this.opacityStep;
			updateOpacity();
			setTimeout(name + '.fade()', this.timeFade);
		}
	}

	function updateOpacity() {
		if (opacity > 100)
			opacity = 100;
		else if (opacity < 0)
			opacity = 0;

		if (opacity < 100) {
			if (opacity < 10)
				refDivTop.style.opacity = '.0'+opacity;
			else
				refDivTop.style.opacity = '0.'+opacity;
		} else {
			refDivTop.style.opacity = '1.'+(opacity%100);
		}
		refDivTop.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity="+opacity+")";	
	}
}

/*----------------------------------------------------------------------------------------------*/

function sponsorInit() {
	sponsorFade = new Fader('sponsorFade', 'sponsor1', 'sponsor2', 50, 7000, 10, sponsorArray);
	setTimeout('sponsorFade.fade()', sponsorFade.timeWait);
}

function ImageList(random) {

	var images = new Array();
	var index = -1;

	this.add = function(imgPath) {
		images.push(imgPath);
	}

	this.next = function() {
		if (images.length > 1) {
			if (random) {
				do {
					next = Math.floor(Math.random() * images.length);
				} while (next == index);
				index = next;
			} else {
				index++;
				if (index >= images.length)
					index = 0;
			}
		}
		return images[index];
	}

	this.current = function() {
		return images[index];
	}
}

function Fader(faderName, divBottomName, divTopName, timeFade, timeWait, opacityStep, imgArray) {

	var name = faderName;

	this.timeFade = timeFade;
	this.timeWait = timeWait;
	this.opacityStep = Math.max(opacityStep, 1);

	var fadingUp = false;
	var opacity = 100;

	var images = new ImageList(true);
	for (var i = 1; i < imgArray.length; i++) {
		images.add(imgArray[i]);
	}

	var refDivBottom = document.getElementById(divBottomName);
	var refDivTop = document.getElementById(divTopName);

	refDivTop.style.backgroundImage = "url('" + images.next() + "')";
	refDivBottom.style.backgroundImage = "url('" + images.next() + "')";



	function replaceImage() {
		if (fadingUp) {
			refDivTop.style.backgroundImage = "url('" + images.next() + "')";
		} else
			refDivBottom.style.backgroundImage = "url('" + images.next() + "')";
	}

	this.fade = function() {
		if (opacity == 100 && fadingUp) {
			fadingUp = false;
			replaceImage();
			setTimeout(name + '.fade()', this.timeWait);
		}
		else if (opacity == 0 && !fadingUp) {
			fadingUp = true;
			replaceImage();
			setTimeout(name + '.fade()', this.timeWait);
		} else {
			opacity += (fadingUp) ? this.opacityStep : -this.opacityStep;
			updateOpacity();
			setTimeout(name + '.fade()', this.timeFade);
		}
	}

	function updateOpacity() {
		if (opacity > 100)
			opacity = 100;
		else if (opacity < 0)
			opacity = 0;

		if (opacity < 100) {
			if (opacity < 10)
				refDivTop.style.opacity = '.0'+opacity;
			else
				refDivTop.style.opacity = '0.'+opacity;
		} else {
			refDivTop.style.opacity = '1.'+(opacity%100);
		}
		refDivTop.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity="+opacity+")";	
	}
}

/*---------------------------------------------*/

function unblur() {
		this.blur();
	}

	function getLinksToBlur() {
		if (!document.getElementById) return
		links = document.getElementsByTagName("a");
		for(i=0; i<links.length; i++) {
			links[i].onfocus = unblur
		}
	}
function removeBlur() {
			// removes the link boxes
			getLinksToBlur();
		}


/*------------------------------------------------------*/

/*javascript:killSpam('info','webdesigndanmark.dk')
	function killSpam(user,domain) {
	locationstring = "mailto:" + user + "@" + domain;
	window.location = locationstring;
	}*/