﻿function bodyHasScroll() {
	if (window.innerHeight) {
		windowHeight=window.innerHeight;
	} else {
		windowHeight= document.documentElement.clientHeight
	}
	if (windowHeight < document.body.scrollHeight) {
		return true;
	}
}

function init() {
	adjustFooter();
	checkMenus();
	if (document.body.id=='frontpage') {
		$('#imageViewer').crossSlide({
		  sleep: 7,
		  fade: 0.5
		}, [
		  { src: '/library/content/punktum.jpg'},
		  { src: '/library/content/case-1.jpg'},
		  { src: '/library/content/case-2.jpg'},
		  { src: '/library/content/case-3.jpg'}
		]);
	} else if (document.body.id=='subcontentpage') { 
		$('#imageViewer').crossSlide({
		  sleep: 7,
		  fade: 0.5
		}, [
		  { src: '/library/content/case-4.jpg'},
		  { src: '/library/content/case-5.jpg'},
		  { src: '/library/content/case-6.jpg'},
		  { src: '/library/content/case-7.jpg'}
		]);
	} else {
		Gallery.addNumbersToThumbs();
	}
}
window.onload=init;
window.onresize=adjustFooter;
 

function checkMenus() {
	var topMenu=document.getElementById('navigation').getElementsByTagName('a');
	for (i=0;i<topMenu.length;i++) {
		if (document.location.href.indexOf(topMenu[i].href)>-1) {
			topMenu[i].className='active';
		}
	}
	if (document.getElementById('subnavigation')) {
		var subMenu=document.getElementById('subnavigation').getElementsByTagName('a');
		for (i=0;i<subMenu.length;i++) {
			if (document.location.href.indexOf(subMenu[i].href)>-1) {
				subMenu[i].className='active';
			}
		}
	}
}
function adjustFooter() {
	if (bodyHasScroll()) {
		document.getElementById('container').style.marginBottom='0px';
		document.getElementById('footer').style.position='static';
	} else {
		document.getElementById('container').style.marginBottom='190px';
		document.getElementById('footer').style.position='fixed';
	}
}

var Gallery = {
	showPicture : function(url) {
		$("#slideshow").hide();
		var slideshow=document.getElementById('slideshow');
		oldSrc=slideshow.src;
		slideshow.src = url;
		if (slideshow.src==oldSrc) {
			$("#slideshow").fadeIn(300);
		} else {
			slideshow.onload = function() {
				$("#slideshow").fadeIn(300);
			}
		}
	},
	addNumbersToThumbs : function() {
		var thumbList = document.getElementById('thumbnails').getElementsByTagName('li');
		for (i=0;i<thumbList.length;i++) {
			thumbList[i].no=i+1;
			Gallery.addNumber(thumbList[i]);
		}
	},
	addNumber: function(target) {
		var number = document.createElement('div');
		number.innerHTML=target.no;
		number.className='thumbNumber';
		target.appendChild(number);
		number.style.left=(i*80)+45+"px";
		number.style.cursor='pointer';
		number.onclick=function() {
			document.location.href=target.getElementsByTagName('a')[0].href;
		}
	}
}
var Form = {
	validate : function(form) {
		var validates=true;
		var returnMessage='Følgende felt(er) mangler at blive udfyldt:';
		var formElement = form.getElementsByTagName('input');
		for (i=0;i<formElement.length;i++) {
			if (formElement[i].value.length<=0) {
				returnMessage+="\n- "+formElement[i].id.replace("email","e-mail");
				validates=false;
			}
		}
		if (!validates) {
			alert(returnMessage);
		}
		return validates;
	}
}
