// Initialise scripts
$(document).ready(function () {
    // Nav main  
    $('#nav-main .nav-main-sub').hide();
    $('#nav-main ul > li').hover(function () {
        $(this).children('.nav-main-sub').show();
        if ($(this).hasClass('active')) {
            return;
        }
        else {
            if ($(this).hasClass('koken')) {
                $(this).css('background-position', '0 -62px').addClass('highlight');
            }
            else if ($(this).hasClass('schenken')) {
                $(this).css('background-position', '0 -93px').addClass('highlight');
            }
            else if ($(this).hasClass('tafelen')) {
                $(this).css('background-position', '0 -124px').addClass('highlight');
            }
            else {
                $(this).css('background-position', '0 -31px').addClass('highlight');
            }
        }
    },
  function () {
      $(this).children('.nav-main-sub').hide();
      if ($(this).hasClass('active')) {
          return;
      }
      else {
          $(this).css('background-position', '0 0').removeClass('highlight');
      }
  });

    // Set active nav item on page load
    $.fn.setActiveState = function (list) {
        if ($(this).hasClass('koken')) {
            return this.css('background-position', '0 -62px').children('a');
        }
        else if ($(this).hasClass('schenken')) {
            $(this).css('background-position', '0 -93px').children('a');
        }
        else if ($(this).hasClass('tafelen')) {
            $(this).css('background-position', '0 -124px').children('a');
        }
        else {
            $(this).css('background-position', '0 -31px').children('a');
        }
    }
    $('#nav-main .active').setActiveState();
    // END Nav main

    // Function to remove border of last item
    $.fn.removeLastBorder = function (list) {
        return this.children('li').last().addClass('border-none');
    }
    $('.item .aanraders ul').removeLastBorder();


    // Ingredienten
    $('.item .ingredienten li:odd').addClass('right-col');

    // Remove input value on focus
    $.fn.clearDefault = function () {
        return this.each(function () {
            var default_value = $(this).val();
            $(this).focus(function () {
                if ($(this).val() == default_value) $(this).val("");
            });
            $(this).blur(function () {
                if ($(this).val() == "") $(this).val(default_value);
            });
        });
    };
    $('.item .form input[type=text]').clearDefault();
    $('#nieuwsbrief input').clearDefault();

    // Password field switcher
    $('.password-clear').show();
    $('.password-password').hide();

    $('.password-clear').focus(function () {
        $('.password-clear').hide();
        $('.password-password').show();
        $('.password-password').focus();
    });
    $('.password-password').blur(function () {
        if ($('.password-password').val() == '') {
            $('.password-clear').show();
            $('.password-password').hide();
        }
    });

    // Custom Tabs functie (gebruikt bij Tafelen (uitleg thema maand))
    $.fn.tabs = function (content) {
        $(content).children().not('li:first').hide();
        this.children().first().find('a').addClass('active').end().end().click(
	  function () {
	      var pos = $(this).index();
	      $(this).parent().children().find('a').removeClass('active').css('zoom', '1').end().end().end().find('a').addClass('active');
	      $(content).children().hide().eq(pos).show();
	      return false;
	  }
	);
    };
    $('#nav-steps').tabs('#uitleg');

    $("#productCaroussel").jCarouselLite({
        btnNext: ".pijlR",
        btnPrev: ".pijlL",
        visible: 6
    });

    // Image carousel (gebruikt bij Tafelen (uitleg thema maand))
    $('.carousel .images li').not('li:first').hide();
    $('.carousel .pagination .previous').hide();
    var test = $('.carousel .images').children().index();
    var aantal_2 = $('.carousel .images').children().size();
    var aantal = aantal_2 - 1;
    var i = 0;

    $('.carousel .pagination .next').click(function () {
        i++;
        $('.carousel .images').children().hide();
        $('.carousel .images li').eq(i).show();
        if (i == aantal) {
            $(this).hide();
        }
        if (i != 0) {
            $('.previous').show();
        }
        return false;
    });
    $('.carousel .pagination .previous').click(function () {
        i--;
        $('.carousel .images').children().hide();
        $('.carousel .images li').eq(i).show();
        if (i == 0) {
            $(this).hide();
        }
        if (i != aantal) {
            $('.next').show();
        }
        return false;
    });

	// custom event tracking
    $("#home #nieuwsbrief input[type='image']").click(function () {
	var current_domain = document.domain.toString();
	if (current_domain == 'www.smaakvolplezier.be' || current_domain == 'smaakvolplezier.be') {
		_gaq.push(['_trackEvent', 'homepage_buttons', 'optin', 'enewsNL']);
	}else{
		_gaq.push(['_trackEvent', 'homepage_buttons', 'optin', 'enewsFR']);
	}
    });

    // Home
    $("#branding select").uniform();
    $("#tabs-nav").tabsHover("#tabs-panes");

    $("#branding select").change(function (e) {
    document.location.href=this[this.selectedIndex].value;
    });

    /* VERSION 2 */

});




