	/***************************************************/
	/****			RESILUX JavaScript CODE			****/
	/****					  by					****/
	/****			    Dimitry Dierickx			****/
	/***************************************************/
	
	/****	PLUGINS									****/

	// # QUERYSTRING # //
	// By http://stackoverflow.com/questions/901115/get-querystring-values-in-javascript/2880929#2880929
	
	var urlParams = {};
	(function () {
		var e,
			a = /\+/g,  // Regex for replacing addition symbol with a space
			r = /([^&=]+)=?([^&]*)/g,
			d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
			q = window.location.search.substring(1);
	
		while (e = r.exec(q))
		   urlParams[d(e[1])] = d(e[2]);
	})();

	/****	SPOTLIGHT								****/
	
	var spotlight_toggle		= 'on';
	var spotlight_cookie		= 'spotlight';
	
	var spotlight_item_width	= 717;
	var spotlight_full_width	= 717;
	var spotlight_item_timer;
	var spotlight_item_count	= 1;
	var spotlight_item_current	= 1;
	var spotlight_item_prevpos	= 0;
	var spotlight_item_scroll_interval	= 7000;
	
	var spotlight_feed_scroll_direction		= 1;
	var spotlight_feed_scroll_increment		= (isIE ? 1.1 : 1); // IE-bug, 1 doesn't work...
	var spotlight_feed_scroll_total			= -25;
	var spotlight_feed_scroll_interval		= 100;
	var spotlight_feed_timer;
	var spotlight_feed_height	= 220;
	
	$(function()
	{
		// Disable spotlight for older versions
		if(!disableSpotlight)
		{
			// Calculate some facts
			spotlight_item_count	= $('#spotlight_item_feed').find('.spotlight_item').length;
			spotlight_full_width	= spotlight_item_count * spotlight_item_width;
			spotlight_feed_height	= $('#spotlight_feed_items').outerHeight() - $('#spotlight_feed').outerHeight();
			
			// Set those facts in CSS
			$('#spotlight_item_feed').css('width', spotlight_full_width + 'px');
			
			// Set the scrollbars to the correct frames
			$('.spotfeed_scrollpane').jScrollPane();
			$('.spotitem_scrollpane').jScrollPane({
				animateScroll: true
			});
			
			// Some button interactions
			$('#spotlight_arrow_right').click(function(){
				scrollItemWithNextButton();
				//$('.spotitem_scrollpane').data('jsp').scrollByX(717);
				return false;
			});
			
			$('#spotlight_arrow_left').click(function(){
				scrollItemWithPrevButton();
				//$('.spotitem_scrollpane').data('jsp').scrollByX(-717);
				return false;
			});
			
			// Hide the buttons when necessary
			checkButtons();
			
			// Some mouse interactions
			$('#spotlight_item').mouseenter(function() { clearInterval(spotlight_item_timer); });
			$('#spotlight_item').mouseleave(function() { spotlight_item_timer = setInterval(scrollItem, spotlight_item_scroll_interval); });
			$('#spotlight_feed').mouseenter(function() { clearInterval(spotlight_feed_timer); });
			$('#spotlight_feed').mouseleave(function() { spotlight_feed_timer = setInterval(scrollFeed, spotlight_feed_scroll_interval); });
			
			// Autoscroll feeds
			animateSpotlight();
			
			// Scrollbar position and snapping
			$('.spotfeed_scrollpane .jspDrag').mouseup(updateFeedPosition);
			$('.spotitem_scrollpane .jspDrag').mouseup(updateItemPosition);
			
			
			
			// Fetch cookie-data and toggle the spotlight on/off by user preference
			var spotlight_cookie_val	= getCookie(spotlight_cookie);
			if(spotlight_cookie_val != null && spotlight_cookie_val != spotlight_toggle) toggleSpotlight();
		}
		
		// Show the 'show/hide' button and bind the events
		$('#spotlight_toggle').show();
		$('#spotlight_toggle').click(toggleSpotlight);
		
		// Equalize children height were needed
		equalizeHeight();
		equalizeHeightByPC();
	});
	
	function equalizeHeight()
	{
		$('.equalheightchildren').each(function(index)
		{
			var children	= $(this).children().not('.noequalheight');
			var height	= 0;
			children.each(function(index)
			{
				if(height < $(this).height())
					height = $(this).height();
			});
			children.css({'height' : height+'px'});
		});
	}
	
	function equalizeHeightByPC()
	{
		
		$('.ehp').each(function(index)
		{
			var children	= $('.ehc', this).not('.neh');
			var height	= 0;
			children.each(function(index)
			{
				if(height < $(this).height())
					height = $(this).height();
			});
			children.css({'height' : height+'px'});
		});
	}
	
	function checkButtons()
	{
		if(spotlight_item_current == 1)						$('#spotlight_arrow_left').hide(isIE ? 0 : 200); else $('#spotlight_arrow_left').show(isIE ? 0 : 200);
		if(spotlight_item_current == spotlight_item_count)	$('#spotlight_arrow_right').hide(isIE ? 0 : 200); else $('#spotlight_arrow_right').show(isIE ? 0 : 200);
	}
	
	function scrollFeed()
	{
		var increment	= spotlight_feed_scroll_increment;
		
		if(spotlight_feed_scroll_direction == 1)
		{
			// Scrolling down
			if(spotlight_feed_scroll_total >= (spotlight_feed_height + 25))
			{
				// Switch the direction
				spotlight_feed_scroll_direction = 0;
			}
		} else {
			increment	= increment * -1;
			
			// Scrolling up
			if(spotlight_feed_scroll_total <= 0)
			{
				// Switch the direction
				spotlight_feed_scroll_direction = 1;
			}
		}
		
		if(spotlight_feed_scroll_total >= 0)	$('.spotfeed_scrollpane').data('jsp').scrollByY(increment);
		spotlight_feed_scroll_total += increment;
	}
	
	function scrollItemTo(itemnr)
	{
		var position	= (itemnr - 1) * spotlight_item_width;
		$('.spotitem_scrollpane').data('jsp').scrollToX(position);
		checkButtons();
	}
	
	function scrollItem() {
		if(TabHasFocus())
		{
			spotlight_item_current++;
			
			if(spotlight_item_current > spotlight_item_count)
			{
				spotlight_item_current = 1;
			}
			
			scrollItemTo(spotlight_item_current);
		}
	}
	
	function scrollItemWithNextButton()
	{
		if(spotlight_item_current < spotlight_item_count) spotlight_item_current++;
		scrollItemTo(spotlight_item_current);
	}
	
	function scrollItemWithPrevButton()
	{
		if(spotlight_item_current > 1)	spotlight_item_current--;
		scrollItemTo(spotlight_item_current);
	}
	
	function updateItemPosition()
	{
		// Set the variables
		var curr_item	= 1;
		var percentage	= Math.round((parseInt($('.spotitem_scrollpane .jspDrag').css('left')) / (spotlight_item_width)) * 100);
		var position	= (percentage/100) * spotlight_full_width;
		
		// Get the scroll direction
		var scrolldir	= (position < spotlight_item_prevpos) ? 0 : 1; // 0: <-- || 1: --> 
		
		// Use this info to correctly round our position
		if(scrolldir == 1)
		{
			// Scroll to right
			curr_item	= Math.ceil(position / (spotlight_item_width + 1)) + 1;
		} else {
			// Scroll to left
			curr_item	= Math.floor(position / (spotlight_item_width + 1)) + 1;
		}
		
		// Update position
		spotlight_item_prevpos	= position;
		
		// Scroll to this item, and mark it as our current item
		spotlight_item_current = curr_item;
		scrollItemTo(curr_item);
	}
	
	function updateFeedPosition()
	{
		var prevpos		= spotlight_feed_scroll_total;
		var maxtop		= parseInt($('.spotfeed_scrollpane').css('height')) - parseInt($('.spotfeed_scrollpane .jspDrag').css('height'));
		var curtop		= parseInt($('.spotfeed_scrollpane .jspDrag').css('top'));
		var maxcnt		= spotlight_feed_height;
		var position	= (Math.floor((curtop/maxtop)*100)/100) * maxcnt;
		
		spotlight_feed_scroll_direction	= (position < prevpos) ? 0 : 1;
		spotlight_feed_scroll_total	= position;
	}
	
	function animateSpotlight()
	{
		spotlight_item_timer	= setInterval(scrollItem, spotlight_item_scroll_interval);
		spotlight_feed_timer	= setInterval(scrollFeed, spotlight_feed_scroll_interval);
	}
	
	function stopSpotlight()
	{
		clearInterval(spotlight_item_timer);
		clearInterval(spotlight_feed_timer);
	}
	
	function toggleSpotlight()
	{
		if(spotlight_toggle == 'on')
		{
			// Hide spotlight
			stopSpotlight();
			$('#spotlight_toggle').html('show');
			
			$('#bg_spotlight').addClass('hiddenspotlight');
			$('#spotlight').addClass('hiddenspotlight');
			$('#ie6warning').addClass('hiddenspotlight');
			$('#spacer_header').addClass('hiddenspotlight');
			
			spotlight_toggle	= 'off';
		}
		else
		{
			// Show spotlight
			animateSpotlight();
			$('#spotlight_toggle').html('hide');
			
			$('#bg_spotlight').removeClass('hiddenspotlight');
			$('#spotlight').removeClass('hiddenspotlight');
			$('#ie6warning').removeClass('hiddenspotlight');
			$('#spacer_header').removeClass('hiddenspotlight');
			
			spotlight_toggle	= 'on';
		}
		
		setCookie(spotlight_cookie, spotlight_toggle, 7);
	}
	
	
	/****	SUBMENU EXPAND							****/

	$(function()
	{
		$('div.page_navi_sub').each(function(index) {
			if(!$(this).hasClass('sub_active'))
			{
				$(this).hide();
			}
		});
		
		
	});

	function toggleSubmenu(sub_id)
	{
		return true;
		
		if($('#'+sub_id).is(':hidden')) {
			$('#'+sub_id).slideDown();
		} else {
			$('#'+sub_id).slideUp();
		}
		
		return false;
	}
	
	
	/****	LANGUAGE SELECTION						****/
	
	function fetchLanguages()
	{
		var my_array = new Array();
						
		$('#language option').each(function(index) {
			my_array[my_array.length]	= $(this).val();
		});
		
		return my_array;
	}
	
	function fetchNewLink(lang)
	{
		var cur_link	= location.href;
		var arr_lang	= fetchLanguages();
		var str_lang	= arr_lang.join('|');
		var reg_ptrn	= '(\/)(' + str_lang + ')(\/)?';
		
		var p			= new RegExp(reg_ptrn, 'i');
		var new_link	= cur_link.replace(p, '$1'+lang+'$3');
		
		return new_link;
	}
	
	function switchLanguage() {
		var my_lang	= $('#language').val();
		var my_link	= fetchNewLink(my_lang);
		
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+365);
		document.cookie= 'res_lang' + "=" + escape(my_lang)+ '; expires=' + exdate.toGMTString() + ';path=';
		
		redirectToLink(my_link);
	}
	
	/****	SEARCH FIELD							****/
	
	$(function() {
		// Put a search word in our search field, or hide it when it has focus
		$('#search .searchfield').focus(function() {
			if($(this).val() == "search")
			{
				$(this).val('');
			}
		});
		
		$('#search .searchfield').blur(function() {
			if($(this).val() == "")
			{
				$(this).val('search');
			}
		});
		
		$('#search .searchfield').keyup(function() {
			if($(this).val() != "" && $(this).val() != "search")
			{
				clearHighlights();
				highlightSearch($(this).val());
			}
		});
		
		// Highlight a word
		if(urlParams["highlight"] != null)
		{
			clearHighlights();
			highlightSearch(urlParams["highlight"]);
		}
	});
	
	function highlightSearch(str)
	{
		$('div#page_content, div#page_info').highlight(str, "highlight");
	}
	
	function clearHighlights()
	{
		$('div#page_content, div#page_info').removeHighlight();
	}
	
	/****	GLOBAL FUNCTIONS						****/
	
	function redirectToLink(url)
	{
		if(location.replace)
		{
			location.replace(url);
		} else {
			location.href	= url;
		}
	}
	
	/***************************************************/
