/*######################################################*\
||                                                      ||
||                  S N E L S I T E                     ||
||                                                      ||
||       Media Design Content Management System         ||
|| Copyright 2002-2005 Media Design  v. 3.0.0           ||
\*######################################################*/


// IE-circumvent, thanks to Mark Wubben
if (document.createElementNS == null)
{
	document.createElementNS = function(ns, tn){ return document.createElement(tn) }
}

// ARRAY EXTENSIONS

if (!Array.prototype.push) Array.prototype.push = function() {
    for (var i=0; i<arguments.length; i++) this[this.length] = arguments[i];
    return this.length;
}

Array.prototype.find = function(value, start) {
    start = start || 0;
    for (var i=start; i<this.length; i++)
        if (this[i]==value)
            return i;
    return -1;
}

Array.prototype.has = function(value) {
    return this.find(value)!==-1;
}

// FUNCTIONAL

function tour_init() 
{
	//alert('woot');
	if (!document.getElementById) return false;
	if (document.getElementById('start-tour'))
	{
		var img = document.getElementById('start-tour');
		img.onclick = function() { window.open('http://www.mov-it.net/documents/Tourviewer_inaxi.html', null, 'width=900, height=600, toolbar=no, menubar=no, statusbar=no')};
	}
}

function map(list, func) {
    var result = [];
    func = func || function(v) {return v};
    for (var i=0; i < list.length; i++) result.push(func(list[i], i, list));
    return result;
}

function filter(list, func) {
    var result = [];
    func = func || function(v) {return v};
    map(list, function(v) { if (func(v)) result.push(v) } );
    return result;
}


// DOM

function getElem(elem) {
    if (document.getElementById) {
        if (typeof elem == "string") {
            elem = document.getElementById(elem);
            if (elem===null) throw 'cannot get element: element does not exist';
        } else if (typeof elem != "object") {
            throw 'cannot get element: invalid datatype';
        }
    } else throw 'cannot get element: unsupported DOM';
    return elem;
}

function hasClass(elem, className) {
    return getElem(elem).className.split(' ').has(className);
}

function getElementsByClass(className, tagName, parentNode) {
    parentNode = !isUndefined(parentNode)? getElem(parentNode) : document;
    if (isUndefined(tagName)) tagName = '*';
    return filter(parentNode.getElementsByTagName(tagName),
        function(elem) { return hasClass(elem, className) });
}


// DOM EVENTS

function listen(event, elem, func) {
    elem = getElem(elem);
    if (elem.addEventListener)  // W3C DOM
        elem.addEventListener(event,func,false);
    else if (elem.attachEvent)  // IE DOM
        elem.attachEvent('on'+event, function(){ func(new W3CDOM_Event(elem)) } );
        // for IE we use a wrapper function that passes in a simplified faux Event object.
    else throw 'cannot add event listener';
}

function mlisten(event, elem_list, func) {
    map(elem_list, function(elem) { listen(event, elem, func) } );
}

function W3CDOM_Event(currentTarget) {
    this.currentTarget  = currentTarget;
    this.preventDefault = function() { window.event.returnValue = false }
    return this;
}


// MISC CLEANING-AFTER-MICROSOFT STUFF

function isUndefined(v) {
    var undef;
    return v===undef;
}

function add_onclicks()
{
	var contentDiv = document.getElementById('content');
	var imgpopups = getElementsByClass('imgpopup', 'a', contentDiv);
	for (var i = 0; i < imgpopups.length; i++)
	{
		var sendurl = imgpopups[i];
		eval('imgpopups[i].onclick = function () { popup_inline_img(this, "' + sendurl + '"); return false; };');
		
	}
}

function clear_inline_img(elemid)
{
	var existPopup = document.getElementById(elemid);
	if (existPopup != false && existPopup != null && existPopup != undefined)
	{
		existPopup.parentNode.removeChild(existPopup);
	}
	add_onclicks();
}

function popup_inline_img(elem, url)
{

	clear_inline_img('popupimg');

	var imgPopup = document.createElement('img');

	imgPopup.setAttribute('src', url);
	imgPopup.setAttribute('alt', 'popup');
	imgPopup.setAttribute('id', 'popupimg');
	imgPopup.className = 'imgpopup';

	imgPopup.src = url;

	elem.onclick = function () { clear_inline_img('popupimg'); return false; };

	elem.appendChild(imgPopup);
}

function wiewashover()
{
	if (!document.getElementById) return false;
	if (!document.getElementById('wiewas-hover-rembrandttext-img')) return false;

	var wieWasImg = document.getElementById('wiewas-hover-rembrandttext-img');
	var wieWasTxt = document.getElementById('wiewas-hover-rembrandttext-text');

	var shown = false;
	wieWasImg.onclick = function() { if (shown == false) { wieWasTxt.style.display = "block"; shown = true; } else { wieWasTxt.style.display = "none"; shown = false; }  }
	wieWasTxt.onclick = function() { wieWasTxt.style.display = "none"; }
	return true;
}

/*######################################################*\
||                   S N E L S I T E                    ||
||                        3.0.0                         ||
||           Copyright 2002-2005 Media Design           ||
\*######################################################*/