var cScrollStep = 5;
var cScrollSpeed = 20;
var ScrollTimeOut;
var TimeScrolling = 0;
var strBrowser    = "";
var ContentHoekROoffset = 0;
var TopDivOffset = 0;
var BottomDivOffset = 0;

var theDiv;

var DLC_ImageArray = new Array(
"/style%20library/koreindelunchclub/tn-boterhamgeel.gif","/style%20library/koreindelunchclub/tn-boterhamgeelhover.gif",
"/style%20library/koreindelunchclub/spn-boterhamdonker.gif"
);

function DeLunchClubOnLoad()
{
	// Gridview van FAQ webpart inklappen
	if (theGV = document.getElementById('FAQgview'))
		CloseGroupedGridView(theGV);
	
	// Browser bepalen
	GetBrowser();
	
	theDiv = document.getElementById("KoreinContent");
	
	var KCHRO = document.getElementById("KoreinContentHoekRO");
	var THD = document.getElementById("TopHolderDiv");
	var BCD = document.getElementById("BreadcrumbDiv");
	var CTD = document.getElementById("ContentTableDiv");
	var CFD = document.getElementById("ContentFooterDiv");
	
	var RCC = document.getElementById("RightContentCell");
	var theTD = document.getElementById("RightContentTopCorners");
	var theBD = document.getElementById("RightContentBottomCorners");
	
	// Mouse scroll wheel event aan content div hangen
	if (theDiv)
		hookEvent(theDiv, "mousewheel", DoMouseWheel);
	
	// Positie van ronde hoek van content area goed zetten
	if (KCHRO && THD && BCD && CTD && CFD)
	{
		var newTop = THD.clientHeight + BCD.offsetHeight + CTD.offsetHeight - CFD.offsetHeight + ContentHoekROoffset;
		
		KCHRO.style.display = "block";
		KCHRO.style.top = (newTop - KCHRO.clientHeight) + "px";
	}

	// Positie van ronde hoeken van right content area goed zetten
	if (THD && RCC && theTD && theBD)
	{
		var newTop = THD.clientHeight + BCD.offsetHeight;
		
		theTD.style.display = "block";
		theTD.style.top = (newTop + TopDivOffset) + "px";
		
		theBD.style.display = "block";
		theBD.style.top = (newTop + RCC.clientHeight - theBD.clientHeight + BottomDivOffset) + "px";
	}
	
	// PNG images aanpassen voor IE6
	if (strBrowser == "MSIE6")
		correctPNG();
	
	// Als de console balk wordt weergegeven, dan ronde hoekje verbergen
	var theCD = document.getElementById("ConsoleDiv");
	if (theCD)
	{
		var theCT = theCD.getElementsByTagName("table");
		if (theCT.length > 0)
		{
			if (KMDH = document.getElementById("KoreinMiddleBovenHoekje"))
			{
				KMDH.style.backgroundImage = "none";
				if (KCHRO)
				{
					KCHRO.style.display = "none";
				}
			}
			if (theTD && theBD)
			{
				theTD.style.display = "none";
				theBD.style.display = "none";
			}
			
			var SPT = document.getElementById("StartPageT");
			var SPO = document.getElementById("StartPageO");
			var SPP = document.getElementById("StartPageP");
			
			if (SPT)
				SPT.style.display = "none";
				
			if (SPO)
				SPO.style.display = "none";
				
			if (SPP)
				SPP.style.display = "none";
		}
		
		// Als in edit mode, dan content areas laten groeien met de inhoud
		if (document.forms[0].MSOLayout_InDesignMode.value == '1')
		{
			if (temp = document.getElementById('PageImages'))
				temp.style.display = 'none';
				
			if (temp = document.getElementById('WeetjeDiv'))
			{
				temp.style.overflow = 'visible';
				temp.style.position = 'relative';
			}
		}
	}
	
	// Images preloaden
	if (DLC_ImageArray.length > 0)
	{
		for (var i = 0; i < DLC_ImageArray.length; i++)
		{
			var PreLoad = new Image();
			if (DLC_ImageArray[i].length > 0)
			{
				PreLoad.src = DLC_ImageArray[i];
			}
		}
	}
}
function CloseGroupedGridView(theGV)
{
	var theRows = theGV.getElementsByTagName('TR');
	for (i = 0; i < theRows.length; i++)
	{
		if (theRows[i].className == 'ms-gb')
		{
			if (theLink = theRows[i].childNodes[0].childNodes[0])
			{
				if (document.dispatchEvent)
				{
				    var oEvent = document.createEvent('MouseEvents');
				    oEvent.initMouseEvent("click", true, true,window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
				    theLink.dispatchEvent(oEvent);
				}
				else
				{
					theLink.fireEvent('onclick');
				}
			}
		}
	}
}
function StartScrollUp()
{
	ScrollTimeOut = window.setTimeout("Scroll(" + (cScrollStep * -1) + ", true)", cScrollSpeed);
}
function StartScrollDown()
{
	ScrollTimeOut = window.setTimeout("Scroll(" + cScrollStep + ", true)", cScrollSpeed);
}
function StopScroll()
{
	clearInterval(ScrollTimeOut);
	TimeScrolling = 0;
}
function DoMouseWheel(e)
{
	e = e ? e : window.event;
	var raw = e.detail ? e.detail : e.wheelDelta;
	var normal = e.detail ? e.detail : e.wheelDelta / 40;
	
	var theStep;
	
	if (raw == normal)
		theStep = raw * 4;
	else
		theStep = raw * -1 / 10;
	
	Scroll(theStep, false);
	TimeScrolling = 0;
	
	return CancelEvent(e);
}
function Scroll(step, timeout)
{
	if (theDiv)
	{
		if (theDiv.clientHeight < theDiv.scrollHeight)
		{
			var newPos = theDiv.scrollTop;
			
			newPos = newPos + step;
			TimeScrolling = TimeScrolling + cScrollSpeed;
			
			if ((TimeScrolling >= 1000) && ((step == (cScrollStep * 1)) || (step == (cScrollStep * -1))))
					step = step * 2;
			else if ((TimeScrolling >= 2000) && ((step == (cScrollStep * 2)) || (step == (cScrollStep * -2))))
					step = step * 2;
			
			if (newPos < 0)
				newPos = 0;
			
			if (newPos > theDiv.scrollHeight)
				newPos = theDiv.scrollHeight;
				
			theDiv.scrollTop = newPos
			
			if (newPos >= (newPos + theDiv.clientHeight))
				timeout = false;
			
			if (timeout)
				ScrollTimeOut = window.setTimeout("Scroll(" + step + ", true)", cScrollSpeed);
		}
	}
}
function NavigationBarHover(obj)
{
	var theDiv = obj.childNodes[0];
	
	if (theDiv)
	{
		if (theDiv.className.indexOf("-Hover") > -1)
		{
			theDiv.className = theDiv.className.replace("-Hover","");
		}
		else
		{
			theDiv.className = theDiv.className + "-Hover";
		}
	}
}
function NavigationBarOnClick(obj)
{
	var theLink = obj.childNodes[0].childNodes[0];
	
	if (theLink)
	{
		if (theLink.target == "_self")
		{
			document.location = theLink.href;
		}
		else
		{
			window.open(theLink.href);
		}
	}
	
	return false;
}
function SearchBoxKeyPress(k)
{
	var unicode = k.keyCode? k.keyCode : k.charCode;
	
	if (unicode == 13 || unicode == 10)
	{
		k.returnValue = false;
		DoSearch();
		return false;
	}
	else
	{
		return true;
	}
}
function DoSearch()
{
	var sb = document.getElementById("searchbox");
	
	if (sb)
	{
		if (sb.value != "")
			window.location = "/pages/results.aspx?k=" + encodeURIComponent(sb.value);
		else
			alert('U heeft geen zoekwoord opgegeven');
	}
}
function GetBrowser()
{
	strBrowser = navigator.appVersion;
	if (strBrowser.indexOf('MSIE') > 0)
		strBrowser = "MSIE" + parseFloat(strBrowser.substring(strBrowser.indexOf('MSIE') + 5));
	else
		strBrowser = navigator.appName + parseInt(strBrowser);
}
function correctPNG() 
{
	for(var i=0; i<document.images.length; i++)
	{
		var img = document.images[i];
		var imgName = img.src.toUpperCase();
		
		if (imgName.substring(imgName.length - 3, imgName.length) == "PNG")
		{
			var imgID = (img.id) ? "id='" + img.id + "' " : "";
			var imgClass = (img.className) ? "class='" + img.className + "' " : "";
			var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
			var imgStyle = "display:inline-block;" + img.style.cssText;
			
			if (img.align == "left")
				imgStyle = "float:left;" + imgStyle;
				
			if (img.align == "right")
				imgStyle = "float:right;" + imgStyle;
			
			if (img.parentElement.href)
				imgStyle = "cursor:hand;" + imgStyle;
			
			var strNewHTML = "<span " + imgID + imgClass + imgTitle
			+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
			
			img.outerHTML = strNewHTML;
			i = i - 1;
		}
	}
}
function CancelEvent(e)
{
	e = e ? e : window.event;
	
	if(e.stopPropagation)
		e.stopPropagation();
	
	if(e.preventDefault)
		e.preventDefault();
	
	e.cancelBubble = true;
	e.cancel = true;
	e.returnValue = false;
	
	return false;
}
function hookEvent(element, eventName, callback)
{
	if(element.addEventListener)
	{
		if(eventName == 'mousewheel')
		{
			element.addEventListener('DOMMouseScroll', callback, false);  
		}
		else
		{
			element.addEventListener(eventName, callback, false);
		}
	}
	else if(element.attachEvent)
	{
		element.attachEvent("on" + eventName, callback);
	}
	else
	{
		// Older browsers
		var currentEventHandler = elementObj['on' + eventName];
		if (currentEventHandler == null)
			elementObj['on' + eventName] = eventHandlerFunctionName;
		else
			elementObj['on' + eventName] = function(e) { currentEventHandler(e); eventHandlerFunctionName(e); }
	}
}

// Bind scripts to events
hookEvent(window, "load", DeLunchClubOnLoad);

// Overrule standard sharepoint scripts
function ProcessImn() { }



