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

	$("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,
		showCloseButton				: false,
		zoomSpeedOut				: 0,
		zoomSpeedChange			: 0
	});
	

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


  $('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) {}
  }); 


	if ($('#popup_auto').length) {
		$('#popup_auto').fancybox().trigger('click');
	}


	if ($('#divTabs').length) {
		$("#divTabs").tabs();
	}


	if ($('#tabs').length) {
		$("#divTabs").tabs();
	}






  // ************************************ 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);
      }
      
    });
  }






  // zet in de css de cycleshows op display:none
  // op deze manier:
  //  .cycleshow {display:none;}
	if ($('.cycleshow').length) {
	  $('.cycleshow').show();
    $('.cycleshow').cycle({
      fx:     'fade', 
      timeout:  4000,
      delay:		500,
      speed:		1000,
      pause:		false   // pause on mouseover
    });
  }



  
  
	if ($('#slideshow1').length) {
    $('#slideshow1').before('<div id="slideshow1nav" class="slideshow1nav">').cycle({
      fx:     'fade', 
      timeout: 0,
      pager:  '#slideshow1nav',
      delay:		0,
      speed:		1000,
      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 = 'moment...';
				  return;
			    }
			  }
			  // niet gevonden in de lijst, dan naar de search-pagina
		    location.href = 'collectie.aspx?q=' + escape(this.value);
		  });
  		
  		// Enter uitgezet
  		$("#autocomplete_search").keypress(function(e){ 
			  if(e.which == 13) {
				  return false;
			  }
		  });

  		
//		  $("#autocomplete_search").keypress(function(e){ 
//			  if(e.which == 13) {
//				  location.href = 'collectie.aspx?q=' + escape(this.value);
//				  return false;
//			  }
//		  });
      
	  }  // if found #autocomplete_search



});

