$(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;
			  }
		  }
		  // Het idee: Niet gevonden in de lijst, dan naar de search-pagina.
		  // deze redirect wordt niet gestart in deze result-functie.
		  // vandaar dat hieronder een keypress-event wordt gezet.
		  location.href = 'product_search.aspx?redirect_1_product=1&q=' + escape(this.value);
		});
		
		
		//  Dit werkt nog niet goed, omdat bij ENTER zowel de Result-functie, als de keypress-functie wordt gestart.
		
  	$("#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 ($(".div_tooltip").length) {
      // hide tooltips
      $(".div_tooltip div").css("display", "none");
      $(".div_tooltip div").css("visible", "hidden");
      
      // add tooltips
      $(".div_tooltip").each(function() {
        $(this).simpletip({
         content : $(this).find('div').html(),
         fixed : false,
         position : [50,1],
         showeffect: 'fade'
        })
      });
   }



});

