/*
 *  wwwRoot
 */
var wwwRoot = "http://" + window.location.hostname + "/";


/*
 *  Browser Detect Lite
 */
function BrowserDetectLite() {
	var ua = navigator.userAgent.toLowerCase();

	// browser name
	this.isGecko     = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
	this.isMozilla   = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
	this.isNS        = ((this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1)));
	this.isIE        = ((ua.indexOf('msie') != -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1));
	this.isSafari    = (ua.indexOf('safari') != - 1);
	this.isOpera     = (ua.indexOf('opera') != -1);
	this.isKonqueror = (ua.indexOf('konqueror') != -1 && !this.isSafari);
	this.isIcab      = (ua.indexOf('icab') != -1);
	this.isAol       = (ua.indexOf('aol') != -1);

	// spoofing and compatible browsers
	this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
	this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);

	// browser version
	this.versionMinor = parseFloat(navigator.appVersion);

	// correct version number
	if (this.isNS && this.isGecko) {
		this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('/') + 1 ) );
	}
	else if (this.isIE && this.versionMinor >= 4) {
		this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
	}
	else if (this.isMozilla) {
		this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
	}
	else if (this.isSafari) {
		this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('/') + 1 ) );
	}
	else if (this.isOpera) {
		if (ua.indexOf('opera/') != -1) {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera/') + 6 ) );
		}
		else {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera ') + 6 ) );
		}
	}
	else if (this.isKonqueror) {
		this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
	}
	else if (this.isIcab) {
		if (ua.indexOf('icab/') != -1) {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab/') + 6 ) );
		} else {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab ') + 6 ) );
		}
	}

	this.versionMajor = parseInt(this.versionMinor);
	this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );

	// dom support
	this.isDOM1 = (document.getElementById);
	this.isDOM2Event = (document.addEventListener && document.removeEventListener);

	// css compatibility mode
	this.mode = document.compatMode ? document.compatMode : 'BackCompat';

	// platform
	this.isWin   = (ua.indexOf('win') != -1);
	this.isWin32 = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
	this.isMac   = (ua.indexOf('mac') != -1);
	this.isUnix  = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
	this.isLinux = (ua.indexOf('linux') != -1);

	// specific browser shortcuts
	this.isNS4x  = (this.isNS && this.versionMajor == 4);
	this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
	this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
	this.isNS4up = (this.isNS && this.versionMinor >= 4);
	this.isNS6x  = (this.isNS && this.versionMajor == 6);
	this.isNS6up = (this.isNS && this.versionMajor >= 6);
	this.isNS7x  = (this.isNS && this.versionMajor == 7);
	this.isNS7up = (this.isNS && this.versionMajor >= 7);

	this.isIE4x  = (this.isIE && this.versionMajor == 4);
	this.isIE4up = (this.isIE && this.versionMajor >= 4);
	this.isIE5x  = (this.isIE && this.versionMajor == 5);
	this.isIE55  = (this.isIE && this.versionMinor == 5.5);
	this.isIE5up = (this.isIE && this.versionMajor >= 5);
	this.isIE6x  = (this.isIE && this.versionMajor == 6);
	this.isIE6up = (this.isIE && this.versionMajor >= 6);

	this.isIE4xMac = (this.isIE4x && this.isMac);
}
var browser = new BrowserDetectLite();


/*
 * Redirect low resolutions
 */
if ((screen.width < 1024 || screen.height < 768) && (document.location.href.toLowerCase().indexOf('?show') == -1)) {
	alert('Voor deze site heeft u een hogere resolutie nodig.\nU wordt doorgestuurd naar de tekstversie van deze site');
	document.location = wwwRoot + 'index.php?Show=Organisatie&view=basic';
}

/*
 *  Redirect old browsers
 */
if ((browser.isNS4x || browser.isIE4x || (browser.isOpera && browser.versionMajor <= 5)) && (document.location.href.toLowerCase().indexOf('?show') == -1)) {
	alert('Voor deze site heeft u een betere browser nodig.\nU wordt aangeraden hierover meer te lezen op http://www.webstandards.org/upgrade/.\nU wordt doorgestuurd naar de tekstversie van onze site');
	document.location = wwwRoot + 'index.php?Show=Organisatie&view=basic';
}


/*
 *  inArray prototype
 */
Array.prototype.inArray = function(element) {
	for (var values in this) {
		if (this[values] == element) {
			return true;
		}  
	}
	return false;
};


/*
 *  Make sure selecting and scrolling is disabled
 *  Selecting form elements should be allowed
 */
var omitFormTags = new Array("input", "textarea", "select");

function disableSelect(e) {
	if (browser.isGecko) {
		if (!omitFormTags.inArray(e.target.tagName.toLowerCase())) {
			return false;
		}
	} else {
		if (!omitFormTags.inArray(e.srcElement.tagName.toLowerCase())) {
			return false;
		}
	}
}

function enableSelect() {
	return true;
}

/*
 *  Randomizer function
 */
function randOrd(a, b) {
	return (Math.round(Math.random()) - 0.5);
} 


/*
 *  Dropdown list onchange code
 */
function clickList(subPage, extraValue) {
	window.location="index.php?Show=" + subPage + "&Value=" + extraValue; 
}


/*
 *  Show page when completely loaded
 */
function showPage() {
	if (browser.isIE5up && window.attachEvent) {
		var innerWindow = document.getElementById("windowinner");
		
		if (innerWindow) {
			innerWindow.attachEvent(
				'onmousewheel', 
				function(event) {
					scrollWheel(event, 'window');
				}
			)
		}
	}

	if (typeof document.onselectstart != "undefined") {
		document.onselectstart = function() { return disableSelect(event); }
	} else {
		document.onmousedown = disableSelect;
		document.onmouseup = enableSelect;
	}

	var loaderObject = document.getElementById("pageloader");
	if (loaderObject) {
		loaderObject.style.visibility = "hidden";
		loaderObject.style.display = "none";
	}
	
	var pageBody = document.getElementById("container");
	pageBody.style.visibility = "visible";
} 


/*
 *  Show page when completely loaded
 */
var effectsDisabled = false;
function switchEffects() {
	if (chainReady) {
		var effectToggle = document.getElementById("effecttoggle");
		var contentWindow = document.getElementById("contentwindow");
		var windowOuter = document.getElementById("windowouter");
		var windowInner = document.getElementById("windowinner");
		var windowScroller = document.getElementById("windowscroller");
		var lang;
		windowInner.style.top = "0px";

		if (effectToggle.firstChild.nodeValue == "Schakel animatie uit" || effectToggle.firstChild.nodeValue == "Schakel animatie in") {
			lang = "nl";
		} else if (effectToggle.firstChild.nodeValue == "Switch off animation" || effectToggle.firstChild.nodeValue == "Switch on animation") {
			lang = "en";
		}

		if (effectsDisabled) {
			effectsDisabled = false;
			windowScroller.style.display = "block";
			windowScroller.style.visibility = "visible";
			contentWindow.style.overflow = "hidden";
			contentWindow.style.backgroundImage = "url(/media/images/bg_content.gif)";
			windowOuter.style.overflow = "hidden";
			if (lang == "nl") { 
				effectToggle.firstChild.nodeValue = "Schakel animatie uit";
			} else {
				effectToggle.firstChild.nodeValue = "Switch off animation";
			}
		} else {
			effectsDisabled = true;
			windowScroller.style.display = "none";
			windowScroller.style.visibility = "hidden";
			contentWindow.style.overflow = "auto";
			contentWindow.style.overflowX = "hidden";
			contentWindow.style.backgroundImage = "none";
			windowOuter.style.overflow = "visible";
			if (lang == "nl") { 
				effectToggle.firstChild.nodeValue = "Schakel animatie in";
			} else {
				effectToggle.firstChild.nodeValue = "Switch on animation";
			}
		}
	}
}


/*
 *  Block click event handler & effect chain
 */
var currentBlock = false;
var chainReady = true;

function clickBlock(blockName) {
	// Test if this is the pretty version of the page
	var contentWindow = document.getElementById("contentwindow");
	if (!contentWindow) { return true; }

	// Start effects event chain
	if (chainReady) {
		effectChain1(blockName);
		chainReady = false;
	}

	return false;
}
function effectChain1(blockName) {
	// Fade in previous block & fade out previous content window
	if (currentBlock) {
		fadeElement(currentBlock, 20, 20, 100, 20, "var nothing;");
		fadeElement("contentwindow", 100, 0, 100, -20, "effectChain2('" + blockName + "')");
	} else {
		effectChain2(blockName);
	}
}
function effectChain2(blockName) {
	// Hide content window
	var contentWindow = document.getElementById("contentwindow");
	contentWindow.style.display = "none";
	contentWindow.style.visibility = "hidden";

	// Logo click starts a different effect chain
	if (blockName == "Logo") {
		resetBlocks();
		return true;
	} else {
		if (!browser.isIE5x && !browser.isIE4x) {
			var logoAnchor = document.getElementById("logolink");
			logoAnchor.style.cursor = "pointer";
		}
	}

	// Reset scroll position
	var scrollWindow = document.getElementById("windowinner");
	scrollWindow.style.top = "0px";

	// Loader icon
	var loaderIcon = document.getElementById("loader");
	loaderIcon.style.visibility = "visible";
	scrollWindow.style.visibility= "hidden";

	// Start loading the content
	loadContent(blockName);
	
	// Move blocks
	var clickedBlock = grid.getBlockByName(blockName);
	grid.clearBlockArea(clickedBlock.getPosition(), "effectChain3('" + blockName + "')");
	
}
function effectChain3(blockName) {
	var contentWindow = document.getElementById("contentwindow");
	contentWindow.style.display = "block";
	contentWindow.style.visibility = "visible";

	// Show content window & fade out clicked block
	fadeElement("contentwindow", 0, 0, 100, 20, "effectChain4('" + blockName + "')");
	fadeElement(blockName, 100, 20, 100, -20, "var nothing;");
}
function effectChain4(blockName) {
	currentBlock = blockName;
	chainReady = true;
	// add the a tag to enlarge the window
	// after the first h2 this should be inserted
	
	allnodes = document.getElementById('testFullScreen').childNodes;
	// the secode = 1
	atag = document.createElement('a');
	atag.href = '?Show=' + blockName;
	atag.innerHTML = '<FONT COLOR="FF0000"><b>Volledig scherm<b></FONT>';
	atag.id='printtag';
	document.getElementById('testFullScreen').innerHTML = '<a href="?Show=' + blockName + '" id="printtag" style="color:#FF0000;"><b>Volledig scherm<b></a>';//insertBefore(atag,allnodes[1]);
	
}


/*
 *  Reset block positions
 */
function resetBlocks() {
	if (!browser.isIE5x && !browser.isIE4x) {
		var logoAnchor = document.getElementById("logolink");
		logoAnchor.style.cursor = "default";
	}
	
	grid.resetGrid();
}
function endReset(resetNow) {
	if (resetNow) {
		currentBlock = false;
		chainReady = true;
	} else {
		setTimeout('endReset(true)', 700)
	}
}


/*
 *  Blixem Page - Block object
 */
function Block(newName) {
	var blockName = newName;
	var blockLayer = document.getElementById(blockName);
	var myGrid;
	
	/*
	 * Get block name
	 */
	this.getName = function() {
		return blockName;
	}	
	
	/*
	 * Get block's grid Position
	 */
	this.getPosition = function() {
		return myGrid.getBlockPositionByName(blockName);
	}	
	
	/*
	 * Associate grid & block
	 */
	this.setGrid = function(grid) {
		myGrid = grid;
	}
}


/*
 *  Blixem Page - Position object
 */
function Position(xPos, yPos) {
	this.x = xPos;
	this.y = yPos;
}


/*
 *  Blixem Page - Grid object
 */
function Grid() {

	/*
	 * Create 3x3 twodimensional array (grid X & Y)
	 */
	var gridPositions = new Array(3);
	for (var i=0; i < gridPositions.length; i++) {
		gridPositions[i] = new Array(3);
	}
	
	/*
	 * Add block to grid on position X,Y
	 */
	this.addBlock = function(block, xPos, yPos) {
		block.setGrid(this);
		gridPositions[yPos][xPos] = block;
	}

	/*
	 * Get block on position X,Y
	 */
	this.getBlock = function(xPos, yPos) {
		return gridPositions[yPos][xPos];
	}
		
	/*
	 * Get block by blockname
	 */
	this.getBlockByName = function(blockName) {
		for (var y=0; y < gridPositions.length; y++) {
			for (var x=0; x < gridPositions[y].length; x++) {
				if (gridPositions[y][x] && gridPositions[y][x].getName() == blockName) {
					return gridPositions[y][x];
				}
			}
		}
		
		return false;
	}
	
	/*
	 * Get grid position of specified block
	 */
	this.getBlockPositionByName = function(blockName) {
		for (var y=0; y < gridPositions.length; y++) {
			for (var x=0; x < gridPositions[y].length; x++) {
				if (gridPositions[y][x] && gridPositions[y][x].getName() == blockName) {
					return new Position(x, y);
				}
			}
		}
		
		return false;
	}
		
	/*
	 * Return canvas pixel positions for grid location
	 */
	this.getCanvasPosition = function(xPos, yPos) {
		return new Position((xPos * 320) + xPos, (yPos * 200) + yPos);
	}	


	/*
	 * Load the default grid
	 */
	this.loadGrid = function() {
		grid.addBlock(new Block("Logo"), 1, 0);
		grid.addBlock(new Block("Iaas"), 0, 1);
		grid.addBlock(new Block("Organisatie"), 1, 1);
		grid.addBlock(new Block("Referenties"), 2, 1);
		grid.addBlock(new Block("Systeembeheer"), 0, 2);
		grid.addBlock(new Block("Contact"), 2, 2);
	}


	/*
	 * Reset the grid
	 */
	this.resetGrid = function() {
		// Reset the grid
		gridPositions = new Array(3);
		for (var i=0; i < gridPositions.length; i++) {
			gridPositions[i] = new Array(3);
		}
		
		// Add blocks
		grid.addBlock(new Block("Logo"), 1, 0);
		grid.addBlock(new Block("Iaas"), 0, 1);
		grid.addBlock(new Block("Organisatie"), 1, 1);
		grid.addBlock(new Block("Referenties"), 2, 1);
		grid.addBlock(new Block("Systeembeheer"), 0, 2);
		grid.addBlock(new Block("Contact"), 2, 2);
		
		// Get new positions
		block1Position = this.getCanvasPosition(1, 0);
		block2Position = this.getCanvasPosition(0, 1);
		block3Position = this.getCanvasPosition(1, 1);
		block4Position = this.getCanvasPosition(2, 1);
		block5Position = this.getCanvasPosition(0, 2);
		block6Position = this.getCanvasPosition(2, 2);
		
		// Move blocks back to their default position
		slideElement("Logo", block1Position.x, block1Position.y, 1, 50, "var nothing;");
		slideElement("Iaas", block2Position.x, block2Position.y, 1, 50, "var nothing;");
		slideElement("Organisatie", block3Position.x, block3Position.y, 1, 50, "var nothing;");
		slideElement("Referenties", block4Position.x, block4Position.y, 1, 50, "var nothing;");
		slideElement("Systeembeheer", block5Position.x, block5Position.y, 1, 50, "var nothing;");
		slideElement("Contact", block6Position.x, block6Position.y, 1, 50, "endReset(false)");	
	}
	

	/*
	 * Clears the area around a block
	 */
	this.clearBlockArea = function(blockPosition, callBack) {
		var xPos = blockPosition.x;
		var yPos = blockPosition.y;
		var expandDirection = new Array();

		// Try 4 possible directions
		if ((xPos - 1) >= 0 && (yPos - 1) >= 0) { // Up, Left
			expandDirection[expandDirection.length] = new Position(-1, -1);
		}
		if ((xPos + 1) <= 2 && (yPos - 1) >= 0) { // Up, Right
			expandDirection[expandDirection.length] = new Position(1, -1);
		}
		if ((xPos - 1) >= 0 && (yPos + 1) <= 2) { // Down, Left
			expandDirection[expandDirection.length] = new Position(-1, 1);
		}
		if ((xPos + 1) <= 2 && (yPos + 1) <= 2) { // Down, Right
			expandDirection[expandDirection.length] = new Position(1, 1);
		}

		// Choose random expand direction
		var expandDirection = expandDirection[Math.floor(Math.random() * expandDirection.length)];
		
		// Remember expansion area
		var expansionArea = new Array(4);
		expansionArea[0] = new Position(xPos, yPos);
		expansionArea[1] = new Position(xPos + expandDirection.x, yPos);
		expansionArea[2] = new Position(xPos, yPos + expandDirection.y);
		expansionArea[3] = new Position(xPos + expandDirection.x, yPos + expandDirection.y);

		// Determine where the content window has to go
		var contentPosition = new Position(9999, 9999);
		for (var i=0; i < 4; i++) {
			if (expansionArea[i].x < contentPosition.x || expansionArea[i].y < contentPosition.y) {
				contentPosition = new Position(expansionArea[i].x, expansionArea[i].y);
			}
		}
		contentPosition = this.getCanvasPosition(contentPosition.x, contentPosition.y);
		var contentWindow = document.getElementById("contentwindow");
		contentWindow.style.left = (contentPosition.x + 10) + "px";
		contentWindow.style.top = (contentPosition.y + 10) + "px";
		contentWindow.style.zIndex = zIndex + 100;

		// Scan the whole grid to find empty spots and to determine
		// how we have to move other blocks in order to make the expansion possible
		var freePositions = Array(); 
		var moveBlocks = Array();
		
		for (var y=0; y < gridPositions.length; y++) {
			for (var x=0; x < gridPositions[y].length; x++) {
				var currentBlock = this.getBlock(x,y);
				
				// In the expansion area?
				var inArea = false;
				for (var i=0; i < 4; i++) {
					if (x == expansionArea[i].x && y == expansionArea[i].y) { inArea = true; break; }
				}				
				
				// Register blocks that need to be moved
				if (inArea) {
					if (typeof currentBlock != 'undefined') {
						if (!(x == xPos && y == yPos)) {
							moveBlocks[moveBlocks.length] = currentBlock;
						}
					}
				// Register empty blocks
				} else {
					if (typeof currentBlock == 'undefined') {
						freePositions[freePositions.length] = new Position(x, y);
					}
				}
			}
		}
		
		// Move blocks to free positions
		moveBlocks.sort(randOrd);
		var movedBlocks = false;
		for (var i=0; i < freePositions.length; i++) {
			var newCanvasPosition = grid.getCanvasPosition(freePositions[i].x, freePositions[i].y);
			if (slideElement(moveBlocks[i].getName(), newCanvasPosition.x, newCanvasPosition.y, 1, 50, callBack)) {
				movedBlocks = true;
				
				// Clear old position
				var oldPosition = moveBlocks[i].getPosition();
				gridPositions[oldPosition.y][oldPosition.x] = this.getBlock(freePositions[i].x, freePositions[i].y);
				
				// Register block with new position
				gridPositions[freePositions[i].y][freePositions[i].x] = moveBlocks[i];
				callBack = "var nothing;"
			}
		}
		
		// If nothing has changed, we still have to continue the event chain
		if (!movedBlocks) {
			eval(callBack);
		}
	}
}


/*
 *  Slide functions
 */
var zIndex = 100;
var slideID = new Array();
var slidePosition = new Array();
var slideCallback = new Array();

function slideElement(elementID, moveToX, moveToY, minStep, maxStep, callBack) {
	var moveElement = document.getElementById(elementID);

	// Skip all transition effects if effects disabled
	if (effectsDisabled) {
		moveElement.style.left = moveToX + 'px';
		moveElement.style.top = moveToY + 'px';
		eval(callBack);
		return true;
	}

	if (moveElement && !slideID[elementID]) {
		slideCallback[elementID] = callBack;
				
		// Bring element to top so we can see it
		moveElement.style.zIndex = zIndex;
	   	zIndex++;

		// Get current X and Y, make sure they are Integers
		slidePosition[elementID] = new Position(moveElement.style.left, moveElement.style.top);
		if (!slidePosition[elementID].x) { slidePosition[elementID].x = '0'; }
		if (!slidePosition[elementID].y) { slidePosition[elementID].y = '0'; }
		slidePosition[elementID].x = parseInt(slidePosition[elementID].x);
		slidePosition[elementID].y = parseInt(slidePosition[elementID].y);

		// Start sliding
		slideID[elementID] = setInterval("moveElementTo('" + elementID + "', " + moveToX + ", " + moveToY + ", " + minStep + ", " + maxStep + ")", 20);
		return true;
	} else {
		eval(callBack);
		return false;
	}
}

function moveElementTo(elementID, moveToX, moveToY, minStep, maxStep) {
	var moveElement = document.getElementById(elementID);

	// Move distance
	var moveX = parseInt(Math.abs((slidePosition[elementID].x - moveToX) / 2));
	var moveY = parseInt(Math.abs((slidePosition[elementID].y - moveToY) / 2));

	// Step size limiter
	if (moveX < minStep) { moveX = minStep; }
	if (moveX > maxStep) { moveX = maxStep; }
	if (moveY < minStep) { moveY = minStep; }
	if (moveY > maxStep) { moveY = maxStep; }

	// Direction
	if (slidePosition[elementID].x > moveToX) { moveX = 0 - moveX; }
	if (slidePosition[elementID].y > moveToY) { moveY = 0 - moveY; }
	if (slidePosition[elementID].x == moveToX) { moveX = 0; }
	if (slidePosition[elementID].y == moveToY) { moveY = 0; }

	// New X and Y
	var newX = slidePosition[elementID].x + parseInt(moveX);
	var newY = slidePosition[elementID].y + parseInt(moveY);

	// Move
	slidePosition[elementID].x = newX;
	slidePosition[elementID].y = newY;
	moveElement.style.left = newX + 'px';
	moveElement.style.top = newY + 'px';

	if (newX == moveToX && newY == moveToY) {
		clearInterval(slideID[elementID]);
		slideID[elementID] = false;
		eval(slideCallback[elementID]);
	}
}


/*
 *  Scrolling
 */
var scrollID = new Array();

function scrollPage(scrollButton, scrollLayerName, scrollOffset) {
	// Start scrolling
	if (browser.isGecko) {
		scrollID[scrollLayerName] = setInterval("scrollLayer('" + scrollLayerName + "', " + scrollOffset*1.5 + ")", 10);
	} else {
		scrollID[scrollLayerName] = setInterval("scrollLayer('" + scrollLayerName + "', " + scrollOffset + ")", 20);
	}
}

function scrollStop(scrollButton, scrollLayerName) {
	clearInterval(scrollID[scrollLayerName]);
}

function scrollLayer(scrollLayerName, scrollOffset) {
	var scrollLayerContainer = document.getElementById(scrollLayerName + 'outer');
	var scrollLayer = document.getElementById(scrollLayerName + 'inner');

	var maxScrollPos = (0 - scrollLayer.scrollHeight) + scrollLayerContainer.clientHeight;
	var currentPos = parseInt(scrollLayer.style.top);
	var newPos = currentPos + scrollOffset;

	if (parseInt(scrollLayerContainer.clientHeight) <= parseInt(scrollLayer.scrollHeight)) {
		if (newPos < maxScrollPos) {
			newPos = maxScrollPos;
		} else if (newPos > 0) {
			newPos = 0;
		}
	} else {
		newPos = 0;
	}

	scrollLayer.style.top = newPos + 'px';

	if(newPos == maxScrollPos || newPos == 0) {
		clearInterval(scrollID[scrollLayerName]);
	}
}

function scrollWheel(event, scrollLayerName) {
	if (effectsDisabled) { return false; }
	if (event.wheelDelta > 0) {
		scrollLayer(scrollLayerName, 30)
	} else {
		scrollLayer(scrollLayerName, -30)
	}
}


/*
 *  Fade functions
 */
var fadeID = new Array();
var fadeCurrentOpacity = new Array();
var fadeCallback = new Array();

function fadeElement(elementID, startOpacity, opacityMin, opacityMax, opacityStep, callBack) {
	var fadeElement = document.getElementById(elementID);

	// Skip all transition effects if effects disabled
	if (effectsDisabled) {
		if (opacityStep < 0) {
			opacityStep = -100;
		} else {
			opacityStep = 100;
		}
	}

	if (fadeElement) {
		fadeCallback[elementID] = callBack;
		opacityStep = parseFloat(opacityStep / 100);
		fadeCurrentOpacity[elementID] = parseFloat(startOpacity / 100);

		fadeID[elementID] = setInterval("fadeTo('" + elementID + "', " + opacityMin + ", " + opacityMax + ", " + opacityStep + ")", 50);
		return true;
	} else {
		eval(callBack);
		return false;
	}
}


function fadeTo(elementID, opacityMin, opacityMax, opacityStep) {
	if ((fadeCurrentOpacity[elementID] >= (opacityMin / 100)) && (fadeCurrentOpacity[elementID] <= (opacityMax / 100))) {
		fadeCurrentOpacity[elementID] += opacityStep;
	}

	if (parseInt(fadeCurrentOpacity[elementID] * 100) < opacityMin) {
		fadeCurrentOpacity[elementID] = opacityMin / 100;
		clearInterval(fadeID[elementID]);
		fadeID[elementID] = false;
		eval(fadeCallback[elementID]);
	} else if(parseInt(fadeCurrentOpacity[elementID] * 100) > opacityMax) {
		fadeCurrentOpacity[elementID] = opacityMax / 100;
		clearInterval(fadeID[elementID]);
		fadeID[elementID] = false;
		eval(fadeCallback[elementID]);
	}

	if (browser.isGecko) {
		document.getElementById(elementID).style.MozOpacity = fadeCurrentOpacity[elementID];
	} else if (browser.isIE5up) {
		document.getElementById(elementID).filters.alpha.opacity = parseInt(fadeCurrentOpacity[elementID] * 100);
	}
}


/*
 * Content switching
 */
function loadContent(blockName) {
	LoaderObject = new RemoteFileLoader("LoaderObject");
	LoaderObject.loadInto(wwwRoot + "index.php?Show=" + blockName, "windowinner");
	
}


/*
 * Define grid & blocks
 */
grid = new Grid();
grid.loadGrid();