function Carrousel (sId, iImageCount, sFirstProductId) {
	
	this.id = sId;
	this.imageCount = iImageCount;
	this.firstProductId = sFirstProductId;
	this.sliderWidth = 357;
	this.sliderPos = 0;
	this.sliderMin = 0;
	this.sliderMax = this.sliderWidth * Math.ceil (this.imageCount / 3);
	
	this.init ();
	
}

Carrousel.prototype.init = function () {
	
	this.mainImage = document.getElementById ('CarMainImage' + this.id);
	this.slider = document.getElementById ('CarSlider' + this.id);
	this.buttonPrevious = document.getElementById ('CarButtonPrevious' + this.id);
	this.buttonNext = document.getElementById ('CarButtonNext' + this.id);
	
	this.disablePrevious ();
	
	if (this.sliderPos - this.sliderWidth <= -this.sliderMax)
		this.disableNext ();
		
	this.showImage (this.firstProductId);
		
}


Carrousel.prototype.showImage = function (sProductId) {
	
	if (this.selectedThumb)
	    this.selectedThumb.style.borderColor = '#bbaa00';
	    
	this.selectedThumb = document.getElementById ('carThumbFotoKader' + sProductId);
	this.selectedThumb.style.borderColor = 'black';
	this.mainImage.src = 'images/fotos/groot/' + sProductId + '.jpg';
	
}


Carrousel.prototype.goNext = function () {
	
	if ((this.sliderPos - (2 * this.sliderWidth)) <= -this.sliderMax)
		this.disableNext ();
	
	if (this.sliderPos - this.sliderWidth >= -this.sliderMax)
		this.enablePrevious ();
	
	this.animNext (-this.sliderWidth);
	
}

Carrousel.prototype.goPrevious = function () {
	
	if (this.sliderPos + this.sliderWidth >= this.sliderMin)
		this.disablePrevious ();
	
	if (this.sliderPos + this.sliderWidth < this.sliderMax)
		this.enableNext ();
	
	this.animNext (this.sliderWidth);
	
}

Carrousel.prototype.enablePrevious = function () {
	
	this.buttonPrevious.style.display = 'block';
	
}

Carrousel.prototype.enableNext = function () {
	
	this.buttonNext.style.display = 'block';
	
}

Carrousel.prototype.disablePrevious = function () {
	
	this.buttonPrevious.style.display = 'none';
	
}

Carrousel.prototype.disableNext = function () {
	
	this.buttonNext.style.display = 'none';
	
}

Carrousel.prototype.animNext = function (iTogo) {
	
	var self = this;
	var iStepSize = ((Math.abs(iTogo)/35) * Math.abs ((Math.abs(iTogo)/35))) + (Math.abs(iTogo)/5);
	
	if (iTogo < 0)
		iStepSize = -iStepSize;
	
	var iTogoNew = iTogo - iStepSize;
	this.sliderPos += iStepSize;
	this.slider.style.left = Math.round (this.sliderPos) + 'px';
	
	if (Math.round (Math.abs (iTogoNew)) > 0)
		setTimeout (function () {self.animNext (iTogoNew)}, 15);
	else
		this.sliderPos = Math.round (this.sliderPos);
	
}


function writeEmail (sDomain, sAlias, sDisplayText) {
    
    if (!sDomain)
        sDomain = 'allventure.nl';

    if (!sDisplayText)
        sDisplayText = sAlias + '\u0040' + sDomain;
	
	document.write ('<a href="mailto:' + sAlias + '\u0040' + sDomain + '">' + sDisplayText + '</a>');
	
}


function NMMenu (sId)
{
	
	this.id = sId;
	this.subMenu = [];
	
	this.init ();
	
};


NMMenu.prototype.init = function ()
{
    
    
};


NMMenu.prototype.addSubMenu = function (sBaseMenuItemId, sSubMenuId)
{
	
	this.subMenu.push (new NMSubMenu (sBaseMenuItemId, sSubMenuId));
	
};


function NMSubMenu (sBaseMenuItemId, sSubMenuId) 
{

	this.baseMenuItemId = sBaseMenuItemId;
	this.subMenuId = sSubMenuId;
	
	this.subMenuHidden = false;
    this.baseMenuItemXPos;
    this.baseMenuItemYPos;
	
	this.init ();
	
};


NMSubMenu.prototype.init = function ()
{

	this.baseMenuItem = document.getElementById (this.baseMenuItemId);
	this.subMenu = document.getElementById (this.subMenuId);
	
	// Position box.
	this.repositionBox ();
	
	this.baseMenuItem.onmouseover = createMethodReference (this, 'show');
	this.baseMenuItem.onmouseout = createMethodReference (this, 'mouseOutSubMenu');
	
    this.subMenu.onmouseout = createMethodReference (this, 'mouseOutSubMenu');

};


NMSubMenu.prototype.mouseOutSubMenu = function (e)
{

	if (this.checkMouseLeavesBoth (this.subMenu, this.baseMenuItem, e)) {
		
		this.hide ();
		
	};

};


NMSubMenu.prototype.repositionBox = function ()
{
    
    if (!this.subMenu) return;
    
    var iPositionLeft = this.findPosX (this.baseMenuItem);
    
    if (this.baseMenuItemXPos != iPositionLeft)
    {
	    this.baseMenuItemXPos = iPositionLeft;
	    this.baseMenuItemYPos = this.findPosY (this.baseMenuItem);
		this.subMenu.style.left = (iPositionLeft - 10) + 'px';
		this.subMenu.style.top = (this.baseMenuItemYPos + 17) + 'px';
    };
    
};


NMSubMenu.prototype.show = function () 
{

	// Position box.
	this.repositionBox ();
	
	this.subMenu.style.display = 'block';
	this.subMenuHidden = false;
	
};


NMSubMenu.prototype.hide = function () 
{
	
	this.subMenu.style.display = 'none';
	this.subMenuHidden = true;
	
};


NMSubMenu.prototype.containsDOM = function (container, containee)
{
	
	var isParent = false;
	
	do
	{
		if ((isParent = container == containee)) break;
		containee = containee.parentNode;
	} while (containee != null);
	
	return isParent;
	
};

/*	
NMSubMenu.prototype.checkMouseEnter = function (element, e)
{
	
	if (!e) var e = window.event;

	if (element.contains && e.fromElement)
	{
		return !element.contains(e.fromElement);
	} else if (e.relatedTarget)
	{
		return !this.containsDOM(element, e.relatedTarget);
	};
	
};
*/

NMSubMenu.prototype.checkMouseLeavesBoth = function (element1, element2, e)
{
	
	if (!e) var e = window.event;

	if (element1.contains && e.toElement) {
		return !(element1.contains(e.toElement) || element2.contains(e.toElement));
	} else if (e.relatedTarget) {
		return !(this.containsDOM(element1, e.relatedTarget) || this.containsDOM(element2, e.relatedTarget));
	};
	
};

/*
NMSubMenu.prototype.checkMouseLeave = function (element, e)
{
	
	if (!e) var e = window.event;

	if (element.contains && e.toElement) {
		return !element.contains(e.toElement);
	} else if (e.relatedTarget) {
		return !this.containsDOM(element, e.relatedTarget);
	};
	
};
*/


NMSubMenu.prototype.findPosX = function (obj)
{
	var curleft = 0;
	if(obj.offsetParent)
		while(1) 
		{
		  curleft += obj.offsetLeft;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
	
};


NMSubMenu.prototype.findPosY = function (obj)
{
	var curtop = 0;
	if(obj.offsetParent)
		while(1)
		{
		  curtop += obj.offsetTop;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
	return curtop;
};


function SearchBox (sInputElemId, sButtonElemId)
{
	
	this.inputElemId = sInputElemId;
	this.sButtonElemId = sButtonElemId;

    this.searchParamName = 'zoekstring';
    this.submitUrl = 'parser.asp?xml=nl_zoekresultaten.xml&xsl=website_paginas.xsl&lang=nl';
    
    this.arrayParameters = [];

    this.init ();
	
};


SearchBox.prototype.init = function ()
{
	this.getAllParameters ();
	
	this.inputElem = document.getElementById (this.inputElemId);
	this.buttonElem = document.getElementById (this.sButtonElemId);
	
	this.buttonElem.onclick = createMethodReference (this, 'searchButtonClicked');
	this.inputElem.onkeydown = createMethodReference (this, 'keyDown');
	
	var searchString = this.getParameter (this.searchParamName);
	
	if (searchString)
		this.inputElem.value = searchString;

};


SearchBox.prototype.getAllParameters = function ()
{

	var arrayParametersTemp = window.location.href.split (/\&/);
	arrayParametersTemp[0] = arrayParametersTemp[0].split (/\?/)[1];
	
	var pattern = /=/;
	
	for (var i = 0; i < arrayParametersTemp.length; i++) {
		
		if (pattern.test(arrayParametersTemp)) {
			
			var arrayParemeter = arrayParametersTemp[i].split (/=/);
			
			this.arrayParameters.push (new Parameter (arrayParemeter[0], arrayParemeter[1]));
			
		};
		
	};

};



SearchBox.prototype.searchButtonClicked = function ()
{

    this.submit ();

};


SearchBox.prototype.keyDown = function (e)
{
	
	var evt = (e)?e:(window.event)?window.event:null;
	
	if (evt){
		
		var key = (evt.charCode)?evt.charCode:
			((evt.keyCode)?evt.keyCode:((evt.which)?evt.which:0));
		
		if (key=="13")
			this.submit ();
		
	};
	
};


SearchBox.prototype.getParameter = function (sParamName) {
	
	for (var i = 0; i < this.arrayParameters.length; i++) {
		
		if (this.arrayParameters[i].name == sParamName)
			if (this.arrayParameters[i].value.length > 0)
				return decodeURIComponent (this.arrayParameters[i].value);
		
	};
	
};


SearchBox.prototype.submit = function () {
	
	if (this.inputElem.value.length > 0) {
		
		var sSubmitUrl = this.submitUrl; 
		
		sSubmitUrl += '&' + this.searchParamName + '=' + encodeURIComponent (this.inputElem.value);
		
		location.href = sSubmitUrl;
		
	} else {
		
		this.inputElem.focus ();
		
	};
	
};


function Parameter (sName, sValue)
{
	
	this.name = String (sName);
	this.value = String (sValue);
	this.valueLength = this.value.length;
	
};


function createMethodReference (object, method)
{

    if (!(method instanceof Function))
        method = object[method];

    return function () {
        method.apply(object, arguments);
    };
	
};