function createCookie(name, value, days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
    var expires = "; expires=" + date.toGMTString();
  }
  else var expires = "";
  document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for (var i = 0; i < ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0) == ' ') c = c.substring(1, c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
  }
  return null;
}


function initBannerfooter() {
  var c = readCookie('bannerfooter');
  if (c == 'closed') {
    $('.banner-push').remove();
    $('.banner-footer .close').remove();
    $('.banner-footer').css('position', 'relative');
  }
}

$(document).ready(function () {
    //initBannerfooter();
    $('.banner-footer .close').click(function () {
        var n = 'bannerfooter';
        var v = 'closed';
        var d = 3;
        createCookie(n, v, d);
        initBannerfooter();
    });
    if (!('placeholder' in document.createElement('input'))) {
        $('input[placeholder]').labelify({ text: 'placeholder', labelledClass: 'placeholderText' });
    }
    $('.ws-product a').hide();
    $('.webshop-order .ws-product input[type=text]').focus(function () {
        $(this).addClass('focused');
        $('.webshop-order .ws-product input[type=text]:not(.focused)').attr('disabled', 'disabled');
        $('.webshop input.order').attr('disabled', 'disabled');
        $('.webshop input.update').show();
    });

    $('.webshop-order .ws-product-delivery select').change(function () {
        var productid = $(this).attr('id').substring(1);
        var newvalue = $(this).val();
        location.href = '?updatedelivery=' + productid + '&type=' + newvalue;
    });

    $('.webshop-order .ws-product input[type=text]').blur(function () {
        $(this).removeClass('focused');
        $('.webshop-order .ws-product input[type=text]').removeAttr('disabled');
        $('.webshop input.order').removeAttr('disabled');
        $('.webshop input.update').hide();
        $(this).parent('.ws-product').find('a').trigger('click');
    });

    $('li.active a').live('click', function (e) {
        e.preventDefault();
    });



    if ($.browser.msie && $.browser.version.substr(0, 1) < 7) {
        $('li,.inlogbox').hover(function () {
            $(this).addClass('sfHover');
        }, function () {
            $(this).removeClass('sfHover');
        });
    }

    $(".ctrContentR a[href$='.PDF'],.ctrContentR a[href$='.pdf']").each(function () {
        $(this).addClass('pdficon');
        $(this).attr('target', '_blank');
    });
    $(".ctrContentR a[href~='sitemanager.asp']").each(function () {
        return false;
    });
    $('.contourNavigation input:submit').each(function () { $(this).attr('value', 'verzenden'); });

    $('.btn input:submit').click(function () {
        $(this).parents('.formfield').find('.row input').each(function () {
            var errorMessages = $(this).parent('span.text').nextAll('.errorMsg:visible');
            var errorCount = errorMessages.length;
            if (errorCount > 0) {
                $(this).addClass('reqInputfield');
                errorMessages.each(function () {
                    $(this).css('position', 'absolute').css('top', '-99999em');
                });
            }
            else {
                $(this).removeClass('reqInputfield');
                errorMessages.each(function () {
                    $(this).css('position', 'relative').css('top', '0');
                });
            }
        });
    });


    // SUPERFISH
    $('ul.sf-menu, ul.sf-ecMenu').superfish({
        delay: 250,
        animation: { opacity: 'show', height: 'show' },
        pathClass: 'current',
        pathLevels: 0,
        speed: 'fast',
        autoArrows: false,
        dropShadows: false
    });
    // SUPERFISH END

    // CURVY CORNERS
    $('.box-corner5, .box-corner5b, .box-heading.b14, .box-heading_red.b14, .boxSmall-heading, .boxSmall-banner, .btn, #slideshow .slides-nav, .submenu, .box.search, .tabnavigation a, .tabnavigation span').corner({
        tl: { radius: 5 },
        tr: { radius: 5 },
        bl: { radius: 5 },
        br: { radius: 5 },
        antiAlias: true,
        autoPad: true,
        validTags: ["div"]
    });

    $('.box-heading.L24').corner({
        tl: { radius: 5 },
        tr: false,
        bl: { radius: 5 },
        br: false,
        antiAlias: true,
        autoPad: true,
        validTags: ["div"]
    });

    $('.box-heading.R24, .ctrIconbar').corner({
        tl: false,
        tr: { radius: 5 },
        bl: false,
        br: { radius: 5 },
        antiAlias: true,
        autoPad: true,
        validTags: ["div"]
    });

    $('.ctrFooter').corner({
        tl: { radius: 5 },
        tr: { radius: 5 },
        bl: false,
        br: false,
        antiAlias: true,
        autoPad: true,
        validTags: ["div"]
    });
    // CURVY CORNERS END

    // FONT SIZER
    fontResizer('1em', '1.125em', '1.25em');
    // FONT SIZER END

    // EQUAL HEIGHT
    //$(function(){
    //    $('.eq2').equalHeight();
    //});
    // EQUAL HEIGHT END
});


/**
* jQuery.labelify - Display in-textbox hints
* Stuart Langridge, http://www.kryogenix.org/
* Released into the public domain
* Date: 25th June 2008
* @author Stuart Langridge
* @version 1.3
*/
jQuery.fn.labelify = function (settings) {
  settings = jQuery.extend({
    text: "placeholder",
    labelledClass: "placeholderText"
  }, settings);
  var lookups = {
    placeholder: function (input) {
      return $(input).attr("placeholder");
    }
  };
  var lookup;
  var jQuery_labellified_elements = $(this);
  return $(this).each(function () {
    if (typeof settings.text === "string") {
      lookup = lookups[settings.text];
    };
    var lookupval = lookup(this);
    if (!lookupval) { return; }
    $(this).data("label", lookup(this).replace(/\n/g, ''));
    $(this).focus(function () {
      if (this.value === $(this).data("label")) {
        $(this).removeClass(settings.labelledClass);
        this.value = '';
      }
    }).blur(function () {
      if (this.value === $(this).attr('placeholder')) {
        this.value = $(this).data("label");
        $(this).addClass(settings.labelledClass);
      }
    });
    var removeValuesOnExit = function () {
      jQuery_labellified_elements.each(function () {
        if (this.value === $(this).data("label")) {
          this.value = '';
          $(this).removeClass(settings.labelledClass);
        }
      })
    };
    //    $("form").submit(function () {
    //    removeValuesOnExit();
    //    }, function () {
    //    if (!('placeholder' in document.createElement('input'))) {
    //    $('input[placeholder]').labelify({ text: 'placeholder', labelledClass: 'placeholderText' });
    //    }
    //    });
    $("#mijnbalans fieldset .btn,#mijnbalans .wizard .prev,#mijnbalans .wizard .next,.account .btn-send").mousedown(function () {
      removeValuesOnExit();
    });
    $(window).unload(removeValuesOnExit);
    if (this.value !== this.defaultValue) {
      return;
    }
    if (this.value == '') {
      this.value = $(this).data("label");
      $(this).addClass(settings.labelledClass);
    }
  });
};
