$(document).ready(function() {
	$("a.zoom").fancybox({
		overlayShow					: true,
		hideOnContentClick	: false,
		zoomSpeedIn					: 10,
		zoomSpeedOut				: 10,
		zoomSpeedChange			: 10
	});

	$("a.youtube").fancybox({
		width					      : 540,
		height					    : 360,
		frameWidth					: 540,
		frameHeight					: 360,
		overlayShow					: true,
		hideOnContentClick	: false,
		zoomSpeedIn					: 0,
		zoomSpeedOut				: 0,
		zoomSpeedChange			: 0
	});

	$("a.zoomdyn").fancybox({
		overlayShow					: true,
		hideOnContentClick	: false,
		zoomSpeedIn					: 0,
		zoomSpeedOut				: 0,
		zoomSpeedChange			: 0
	});
	

	$("a.image_popup").fancybox({
		overlayShow		: true,
		zoomSpeedIn		: 10,
		zoomSpeedOut	: 10,
		zoomSpeedChange	: 10,
		titlePosition	: 'inside'
	});


  $('a.zoomdyn').each(function(){ 
		try {
			var fWidth = parseInt($(this).attr('href').match(/width=[0-9]+/i)[0].replace('width=','')); 
			var fHeight =  parseInt($(this).attr('href').match(/height=[0-9]+/i)[0].replace('height=','')); 
			$(this).fancybox({'frameWidth':fWidth,'frameHeight':fHeight});
			$(this).fancybox({'width':fWidth,'height':fHeight});
		} catch(e) {}
  }); 


  // ********** AUTO POPUP ON LOAD ************
	if ($('#popup_auto').length) {
		$('#popup_auto').fancybox().trigger('click');
	}



  // ********** TABS ************
	if ($('#divTabs').length) {
	  	$("#divTabs").tabs();
	  	$("#divTabs").show();
	  	// set active tab
	  	var param = $.getURLParam('selectedTab');
	  	if (param != '') {
	  	  $('#divTabs').tabs('select', param); 
	  	}
	}


  // ********** EXTERNAL LINKS ************
  $("a[target='_blank']").each(function() {
      $(this).addClass('external_link');
  });




	if ($('#autocomplete_search').length) {
    function formatItem(row) {
	    return row[0].split("#")[1] + row[0].split("#")[2];
    }

		$("#autocomplete_search").autocomplete(ac_list, {
			minChars: 1,
			width: 500,
			max: 20,
			matchContains: true, 
			scroll: false,
			scrollHeight: 400,
	    formatItem: formatItem
		});
	  
		$("#autocomplete_search").result(function () {
			  // find name in list
			  for(var i in ac_list) {
				if (ac_list[i].split("#")[1] + ac_list[i].split("#")[2] == this.value) {
				  top.location.href = ac_list[i].split("#")[0];
				  this.value = 'loading...';
				  return;
				}
			  }
			  // niet gevonden in de lijst, dan naar de search-pagina
			  location.href = 'product_search.aspx?redirect_1_product=1&q=' + escape(this.value);
			})
			
			$("#autocomplete_search").keypress(function(e){ 
				if(e.which == 13) {
					location.href = 'product_search.aspx?redirect_1_product=1&q=' + escape(this.value);
					return false;
				}
			});
    
	}  // if found #autocomplete_product



  if ($(".tooltip").length) {
    $(".tooltip").tooltip({ 
        track: false, 
        delay: 100, 
        showURL: false, 
        opacity: 1, 
        fixPNG: false, 
        showBody: " - ", 
        extraClass: "tooltip_custom", 
        top: -15, 
        left: 30
    }); 
  }
  
  
  
  
  
  //Hide (Collapse) the toggle containers on load
	//$(".toggle_container").hide(); 

	//Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
	$(".toggle_trigger").click(function(){
		$(this).toggleClass("active").next().slideToggle("slow");
		return false; //Prevent the browser jump to the link anchor
	});



});

