function gup(name){
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
var Guidance = {
	view: function(id) {
		var allLinks = $$('div.findVejleder a');
		allLinks.each(function(el){
			el.className = "";
		}, this);
		if (document.getElementById('GuidanceLink_'+id)) {
			document.getElementById('GuidanceLink_'+id).className = "active";
		}
	
		var timer = 0;
		var sideblocks = $$('#guidanceContent');
		
		var slidefxs = [];
		var colorfxs = [];
		
		sideblocks.each(function(el, i){
			slidefxs[i] = new Fx.Style(el, 'opacity', {
				duration: 400,
				wait: false,
				onComplete: function() {Guidance.viewEnd(id)}
			});
			slidefxs[i].start(0);
		}, this);
		return false;
	},
	viewEnd: function(id) {
		document.getElementById('guidanceContent').innerHTML = document.getElementById('contentHolder_'+id).innerHTML + '<div class="clr"></div>';
		var timer = 0;
		var sideblocks = $$('#guidanceContent');
		
		var slidefxs = [];
		var colorfxs = [];
		
		sideblocks.each(function(el, i){
			slidefxs[i] = new Fx.Style(el, 'opacity', {
				duration: 400,
				wait: false
			});
			slidefxs[i].start(1);
		}, this);
		return false;
	}
}
var AllEmployees = {
	view: function(id) {
		var timer = 0;
		var sideblocks = $$('#guidanceContainer');
		
		var slidefxs = [];
		var colorfxs = [];
		
		sideblocks.each(function(el, i){
			slidefxs[i] = new Fx.Style(el, 'opacity', {
				duration: 400,
				wait: false,
				onComplete: function() {AllEmployees.viewEnd(id)}
			});
			slidefxs[i].start(0);
		}, this);
		return false;
	},
	viewEnd: function(id) {
		document.getElementById('guidanceContainer').innerHTML = document.getElementById('contentHolder_'+id).innerHTML;
		var timer = 0;
		var sideblocks = $$('#guidanceContainer');
		
		var slidefxs = [];
		var colorfxs = [];
		
		sideblocks.each(function(el, i){
			slidefxs[i] = new Fx.Style(el, 'opacity', {
				duration: 400,
				wait: false
			});
			slidefxs[i].start(1);
		}, this);
		return false;
	}
}
var Video = {
	load: function(id) {
		var timer = 0;
		var sideblocks = $$('#contentText');
		
		var slidefxs = [];
		var colorfxs = [];
		
		sideblocks.each(function(el, i){
			slidefxs[i] = new Fx.Style(el, 'opacity', {
				duration: 400,
				wait: false,
				onComplete: function() {Video.loadEnd(id)}
			});
			slidefxs[i].start(0);
		}, this);
		return false;
	},
	loadEnd: function(id) {
		document.getElementById('contentText').innerHTML = document.getElementById('contentHolder_'+id).innerHTML;
		var timer = 0;
		var sideblocks = $$('#contentText,#goBackBox');
		$$('#goBackBox').setStyle('opacity', '0');
		$$('#goBackBox').setStyle('display', 'block');
		
		var slidefxs = [];
		var colorfxs = [];
		
		sideblocks.each(function(el, i){
			slidefxs[i] = new Fx.Style(el, 'opacity', {
				duration: 400,
				wait: false
			});
			slidefxs[i].start(1);
		}, this);
		return false;
	},
	close: function() {
		Item.open(Item.lastopened);
	}
}
var Item = {
	start: function() {
		var timer = 0;
		var sideblocks = $$('#submenu li');
		
		var slidefxs = [];
		var colorfxs = [];
		
		sideblocks.each(function(el, i){
			timer += 150;
			slidefxs[i] = new Fx.Style(el, 'margin-left', {
				duration: 400,
				transition: Fx.Transitions.backOut,
				wait: false,
				onComplete: function() {Item.setupOver(el)}
			});
			slidefxs[i].start.delay(timer, slidefxs[i], 0);

		}, this);
		
		Item.lastopened = gup('id');
	},
	setupOver: function(el) {
		el.addEvent('mouseover', function() {
			slidefxs = new Fx.Style(el, 'margin-left', {
				duration: 200,
				transition: Fx.Transitions.backOut,
				wait: false
			});
			slidefxs.start(10);
		});
		el.addEvent('mouseout', function() {
			slidefxs = new Fx.Style(el, 'margin-left', {
				duration: 200,
				transition: Fx.Transitions.backOut,
				wait: false
			});
			slidefxs.start(0);
		});
	},
	lastopened: Integer = 0,
	open: function(id) {
		var subMenuLinks = document.getElementById('submenu').getElementsByTagName('a');
		var x = 0;
		while (x < subMenuLinks.length) {
			if (subMenuLinks[x].className == "active") {
				subMenuLinks[x].className = "";
			}
			x++;
		}
		document.getElementById('linkto_'+id).className = "active";
		
		Item.lastopened = id;
		var timer = 0;
		var sideblocks = $$('#contentText,#goBackBox');
		
		var slidefxs = [];
		var colorfxs = [];
		
		sideblocks.each(function(el, i){
			slidefxs[i] = new Fx.Style(el, 'opacity', {
				duration: 400,
				wait: false,
				onComplete: function() {Item.openEnd(id)}
			});
			slidefxs[i].start(0);
		}, this);
		return false;
	},
	openEnd: function(id) {
		document.getElementById('contentText').innerHTML = document.getElementById('contentHolder_'+id).innerHTML
		var timer = 0;
		var sideblocks = $$('#contentText');
		
		var slidefxs = [];
		var colorfxs = [];
		
		sideblocks.each(function(el, i){
			slidefxs[i] = new Fx.Style(el, 'opacity', {
				duration: 400,
				wait: false
			});
			slidefxs[i].start(1);
		}, this);
		return false;
	},
	close: function() {
		var timer = 0;
		var sideblocks = $$('#iconContainer,#submenu,#contentText');	
		var slidefxs = [];
		var colorfxs = [];
		
		sideblocks.each(function(el, i){
			slidefxs[i] = new Fx.Style(el, 'opacity', {
				duration: 400,
				wait: false,
				onComplete: function() {Item.closeEnd()}
			});
			slidefxs[i].start(0);
		}, this);
		
		var content = $$('#contentBox');	
		var contentfxs = [];
		
		content.each(function(el, i){
			contentfxs[i] = new Fx.Style(el, 'height', {
				duration: 400,
				wait: false
			});
			contentfxs[i].start(0);
		}, this);
		
		var content = $$('#contentBox');	
		var contentfxs = [];
		
		content.each(function(el, i){
			contentfxs[i] = new Fx.Style(el, 'width', {
				duration: 400,
				wait: false
			});
			contentfxs[i].start(0);
		}, this);
		return false;
	},
	closeEnd: function() {
		window.open("index.php?id=1","_self");
	}
}
window.addEvent('load', Item.start);
