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

	$("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,'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); 
	  	}
	  	param = $.getURLParam('selectedtab');
	  	if (param != '') {
	  	  $('#divTabs').tabs('select', param); 
	  	}
	}


  // ********** EXTERNAL LINKS ************
//  $("a[target='_blank'").not("[href*='beheer/']").each(function() {
//      $(this).addClass('external_link');
//  });




  
  
	if ($('#slideshow1').length) {
    $('#slideshow1').cycle({
      fx:     'fade', 
      timeout: 2000,
      pager:  '#slideshow1nav',
      delay:		0,
      speed:		2000,
      pause:		0     // pause on mouseover
    });
  }





	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





  // ************************************ CMS EDIT ************************************
  if ($(".divEdit img").length) {
    $(".divEdit img").css('border', '1px solid transparent');
    $(".divEdit img").hover( function(){
      $(this).css('border', '1px solid #333');
    },function(){
      $(this).css('border', '1px solid transparent');
    });
    
    // CHECK JS LOADED
    if (!$.cookie) {
      //alert('add javascript for jquery.cookie.js in header');
      return;
    }
    
    // If FrontEdit in Url-Params = ON, show message
    if ($.getURLParam("FrontEdit") == 'true' || $.getURLParam("FrontEdit") == '1' || $.getURLParam("FrontEdit") == 'True' || 
        $.getURLParam("frontedit") == 'true' || $.getURLParam("frontedit") == '1' || $.getURLParam("frontedit") == 'True' || 
        $.getURLParam("Frontedit") == 'true' || $.getURLParam("Frontedit") == '1' || $.getURLParam("Frontedit") == 'True') {
        $('body').showMessage({	
          thisMessage       : ['Use SHIFT+E to enable/disable FRONT-EDIT'],
          className         : 'showMessage_Green',
          displayNavigation : false,
          delayTime         : 10000,
          position          : 'top',
          autoClose         : true});
    }
    
    // HIDE Edit using Cookie
    if ($.cookie("FrontEdit") == '0') {
      $(".divEdit").hide();
    }
    
    // Shift+E pressed, enable/disable FrontEdit
    $(document).bind('keypress', function(event) {
      var keycode = (event.keyCode ? event.keyCode : event.which);

      // Shift+E pressed, enable/disable FrontEdit
      if ((keycode == 69) && (event.shiftKey)) {

        // GET VALUE FROM COOKIE
        var FrontEdit = $.cookie("FrontEdit");
        
        // TOGGLE ON | OFF
        if (FrontEdit=='0') {
          FrontEdit = '1';
          $(".divEdit").show();
        } else {
          FrontEdit = '0';
          $(".divEdit").hide();
        }
        
        // SAVE COOKIE
        $.cookie("FrontEdit", FrontEdit);
      }
      
    });
  }







  // Nice Tooltip
  if ($(".tooltip").length) {
    $(".tooltip").tooltip({ 
        track: false, 
        delay: 100, 
        showURL: false, 
        opacity: 0.8, 
        fixPNG: true, 
        showBody: " - ", 
        extraClass: "tooltip_custom", 
        top: -15, 
        left: 30
    }); 
  }



  // Facebook Autocomplete
  if ($(".fcbkcomplete").length) {
		$(".fcbkcomplete").fcbkcomplete({
			cache: true,
			addontab: true,
			height: 20,
			firstselected: false
		});
		$(".fcbkcomplete option:selected").removeAttr("selected");
  }



});

