//Fancybox
    $(document).ready(function() {

      $("#nordsee_slider a[rel=picture_group]").fancybox({
        'transitionIn'    : 'none',
        'transitionOut'    : 'none',
        'overlayShow'  : true,
        'cyclic': true
      });

      $(".link_popup").fancybox({
        'titlePosition'    : 'inside',
        'transitionIn'    : 'elastic',
        'transitionOut'    : 'none',
        'overlayShow'  : false,
        'onComplete': function() {
          if ((typeof(Bricks) != 'undefined') && (typeof(Bricks.LodgingMap) != 'undefined')) {
            Bricks.LodgingMap.refresh();
          }
        }
      });

    });
//Script to make houses on Husoversigt to Tilbud -- Add class "tilbud_entry" to "house_entry" div
          $(document).ready(function() {         
        $('.house_entry').each(function(index) {
          if ($(this).hasClass('tilbud_entry')){
            $(this).children('.tilbud_entry_label').show();
          } else {
            $(this).children('.tilbud_entry_label').hide();
          }
        });
            });

//UL, LI Margin    
      $(document).ready(function() {
        $('#faciliteter ul li:nth-child(even)').addClass('dcedf7');
        $('.faciliteter ul li:nth-child(even)').addClass('dcedf7');
        $('#priser ul li:nth-child(even)').addClass('ede4da');
        $('#near_house .box:nth-child(odd)').addClass('dcedf7');
        $('#similar .box:nth-child(odd)').addClass('e6e6e6');
        $('.box ul li li:first-child').css({'padding-left':'0','background-image':'none'});
        $('#sub_houses .box:nth-child(odd)').addClass('dcedf7');
      });


// Nivo slider
jQuery(window).load(function(){
  jQuery("#nordsee_slider").nivoSlider({
    effect:"random",
    slices:15,
    boxCols:8,
    boxRows:4,
    animSpeed:500,
    pauseTime:50000,
    autostart: false,
    startSlide:0,
    directionNav:false,
    directionNavHide:true,
    controlNav:true,
    controlNavThumbs:true,
    controlNavThumbsFromRel:true,
    keyboardNav:true,
    pauseOnHover:true,
    manualAdvance:false,
    afterLoad: function () { $('.nivo-control:gt(5)').hide(); }
  });
});


// Checkboxes on Husoversigt.html
$(document).ready(function() {         
      $('#aside_criteria ul li').each(function(index) {
          if($(this).children("input:hidden").is(":checked")){
          $(this).removeClass("e6e6e6");
          $(this).addClass("a7c2d7");
        }
      });
      
      $('#aside_criteria ul li').click(function() {
        if($(this).children("input:hidden").is(":checked")){
          $(this).removeClass("e6e6e6");
          $(this).addClass("a7c2d7");
        }
        if(!$(this).children("input:hidden").is(":checked")){
          $(this).removeClass("a7c2d7");
          $(this).addClass("e6e6e6");
        }
      });
      });

//Check out steps
    $(window).load(function() {

        //Check for checked boxes on load
        $(".order_more_left").children(".input_counter").children("input[type='text']").each(function(index) {
        var value = $(this).val();
          if( value == "0 stk."){  
          $(this).prop('checked', false);  
          $(this).parent().children("input[type='text']").css("background-image", "url(images/order_input_small.png)");
        }
        else{
          $(this).parent().parent().children("input:hidden").prop('checked', true);

        }
        });
    
      
      //Set background colors according to, if checkboxes in the blue areas is clicked
      $('.order_more .order_more_left').click(function() {
        
        if($(this).children("input:hidden").is(":checked")){
        
          $(this).parent().parent().css("background-color", "#CCE2F0");
          $(this).children(".checkbox").css("background-color", "#CCE2F0");
          $(this).children(".link_popup").css("background-color", "#CCE2F0");
          $(this).children("label").css("background-color", "#CCE2F0");
          $(this).children(".input_counter").children(".updown").css("background-color", "#CCE2F0");
          $(this).parent().children(".order_line_price").css("background-color", "#CCE2F0");
          $(this).children(".input_counter").children("input[type='text']").val("1 stk.");
          $(this).children(".input_counter").children("input").css("background-image", "url(images/order_input.png)");
          
        }
  
        if(!$(this).children("input:hidden").is(":checked")){
        
          $(this).parent().parent().css("background-color", "#DCEDF7");
          $(this).children(".checkbox").css("background-color", "#DCEDF7");
          $(this).children(".link_popup").css("background-color", "#DCEDF7");
          $(this).children("label").css("background-color", "#DCEDF7");
          $(this).children(".input_counter").children(".updown").css("background-color", "#DCEDF7");
          $(this).parent().children(".order_line_price").css("background-color", "#DCEDF7");
          $(this).children(".input_counter").children("input[type='text']").val("0 stk.");
          $(this).children(".input_counter").children("input").css("background-image", "url(images/order_input_small.png)");
        }
      });
        
        
        //Set background colors according to, if checkboxes in the brown areas is clicked
      $('.order_extra .order_more .order_more_left').click(function() {
        
        if($(this).children("input:hidden").is(":checked")){
        
          $(this).parent().parent().css("background-color", "#E8D6C3");
          $(this).children(".checkbox").css("background-color", "#E8D6C3");
          $(this).children(".link_popup").css("background-color", "#E8D6C3");
          $(this).children("label").css("background-color", "#E8D6C3");
          $(this).children(".input_counter").children(".updown").css("background-color", "#E8D6C3");
          $(this).parent().children(".order_line_price").css("background-color", "#E8D6C3");
          $(this).children(".input_counter").children("input[type='text']").val("1 stk.");
          $(this).children(".input_counter").children("input").css("background-image", "url(images/order_input.png)");
          
        }
  
        if(!$(this).children("input:hidden").is(":checked")){
        
          $(this).parent().parent().css("background-color", "#ede4da");
          $(this).children(".checkbox").css("background-color", "#ede4da");
          $(this).children(".link_popup").css("background-color", "#ede4da");
          $(this).children("label").css("background-color", "#ede4da");
          $(this).children(".input_counter").children(".updown").css("background-color", "#ede4da");
          $(this).parent().children(".order_line_price").css("background-color", "#ede4da");
          $(this).children(".input_counter").children("input[type='text']").val("0 stk.");
          $(this).children(".input_counter").children("input").css("background-image", "url(images/order_input_small.png)");
        }
      });

        
      
      //When up-button is clicked
      $('.input_counter_up').click(function() {
        
        //Input object
        var input = $(this).parent().prev("input[type='text']");
        
        //Get original input value
        var originalValue = input.val();
        
        //Strip original value for whitespace and letters so we can plus/minus
        var newValue = originalValue.replace("stk.",""); 
        newValue = newValue.replace(" ",""); 
        
        //Check if checkbox is disabled
        if(parseInt(newValue) == 0){
          return false;
        }
        else{
        
        //+1
        newValue = parseInt(newValue)+1;
        
        //Adding '.stk' to the end
        newValue = newValue+" stk.";
        
        //Adding the new value
        input.val(newValue);
        return false;
        
        }
      });
      
      //When down-button is clicked
      $('.input_counter_down').click(function() {
        
        
        //Input object
        var input = $(this).parent().prev("input[type='text']");
        
        //Get original input value
        var originalValue = input.val();
        
        
        
        //Strip original value for whitespace and letters so we can plus/minus
        var newValue = originalValue.replace("stk.",""); 
        newValue = newValue.replace(" ",""); 
        
        
        //If-sentence to make sure we can't go below zero
        if(parseInt(newValue) > 1){
        
          //+1
          newValue = parseInt(newValue)-1;
          
          //Adding '.stk' to the end
          newValue = newValue+" stk.";
          
          //Adding the new value
          input.val(newValue);
          return false;
        }
        
        else{
        return false;
        }
        
      });
      
    });


//CUSTOM FORM ELEMENTS
//
//Created by Ryan Fait
//www.ryanfait.com
//
//The only things you may need to change in this file are the following
//variables: checkboxHeight, radioHeight and selectWidth (lines 24, 25, 26)
//
//The numbers you set for checkboxHeight and radioHeight should be one quarter
//of the total height of the image want to use for checkboxes and radio
//buttons. Both images should contain the four stages of both inputs stacked
//on top of each other in this order: unchecked, unchecked-clicked, checked,
//checked-clicked.
//
//You may need to adjust your images a bit if there is a slight vertical
//movement during the different stages of the button activation.
//
//The value of selectWidth should be the width of your select list image.
//
//Visit http://ryanfait.com/ for more information.


var checkboxHeight = "20";
var radioHeight = "25";
var selectWidth = "196";


// No need to change anything after this 


document.write('<style type="text/css">input.styled { display: none; } select.styled { position: relative; width: ' + selectWidth + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; } .disabled { opacity: 0.5; filter: alpha(opacity=50); }</style>');

var Custom = {
  init: function() {
    var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active;
    for(a = 0; a < inputs.length; a++) {
      if((inputs[a].type == "checkbox" || inputs[a].type == "radio") && inputs[a].className == "styled") {
        span[a] = document.createElement("span");
        span[a].className = inputs[a].type;

        if(inputs[a].checked == true) {
          if(inputs[a].type == "checkbox") {
            position = "0 -" + (checkboxHeight*1) + "px";
            span[a].style.backgroundPosition = position;
          } else {
            position = "0 -" + (radioHeight*1) + "px";
            span[a].style.backgroundPosition = position;
          }
        }
        inputs[a].parentNode.insertBefore(span[a], inputs[a]);
        inputs[a].onchange = Custom.clear;
        if(!inputs[a].getAttribute("disabled")) {
          span[a].onmousedown = Custom.pushed;
          span[a].onmouseup = Custom.check;
        } else {
          span[a].className = span[a].className += " disabled";
        }
      }
    }
    inputs = document.getElementsByTagName("select");
    for(a = 0; a < inputs.length; a++) {
      if(inputs[a].className == "styled") {
        option = inputs[a].getElementsByTagName("option");
        active = option[0].childNodes[0].nodeValue;
        textnode = document.createTextNode(active);
        for(b = 0; b < option.length; b++) {
          if(option[b].selected == true) {
            textnode = document.createTextNode(option[b].childNodes[0].nodeValue);
          }
        }
        span[a] = document.createElement("span");
        span[a].className = "select";
        span[a].id = "select" + inputs[a].name;
        span[a].appendChild(textnode);
        inputs[a].parentNode.insertBefore(span[a], inputs[a]);
        if(!inputs[a].getAttribute("disabled")) {
          inputs[a].onchange = Custom.choose;
        } else {
          inputs[a].previousSibling.className = inputs[a].previousSibling.className += " disabled";
        }
      }
    }
    document.onmouseup = Custom.clear;
    
    // Init inputs from previous visit
      $('input.styled').prev().each(Custom.clear)
  },
  pushed: function() {
    element = this.nextSibling;
    if(element.checked == true && element.type == "checkbox") {
      this.style.backgroundPosition = "0 -" + checkboxHeight*3 + "px";
    } else if(element.checked == true && element.type == "radio") {
      this.style.backgroundPosition = "0 -" + radioHeight*3 + "px";
    } else if(element.checked != true && element.type == "checkbox") {
      this.style.backgroundPosition = "0 -" + checkboxHeight + "px";
    } else {
      this.style.backgroundPosition = "0 -" + radioHeight + "px";
    }
  },
  check: function() {
    element = this.nextSibling;
    if(element.checked == true && element.type == "checkbox") {
      this.style.backgroundPosition = "0 0";
      element.checked = false;
      $(element).change();
    } else {
      if(element.type == "checkbox") {
        this.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
      } else {
        this.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
        group = this.nextSibling.name;
        inputs = document.getElementsByTagName("input");
        for(a = 0; a < inputs.length; a++) {
          if(inputs[a].name == group && inputs[a] != this.nextSibling) {
            inputs[a].previousSibling.style.backgroundPosition = "0 0";
          }
        }
      }
      element.checked = true;
      $(element).change();
    }
  },
  clear: function() {
    inputs = document.getElementsByTagName("input");
    for(var b = 0; b < inputs.length; b++) {
      if(inputs[b].type == "checkbox" && inputs[b].checked == true && inputs[b].className == "styled") {
        inputs[b].previousSibling.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
      } else if(inputs[b].type == "checkbox" && inputs[b].className == "styled") {
        inputs[b].previousSibling.style.backgroundPosition = "0 0";
      } else if(inputs[b].type == "radio" && inputs[b].checked == true && inputs[b].className == "styled") {
        inputs[b].previousSibling.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
      } else if(inputs[b].type == "radio" && inputs[b].className == "styled") {
        inputs[b].previousSibling.style.backgroundPosition = "0 0";
      }
    }
  },
  choose: function() {
    option = this.getElementsByTagName("option");
    for(d = 0; d < option.length; d++) {
      if(option[d].selected == true) {
        if (document.getElementById("select" + this.name)) {
          document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
        }
      }
    }
  }
}
window.onload = Custom.init;

