$(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,'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); 
	  	}
	}





  // ************************************ 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_Visible") != "1") {
      $(".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_Visible = false;
        FrontEdit_Visible = ($.cookie("FrontEdit_Visible") == "1");
        
        // Er is SHIFT-E geklikt, dus hij moet omdraaien
        FrontEdit_Visible = !FrontEdit_Visible;
        
        // SAVE NEW VALUE IN COOKIE
        if (FrontEdit_Visible) {
          // Yes show edit and save new value into cookie
          $(".divEdit").show();
          $.cookie("FrontEdit_Visible", "1");
        } else {
          // Don't display edit and save new value into cookie
          $(".divEdit").hide();
          $.cookie("FrontEdit_Visible", "0");
        }
        
      }
      
    });
  }





  
  


//	if ($('#slideshow1').length) {
//    $('#slideshow1').before('<div id="slideshow1nav" class="slideshow1nav">').cycle({
//      fx:     'fade', 
//      timeout: 0,
//      pager:  '#slideshow1nav',
//      delay:		0,
//      speed:		1000,
//      pause:		0
//    });
//  }


  
	if ($('#slideshow1').length) {
    $('#slideshow1').cycle({
      fx:     'fade', 
      timeout: 2000,
      delay:		0,
      speed:		3000,
      pause:		0
    });
  }





  // ********** EXTERNAL LINKS ************
  $("a[target='_blank'").not("[href*='beheer/']").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 ($(".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'
        })
      });
   }



});

