﻿
/* ---------------------------------------------------------------------------------- */
/* ----- Functies: onLoad ----------------------------------------------------------- */
/* ---------------------------------------------------------------------------------- */

var carouselleft = 0;

$(document).ready(function() {
  zetNajaarsActieFlash();
  if ($('#carousel').length > 0) {
    /* Carousel op home activeren */
    var deinnerfade = $('#carousel_inner').innerfade({
      speed: 'slow',
      timeout: 10000,
      type: 'sequence',
      containerheight: '325px'
    });
  }

  jQuery('.relative-products .products-overview').jcarousel({ start: carouselleft });


  if ($('#webcam').length > 0) {
    setInterval("updateWebCam()", 5000);
  }
  //  $(".lightbox").lightbox();
  $("a[rel='colorbox']").colorbox({ slideshow: true, speed: 500, slideshowSpeed: 5000 });
  $("a[rel='colorbox2']").colorbox({ slideshow: true, speed: 500, slideshowSpeed: 5000 });
  initFader("#carousel2", 3000, 2000);


  $(".stap1 input").bind("keyup", function(e) { if ((document.layers ? evt.which : e.keyCode) == 13) { stap1knop(); } });
  bindInputEvents(".stap1 input", "Kortingscode",false );
  

});

function stap1knop()
{
  $(".stap1 .discount-btn").click();
}

// Input-elementen voorzien van blur en focus events om standaard-tekst te tonen/verbergen
function bindInputEvents(inputElement, defaultValue, overruleVal) {
  if (overruleVal == true) {
    $(inputElement).val(defaultValue);
  }
  $(inputElement).bind("focus", function(e) {
    if (this.value == defaultValue) $(this).val("").addClass("active");
  }).bind("blur", function(e) {
    if (this.value == "") $(this).val(defaultValue).removeClass("active");
  });
}
//$.fn.lightbox.changeImage(opts.activeImage - 1);


/* ---------------------------------------------------------------------------------- */
/* ----- Functies: Algemeen --------------------------------------------------------- */
/* ---------------------------------------------------------------------------------- */

// Standaard-tekst in input verbergen (onFocus)
function textFieldFocus(object, defaultValue) {
  if (object.value == defaultValue) {
    object.value = "";
  }
  object.className = "active";
}

// Standaard-tekst in input tonen (onBlur)
function textFieldBlur(object, defaultValue) {
  if (object.value == "") {
    object.value = defaultValue;
    object.className = "";
  }
}

function updateWebCam() {
  var date = new Date();
  var random = date.getTime();
  $('#webcam img').attr('src',webcamUrl + "?" + random);
}

function initFader(container, pauseDuration, fadeDuration) {
  var maxItems = $(container).find("li").length;
  if (maxItems > 1) {
    var nextItem = 1;
    var currentItem = 0;

    setInterval(function() {
      if (nextItem > (maxItems - 1)) { nextItem = 0; }
      if (currentItem) $(container).find("li:eq(" + currentItem + ")").fadeOut(fadeDuration, function(e) { $(this).css("z-index", "auto") });
      $(container).find("li:eq(" + nextItem + ")").css("z-index", "10").fadeIn(fadeDuration);
      currentItem = nextItem;
      nextItem++;
    }, (pauseDuration + fadeDuration));
  }
}

function zetNajaarsActieFlash(){
  if ($("body.home #najaarsactie").length > 0)
  {
    $("body.home #najaarsactie").flash(null, { version: 9 }, function(htmlOptions) {
      var $this = $(this);
      $("body.home #najaarsactie").css("top", ($(window).height() - 550) + "px");
      htmlOptions.src = '/interface/flash/struisvogels.swf';
      htmlOptions.width = 990;
      htmlOptions.height = 550;
      htmlOptions.wmode = 'transparent';
      htmlOptions.allowFullscreen = 'true';
      htmlOptions.allowScriptAccess = 'always';
      $this.html('');
      $this.addClass('flash-replaced').prepend($.fn.flash.transform(htmlOptions));
    });
  }
}

function hideFlash(){
  setTimeout(function(){ $("body.home #najaarsactie").hide()},500);
}
