// SprySlidingPanels.js - version 0.5 - Spry Pre-Release 1.6.1
//
// Copyright (c) 2006. Adobe Systems Incorporated.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
//   * Redistributions of source code must retain the above copyright notice,
//     this list of conditions and the following disclaimer.
//   * Redistributions in binary form must reproduce the above copyright notice,
//     this list of conditions and the following disclaimer in the documentation
//     and/or other materials provided with the distribution.
//   * Neither the name of Adobe Systems Incorporated nor the names of its
//     contributors may be used to endorse or promote products derived from this
//     software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
var browserType; 

if (document.layers) {browserType = "nn4"}
if (document.all) {browserType = "ie"}
if (window.navigator.userAgent.toLowerCase().match("gecko")) {
   browserType= "gecko"
}
var Nieuwetime;
var Nieuwetimeslide;
var NieuweSpry;
if (!NieuweSpry) NieuweSpry = {};
if (!NieuweSpry.Widget) NieuweSpry.Widget = {};

NieuweSpry.Widget.SlidingPanels = function(element, opts)
{
	this.element = this.getElement(element);
	this.enableAnimation = true;
	this.currentPanel = null;
	this.enableKeyboardNavigation = true;
	this.hasFocus = false;
	this.previousPanelKeyCode = NieuweSpry.Widget.SlidingPanels.KEY_LEFT;
	this.nextPanelKeyCode = NieuweSpry.Widget.SlidingPanels.KEY_RIGHT;

	this.currentPanelClass = "SlidingPanelsCurrentPanel";
	this.focusedClass = "SlidingPanelsFocused";
	this.animatingClass = "SlidingPanelsAnimating";

	NieuweSpry.Widget.SlidingPanels.setOptions(this, opts);

	if (this.element)
		this.element.style.overflow = "hidden"; 

	// Developers can specify the default panel as an index,
	// id or an actual element node. Make sure to normalize
	// it into an element node because that is what we expect
	// internally.

	if (this.defaultPanel)
	{
		if (typeof this.defaultPanel == "number")
			this.currentPanel = this.getContentPanels()[this.defaultPanel];
		else
			this.currentPanel = this.getElement(this.defaultPanel);
	}

	// If we still don't have a current panel, use the first one!

	if (!this.currentPanel)
		this.currentPanel = this.getContentPanels()[0];

	// Since we rely on the positioning information of the
	// panels, we need to wait for the onload event to fire before
	// we can attempt to show the initial panel. Once the onload
	// fires, we know that all CSS files have loaded. This is
	// especially important for Safari.

	if (NieuweSpry.Widget.SlidingPanels.onloadDidFire)
		this.attachBehaviors();
	else
		NieuweSpry.Widget.SlidingPanels.loadQueue.push(this);
};

NieuweSpry.Widget.SlidingPanels.prototype.onFocus = function(e)
{
	this.hasFocus = true;
	this.addClassName(this.element, this.focusedClass);
	return false;
};

NieuweSpry.Widget.SlidingPanels.prototype.onBlur = function(e)
{
	this.hasFocus = false;
	this.removeClassName(this.element, this.focusedClass);
	return false;
};

NieuweSpry.Widget.SlidingPanels.KEY_LEFT = 37;
NieuweSpry.Widget.SlidingPanels.KEY_UP = 38;
NieuweSpry.Widget.SlidingPanels.KEY_RIGHT = 39;
NieuweSpry.Widget.SlidingPanels.KEY_DOWN = 40;

NieuweSpry.Widget.SlidingPanels.prototype.onKeyDown = function(e)
{
	var key = e.keyCode;
	if (!this.hasFocus || (key != this.previousPanelKeyCode && key != this.nextPanelKeyCode))
		return true;

	if (key == this.nextPanelKeyCode)
		this.showNextPanel();
	else /* if (key == this.previousPanelKeyCode) */
		this.showPreviousPanel();

	if (e.preventDefault) e.preventDefault();
	else e.returnValue = false;
	if (e.stopPropagation) e.stopPropagation();
	else e.cancelBubble = true;

	return false;
};

NieuweSpry.Widget.SlidingPanels.prototype.attachBehaviors = function()
{
	var ele = this.element;
	if (!ele)
		return;

	if (this.enableKeyboardNavigation)
	{
		var focusEle = null;
		var tabIndexAttr = ele.attributes.getNamedItem("tabindex");
		if (tabIndexAttr || ele.nodeName.toLowerCase() == "a")
			focusEle = ele;
	
		if (focusEle)
		{
			var self = this;
			NieuweSpry.Widget.SlidingPanels.addEventListener(focusEle, "focus", function(e) { return self.onFocus(e || window.event); }, false);
			NieuweSpry.Widget.SlidingPanels.addEventListener(focusEle, "blur", function(e) { return self.onBlur(e || window.event); }, false);
			NieuweSpry.Widget.SlidingPanels.addEventListener(focusEle, "keydown", function(e) { return self.onKeyDown(e || window.event); }, false);
		}
	}

	if (this.currentPanel)
	{
		// Temporarily turn off animation when showing the
		// initial panel.

		var ea = this.enableAnimation;
		this.enableAnimation = false;
		this.showPanel(this.currentPanel);
		this.enableAnimation = ea;
	}
};

NieuweSpry.Widget.SlidingPanels.prototype.getElement = function(ele)
{
	if (ele && typeof ele == "string")
		return document.getElementById(ele);
	return ele;
};

NieuweSpry.Widget.SlidingPanels.prototype.addClassName = function(ele, className)
{
	if (!ele || !className || (ele.className && ele.className.search(new RegExp("\\b" + className + "\\b")) != -1))
		return;
	ele.className += (ele.className ? " " : "") + className;
};

NieuweSpry.Widget.SlidingPanels.prototype.removeClassName = function(ele, className)
{
	if (!ele || !className || (ele.className && ele.className.search(new RegExp("\\b" + className + "\\b")) == -1))
		return;
	ele.className = ele.className.replace(new RegExp("\\s*\\b" + className + "\\b", "g"), "");
};

NieuweSpry.Widget.SlidingPanels.setOptions = function(obj, optionsObj, ignoreUndefinedProps)
{
	if (!optionsObj)
		return;
	for (var optionName in optionsObj)
	{
		if (ignoreUndefinedProps && optionsObj[optionName] == undefined)
			continue;
		obj[optionName] = optionsObj[optionName];
	}
};

NieuweSpry.Widget.SlidingPanels.prototype.getElementChildren = function(element)
{
	var children = [];
	var child = element.firstChild;
	while (child)
	{
		if (child.nodeType == 1 /* Node.ELEMENT_NODE */)
			children.push(child);
		child = child.nextSibling;
	}
	return children;
};

NieuweSpry.Widget.SlidingPanels.prototype.getCurrentPanel = function()
{
	return this.currentPanel;
};

NieuweSpry.Widget.SlidingPanels.prototype.getContentGroup = function()
{
	return this.getElementChildren(this.element)[0];
};

NieuweSpry.Widget.SlidingPanels.prototype.getContentPanels = function()
{
	return this.getElementChildren(this.getContentGroup());
};

NieuweSpry.Widget.SlidingPanels.prototype.getContentPanelsCount = function()
{
	return this.getContentPanels().length;
};

NieuweSpry.Widget.SlidingPanels.onloadDidFire = false;
NieuweSpry.Widget.SlidingPanels.loadQueue = [];

NieuweSpry.Widget.SlidingPanels.addLoadListener = function(handler)
{
	if (typeof window.addEventListener != 'undefined')
		window.addEventListener('load', handler, false);
	else if (typeof document.addEventListener != 'undefined')
		document.addEventListener('load', handler, false);
	else if (typeof window.attachEvent != 'undefined')
		window.attachEvent('onload', handler);
};

NieuweSpry.Widget.SlidingPanels.processLoadQueue = function(handler)
{
	NieuweSpry.Widget.SlidingPanels.onloadDidFire = true;
	var q = NieuweSpry.Widget.SlidingPanels.loadQueue;
	var qlen = q.length;
	for (var i = 0; i < qlen; i++)
		q[i].attachBehaviors();
};

NieuweSpry.Widget.SlidingPanels.addLoadListener(NieuweSpry.Widget.SlidingPanels.processLoadQueue);

NieuweSpry.Widget.SlidingPanels.addEventListener = function(element, eventType, handler, capture)
{
	try
	{
		if (element.addEventListener)

			element.addEventListener(eventType, handler, capture);
		else if (element.attachEvent)
			element.attachEvent("on" + eventType, handler);
	}
	catch (e) {}
};

NieuweSpry.Widget.SlidingPanels.prototype.getContentPanelIndex = function(ele)
{
	if (ele)
	{
		ele = this.getElement(ele);
		var panels = this.getContentPanels();
		var numPanels = panels.length;
		for (var i = 0; i < numPanels; i++)
		{
			if (panels[i] == ele)
				return i;
		}
	}
	return -1;
};

function get_object(id) 
{
		   var object = null;
		   if (document.layers) {   
		   object = document.layers[id];
		   } else if (document.all) {

		  object = document.all[id];

		   } else if (document.getElementById) {

		   object = document.getElementById(id);

		   }

		   return object;

}


NieuweSpry.Widget.SlidingPanels.prototype.showPanel = function(elementOrIndex)
{
	if(typeof Nieuwetime == 'number')
	{
		window.clearTimeout(Nieuwetime);
	}
	//alert(Ref + 'lijst');
	//var RefLijst=Ref + 'lijst';
	var aantaldivs=get_object("NieuwetickerReflijst").childNodes.length;
	var itel=0;
	var itelgenoeg=0;
	var teldivs=0;
	var toonnaam=0;
	var naamvolgende="";
	var naamvorige="";
	var telvorige=-1;
	var telvolgende=-1;
	var dezeOK =-1;
	var terugdiv=0;
	var telnaactieve=0;
	var iblokjenaam=0;
	var acti=0;
	var actinr=1;
	for (iaan=0; iaan<aantaldivs; iaan++)
	{
		if(get_object('NieuwetickerReflijst').childNodes[iaan].tagName =="DIV")
		{
			teldivs= teldivs + 1;
			if(get_object('NieuwetickerReflijst').childNodes[iaan].id == elementOrIndex )
			{
				
				acti=iaan;
				dezeOK = 1;
				if(telvorige != -1)
				{
					naamvorige = get_object('NieuwetickerReflijst').childNodes[telvorige].id;
				}
				actinr =get_object('NieuwetickerReflijst').childNodes[iaan].id.replace("Nieuwe","");
				
			}
			telvorige= iaan;
			if((get_object('NieuwetickerReflijst').childNodes[iaan].id == elementOrIndex || elementOrIndex == "[object HTMLDivElement]" || elementOrIndex == "[object]") && itel == 0)
			{
				itel=1;		
				
			}
			else if(itel > 0)
			{
				itel = itel + 1;	
			}
			if(itel ==2)
			{
				toonnaam = iaan;
			}
			if(toonnaam == 0)
			{
				itelgenoeg = itelgenoeg + 1;
			}
			else
			{
				telnaactieve = telnaactieve + 1;	
			}
		}
	}
	var itel=0;
	var vorige=-1;
	//alert(iaan);
	if(acti == 0 || naamvorige == "" )
	{
		//alert(get_object('Nieuwevorige').id);
		get_object('Nieuwevorige').style.visibility = "hidden";
		get_object('Nieuwevorigediv').style.visibility = "hidden";
		get_object('NieuweprevMain').style.visibility = "hidden";
	}
	else
	{
		vorige = acti -1;
		/**/get_object('NieuweprevTD').removeChild(get_object('Nieuweprev'));
		var newprevdiv = document.createElement('div');
		newprevdiv.setAttribute("class","prev");
		newprevdiv.setAttribute("id","Nieuweprev");
		var toonnaammin = parseInt(actinr) -1;
		newprevdiv.innerHTML ='<table align="left" id="NieuweprevMain"  cellspacing="0" cellpadding="0"><tr><td class="bannerKnopBG" align="center"><table align="center" cellspacing="0" cellpadding="0"><tr><td><a href="#" onclick="Nieuwesp.showPanel(\'' + naamvorige +'\'); return false;" name="Nieuwevorigediv" title="Bekijk vorige foto" id="Nieuwevorigediv" class="link"><div style="background-image: url(http://www.blackandwhitecompany.be/images/links.png); width:42px; height:18px; cursor: pointer;float:left;" class="right"><\/div><\/a></td><td><a href="#" onclick="Nieuwesp.showPanel(\'' + naamvorige +'\'); return false;" name="Nieuwevorige" title="Bekijk vorige foto" id="Nieuwevorige" class="linkbanner">&nbsp;&nbsp;00'  + toonnaammin + '<span style="color:#4C4C4C;">/00' + teldivs + '</span><\/a></td></tr></table></td></tr></table>';
		get_object('NieuweprevTD').appendChild(newprevdiv);
	}
	if(toonnaam ==0 && teldivs > 1)
	{
		get_object('Nieuwevolgende').style.visibility = "hidden";
		get_object('Nieuwevolgendediv').style.visibility = "hidden";
		get_object('NieuwenextMain').style.visibility = "hidden";
	}
	naamvolgende = get_object('NieuwetickerReflijst').childNodes[toonnaam].id;
	if(toonnaam !=0)
	{
		get_object('NieuwenextTD').removeChild(get_object('Nieuwenext'));
		var newdiv = document.createElement('div');
		newdiv.setAttribute("class","next");
		newdiv.setAttribute("id","Nieuwenext");
		var toonnaamplus = parseInt(actinr) + 1;
		newdiv.innerHTML ='<table align="right" id="NieuwenextMain" cellspacing="0" cellpadding="0"><tr><td class="bannerKnopBG" align="center"><table align="center" cellspacing="0" cellpadding="0"><tr><td><a href="#" onclick="Nieuwesp.showPanel(\'' + naamvolgende +'\'); return false;" name="Nieuwevolgende" title="Bekijk volgende foto" id="Nieuwevolgende" class="linkbanner">00' + toonnaamplus + '<span style="color:#4C4C4C;">/00' + teldivs + '</span>&nbsp;&nbsp;<\/a></td><td><a href="#" onclick="Nieuwesp.showPanel(\'' + naamvolgende +'\'); return false;" name="Nieuwevolgendediv" title="Bekijk volgende foto" id="Nieuwevolgendediv" class="link"><div style="background-image: url(http://www.blackandwhitecompany.be/images/rechts.png); width:42px; height:18px; cursor: pointer;float:right;" class="right;"><\/div><\/a></td></tr></table></td></tr></table>';
		get_object('NieuwenextTD').appendChild(newdiv);
	}
	var pIndex = -1;
	
	if (typeof elementOrIndex == "number")
	{
		pIndex = elementOrIndex;
	}else // Must be the element for the content panel.
	{	
		pIndex = this.getContentPanelIndex(elementOrIndex);	
	}
	var numPanels = this.getContentPanelsCount();
	if (numPanels > 0)
	{
		if(pIndex >= numPanels)
		{
			pIndex = numPanels - 1;
		}
		else
		{
			pIndex= pIndex;
		}
	}
	else
		pIndex = 0;
	
	var panel = this.getContentPanels()[pIndex];
	var contentGroup = this.getContentGroup();
	if (panel && contentGroup)
	{
		if (this.currentPanel)
			this.removeClassName(this.currentPanel, this.currentPanelClass);
		this.currentPanel = panel;
		var nx =0;
		var ny= 0;
		//if(browserType == "ie")
		//{
			var nx = -panel.offsetLeft;
			var ny = -panel.offsetTop;
	/*	}
		else
		{
			var nx = -(panel.offsetLeft + panel.parentNode.offsetLeft);
			var ny = -(panel.offsetTop  + panel.parentNode.offsetTop);
		}*/
		

		if (this.enableAnimation)
		{
			if (this.animator)
				this.animator.stop();
				
			var cx =0;
			var cy= 0;
			contentGroup.offsetParent.id = "NieuwetickerRef";
			//if(browserType == "ie")
			//{
				var cx = contentGroup.offsetLeft;
				var cy = contentGroup.offsetTop;
			/*}
			else
			{
		
				var cx = (contentGroup.offsetLeft + contentGroup.parentNode.offsetLeft);
				var cy = (contentGroup.offsetTop  + contentGroup.parentNode.offsetTop);
			}*/
			/*for (var i in contentGroup) {
			}*/
			if (cx != nx || cy != ny)
			{
				var self = this;
				this.addClassName(this.element, this.animatingClass);
				this.animator = new NieuweSpry.Widget.SlidingPanels.PanelAnimator(contentGroup, cx, cy, nx, ny, { duration: this.duration, fps: this.fps, transition: this.transition, finish: function()
				{
					self.removeClassName(self.element, self.animatingClass);
					self.addClassName(panel, self.currentPanelClass);
				} });
				this.animator.start();
			}
		}
		else
		{
			contentGroup.style.left = nx + "px";
			contentGroup.style.top = ny + "px";
			this.addClassName(panel, this.currentPanelClass);
		}
	}
	if(teldivs > 1)
	{
		Nieuwetimeslide = acti;
		Nieuwetime = setTimeout("Nieuweslide('" + acti + "')",4000);
		
	}
	return panel;
};
function NieuwepauseTime()
{
	if(typeof Nieuwetime == 'number')
	{
		window.clearTimeout(Nieuwetime);
	}
}

function NieuwerestartTime()
{
	if(typeof Nieuwetime == 'number')
	{
		window.clearTimeout(Nieuwetime);
	}
	Nieuwetime = setTimeout("Nieuweslide('" + Nieuwetimeslide + "')",4000);
}

function Nieuweslide(acti)
{
	
	var aantaldivs=get_object('NieuwetickerReflijst').childNodes.length;
	
	var teldivs=0;
	for (iaan=0; iaan<aantaldivs; iaan++)
	{
		if(get_object('NieuwetickerReflijst').childNodes[iaan].tagName =="DIV")
		{
			teldivs= teldivs + 1;
		}
	}
	var ivolgende=parseInt(acti);
	var volgende="";
	var iok =0;
	if(aantaldivs >= ivolgende)
	{
		for (iaan=0; iaan<aantaldivs; iaan++)
		{
			if(get_object('NieuwetickerReflijst').childNodes[iaan].tagName =="DIV" )
			{	
				if(1 == iok)
				{
					volgende = get_object('NieuwetickerReflijst').childNodes[iaan].id;
					iok = 2;
				}
				if((iaan == ivolgende || ivolgende == 0) && iok ==0)
				{
					iok = 1;	
				}
				
			
			}
		}
	}else
	{
		volgende = get_object('NieuwetickerReflijst').childNodes[0].id;
	}
	
	if(volgende =="")
	{
		if(aantaldivs >= ivolgende)
		{
			for (iaan=0; iaan<aantaldivs; iaan++)

			{
				if(get_object('NieuwetickerReflijst').childNodes[iaan].tagName =="DIV" )
				{	
					if(volgende =="")
					{
						volgende = get_object('NieuwetickerReflijst').childNodes[iaan].id;
					}
				}
			}
		}
	}
	Nieuwesp.showPanel(volgende);
}

NieuweSpry.Widget.SlidingPanels.prototype.showFirstPanel = function()
{
	return this.showPanel(0);
};

NieuweSpry.Widget.SlidingPanels.prototype.showLastPanel = function()
{
	return this.showPanel(this.getContentPanels().length - 1);
};

NieuweSpry.Widget.SlidingPanels.prototype.showPreviousPanel = function()
{
	return this.showPanel(this.getContentPanelIndex(this.currentPanel) - 1);
};

NieuweSpry.Widget.SlidingPanels.prototype.showNextPanel = function()
{
	return this.showPanel(this.getContentPanelIndex(this.currentPanel) + 1);
};

NieuweSpry.Widget.SlidingPanels.PanelAnimator = function(ele, curX, curY, dstX, dstY, opts)
{
	this.element = ele;

	this.curX = curX;
	this.curY = curY;
	this.dstX = dstX;
	this.dstY = dstY;
	this.fps = 60;
	this.duration = 1000;
	this.transition = NieuweSpry.Widget.SlidingPanels.PanelAnimator.defaultTransition;
	this.startTime = 0;
	this.timerID = 0;
	this.finish = null;

	var self = this;
	this.intervalFunc = function() { self.step(); };
	
	NieuweSpry.Widget.SlidingPanels.setOptions(this, opts, true);

	this.interval = 1000/this.fps;
};

NieuweSpry.Widget.SlidingPanels.PanelAnimator.defaultTransition = function(time, begin, finish, duration) { time /= duration; return begin + ((2 - time) * time * finish); };

NieuweSpry.Widget.SlidingPanels.PanelAnimator.prototype.start = function()
{
	this.stop();
	this.startTime = (new Date()).getTime();
	this.timerID = setTimeout(this.intervalFunc, this.interval);
};

NieuweSpry.Widget.SlidingPanels.PanelAnimator.prototype.stop = function()
{
	if (this.timerID)
		clearTimeout(this.timerID);
	this.timerID = 0;
};

NieuweSpry.Widget.SlidingPanels.PanelAnimator.prototype.step = function()
{
	var elapsedTime = (new Date()).getTime() - this.startTime;
	var done = elapsedTime >= this.duration;
	var x, y;

	if (done)
	{
		x = this.curX = this.dstX;
		y = this.curY = this.dstY;
	}
	else
	{
		x = this.transition(elapsedTime, this.curX, this.dstX - this.curX, this.duration);
		y = this.transition(elapsedTime, this.curY, this.dstY - this.curY, this.duration);
	}

	this.element.style.left = x + "px";
	this.element.style.top = y + "px";

	if (!done)
		this.timerID = setTimeout(this.intervalFunc, this.interval);
	else if (this.finish)
		this.finish();
};

 
