
/* Merged Plone Javascript file
 * This file is dynamically assembled from separate parts.
 * Some of these parts have 3rd party licenses or copyright information attached
 * Such information is valid for that section,
 * not for the entire composite file
 * originating files are separated by - filename.js -
 */

/* - jquery.suggest.js - */

	/*
	 *	jquery.suggest 1.1 - 2007-08-06
	 *
	 *	Uses code and techniques from following libraries:
	 *	1. http://www.dyve.net/jquery/?autocomplete
	 *	2. http://dev.jquery.com/browser/trunk/plugins/interface/iautocompleter.js
	 *
	 *	All the new stuff written by Peter Vulgaris (www.vulgarisoip.com)
	 *	Feel free to do whatever you want with this file
	 *
	 */


	(function($) {

		$.suggest = function(input, options) {

			var $input = $(input).attr("autocomplete", "off");
      var $results = $('<div class="blacktxt"></div>');

			var timeout = false;		// hold timeout ID for suggestion results to appear
			var prevLength = 0;			// last recorded length of $input.val()
			var cache = [];				// cache MRU list
			var cacheSize = 0;			// size of cache in chars (bytes?)
			var driver = new SuggestDriver({suggest: function(items){
        $results.hide();
        displayItems(items);
        }});

      $results.addClass(options.resultsClass).appendTo('body');

			resetPosition();
			$(window)
				.load(resetPosition)		// just in case user is changing size of page while loading
				.resize(resetPosition);

			$input.blur(function() {
				setTimeout(function() { $results.hide() }, 200);
			});


			// help IE users if possible
			try {
				$results.bgiframe();
			} catch(e) { }


			// I really hate browser detection, but I don't see any other way
			if ($.browser.mozilla)
				$input.keypress(processKey);	// onkeypress repeats arrow keys in Mozilla/Opera
			else
				$input.keydown(processKey);		// onkeydown repeats arrow keys in IE/Safari

			function resetPosition() {
        var reference = $input.parents('#search');
				// requires jquery.dimension plugin
				$results.css({
					top: (reference.offset().top + reference.height() + 0) + 'px',
					left: (reference.offset().left + reference.width() - 330) + 'px'
				});
			}


			function processKey(e) {
				// handling up/down/escape requires results to be visible
				// handling enter/tab requires that AND a result to be selected
				if ((/27$|38$|40$/.test(e.keyCode) && $results.is(':visible')) ||
					(/^13$|^9$/.test(e.keyCode) && getCurrentResult())) {

		            if (e.preventDefault)
		                e.preventDefault();
					if (e.stopPropagation)
		                e.stopPropagation();

	                e.cancelBubble = true;
	                e.returnValue = false;

					switch(e.keyCode) {

						case 38: // up
							prevResult();
							break;

						case 40: // down
							nextResult();
							break;

						case 9:  // tab
						case 13: // return
							selectCurrentResult();
							break;

						case 27: //	escape
							$results.hide();
							break;

					}

				} else if ($input.val().length != prevLength) {

					if (timeout)
						clearTimeout(timeout);


					timeout = setTimeout(search,
            options.delay);
					prevLength = $input.val().length;

				}


			}


			function search() {

				var q = $.trim($input.val());

				if (q.length >= options.minchars) {
          driver.suggest(q);
				} else {
					$results.hide();
				}

			}

			/*function checkCache(q) {

				for (var i = 0; i < cache.length; i++)
					if (cache[i]['q'] == q) {
						cache.unshift(cache.splice(i, 1)[0]);
						return cache[0];
					}

				return false;

			}

			function addToCache(q, items, size) {

				while (cache.length && (cacheSize + size > options.maxCacheSize)) {
					var cached = cache.pop();
					cacheSize -= cached['size'];
				}

				cache.push({
					q: q,
					size: size,
					items: items
					});

				cacheSize += size;

			}
      */

			function displayItems(items) {

				if (!items)
					return;

				if (!items.length) {
					$results.hide();
					return;
				}


        var sections = new Object();
				var html = '';
        var item;
        var section;
        var index;

				for (var i = 0; i < items.length; i++){
          item = items[i];

          if (!sections[item.type])
            sections[item.type] = new Array();

          sections[item.type].push(item);
        }


         html = '<div class="box">';

        for (section in sections){

          html += '<div class="producten bgwhite smallpadding group">';
          html += '<h4>' + section + '</h4>';

          for (var i = 0; i < sections[section].length; i++){
            item = sections[section][i];
            html +=
              '<div class="item desc">' +
                (item.image ? '<img class="leftimg borders" src="' + item.image + '" width="58" height="42" alt="" />' : '') +
                '<strong><a class="arrowblue" href="' + item.location + '">' + item.title + '</a></strong><br />';
			html += '</div>';
            if (item.description && item.description!=''){
              html += '<br><ul class="left">';
              for (index = 0; index < item.description.length; index++){
                html += '<li>' + item.description[index] + '</li>';
              }
              html += '</ul>';
            }

            html += '<div class="clear"><!--  --></div>';
          }

          html += '</div>';
        }

        html += '<div class="bgwhite smallpadding righttxt"><a class="arrowblue moresearchresults" href="/zoekresultaten/">Toon alle zoekresultaten</a></div>';
        html += '</div>';

		  //console.log(html);

        $results.html(html);
				$results.find('div.group:odd').removeClass("even").addClass("odd");
        $results.find('div.group:even').removeClass("odd").addClass("even");


        $results.show();

				$results
					.find('div.item')
					.mouseover(function() {
						$results.find('div.item').removeClass(options.selectClass);
						$(this).addClass(options.selectClass);
					})
					.click(function(e) {
						e.preventDefault();
						e.stopPropagation();
						selectCurrentResult();
					});

			}

			function getCurrentResult() {

				if (!$results.is(':visible'))
					return false;

				var $currentResult = $results.find('div.' + options.selectClass);

				if (!$currentResult.length)
					$currentResult = false;

				return $currentResult;

			}

			function selectCurrentResult() {

				$currentResult = getCurrentResult();

				if ($currentResult) {
					if($currentResult.find('a').attr('href').replace(location.href,'')!='#') {
						jQuery('#search_category').val(decodeURIComponent($currentResult.find('a').attr('href').replace(location.href,'')));
					} else {
						jQuery('#search_category').val('');
					}
					$input.val($currentResult.text());
					$results.hide();

					if (options.onSelect)
						options.onSelect.apply($input[0]);

				}

			}

			function nextResult() {
        var list;

			  $currentResult = getCurrentResult();

        if ($currentResult) {
          list = $results.find('div.item');


          // locate current result in list.
          $(list).each(function(){
            if ($(this).hasClass(options.selectClass)){
              $currentResult = this;
            }
          });

          $($currentResult).removeClass(options.selectClass);
          index = $(list).index($currentResult) + 1;
          if (index < list.size())
            $(list.get(index)).addClass(options.selectClass);
          else
            $($results.find('div.item').get(0)).addClass(options.selectClass);

				} else {
          $($results.find('div.item').get(0)).addClass(options.selectClass);
			  }
			}

			function prevResult() {
			  var list;
        var index;

				$currentResult = getCurrentResult();

				if ($currentResult) {
          list = $results.find('div.item');

          // locate current result in list.
          $(list).each(function(){
            if ($(this).hasClass(options.selectClass)){
              $currentResult = this;
            }
          });

          $($currentResult).removeClass(options.selectClass);

          index = $(list).index($currentResult) - 1;

          if (index >= 0)
            $(list.get(index)).addClass(options.selectClass);
          else
            $($results.find('div.item').slice(-1)).addClass(options.selectClass);

				} else {
					$($results.find('div.item').slice(-1)).addClass(options.selectClass);
			  }

			}

		}

		$.fn.suggest = function(options) {

		  options = options || {};
			options.delay = options.delay || 100;
			options.resultsClass = options.resultsClass || 'ac_results';
			options.selectClass = options.selectClass || 'ac_over';
			options.matchClass = options.matchClass || 'ac_match';
			options.minchars = options.minchars || 2;
			options.delimiter = options.delimiter || '\n';
			options.onSelect = options.onSelect || false;
			options.maxCacheSize = options.maxCacheSize || 65536;

			this.each(function() {
				new $.suggest(this, options);
			});

			return this;

		};

	})(jQuery);



/* - jquery-effects.js - */
var $j = jQuery.noConflict();
		
    $j(document).ready(function() {
		if ($j('#slider1').length) {
			$j('#slider1').s3Slider({
            	timeOut: 4000 
        	});
		}
		else {
			return;
		};
    });
    $j(document).ready(function(){
		//$("#tabscontent").tabs();
		$j("#tabscontent").tabs({ fx: { opacity: 'toggle' } }).tabs('rotate', 10000);
  	});
  	$j(document).ready(function(){
		$j("#tabscontent2").tabs();
  	});
