"use strict";
(function ($) {
  $(function () {

    //imagecarousel
    function buildCarousel(init) {
      var folder = "/media/images/photos/",
          images = ["home" + init + "a.jpg","home" + init + "b.jpg","home" + init + "c.jpg","home" + init + "d.jpg"],
          current = $("#home" + init).html(""),
          holder = $("<div>").attr({id:"headerimg"+init}).appendTo(current),
          builtimage, link;

      for(var i=0,l=images.length; i<l; i++) {
        link = folder+images[i];
        builtimage = $("<img>").attr({"src":link,"alt":""}).appendTo(holder);
      }

      holder.cycle({
        fx: 'fade',
        speed : 2500,
        timeout : 5000
      });
    }
    if($("#home1").length) {
      buildCarousel(1);
      buildCarousel(2);
      buildCarousel(3);
    }

    // youtubes
    $("a.oembed").oembed();

    // tickets - calculate price [wout]
    var ticketshop = {
      // Calculate total price
      refresh: function() {
        totalprice = 0;
        $("#ticketshop .quantityField").each(function(i, o) {
          totalprice += o.value * ticketshop_price[o.name];
        });

        $("#total").text(totalprice.toFixed(2));
      }
    }

    if($("#ticketshop")) {
      $("#ticketshop .quantityField").change(ticketshop.refresh);
      ticketshop.refresh();
    }
  });
}(jQuery));


