(function(b){function d(a){var b=a.attr("placeholder");e(a,b);a.focus(function(){a.data("changed")!==!0&&a.val()===b&&a.val("")}).blur(function(){a.val()===""&&a.val(b)}).change(function(){a.data("changed",a.val()!=="")})}function e(a,b){a.val()===""?a.val(b):a.data("changed",!0)}function f(a){var c=b("<input>").attr({placeholder:a.attr("placeholder"),value:a.attr("placeholder"),id:a.attr("id"),readonly:!0}).addClass(a.attr("class"));a.after(c);a.val()===""?a.hide():c.hide();b(a).blur(function(){a.val()===
""&&(a.hide(),c.show())});b(c).focus(function(){a.show().focus();c.hide()})}function g(a){a.find(":input[placeholder]").each(function(){b(this).data("changed")!==!0&&b(this).val()===b(this).attr("placeholder")&&b(this).val("")})}"placeholder"in document.createElement("input")||b(document).ready(function(){b(":input[placeholder]").not(":password").each(function(){d(b(this))});b(":password[placeholder]").each(function(){f(b(this))});b("form").submit(function(){g(b(this))})})})(jQuery);;
(function ($) {
  
  /*
    Functions
  */
  function doHomePageHover() {
    $('.node-homebox > a').hover(function() {
      $(this).find('.content').stop().animate({bottom: '0'}, 500);
    }, function() {
      $(this).find('.content').stop().animate({bottom: '-43px'}, 500);
    });  
  }
  
  function makeColSameHeight() {
    var highestHeight = 0;
    var $cols = $('#has-1-child-right div.minidoormat-seperator');

    $cols.each(function(index, val) {
      if(highestHeight < $(val).height()) {
        highestHeight = $(val).height();
      }
    });
    // Apply the heighest to them all
    $cols.height(highestHeight);
  }
  
  function makeFieldsetsFocused() {
    $fieldsetInputs = $('fieldset input:input, fieldset select');
    $fieldsetInputs.focus(function(event) {
      $('.fieldset-wrapper').removeClass('focus');
      $(this)
        .parents('.fieldset-wrapper:first')
        .toggleClass('focus');
    }).blur(function(event) {
      $(this)
        .parents('.fieldset-wrapper:first')
        .toggleClass('focus');
      }
    );
    
    // Webkit does not recognise focus and blur events for radio buttons
    // Use the change event instead
    $fieldsetRadioCheck = $('fieldset [type="radio"], fieldset [type="checkbox"]');
    $fieldsetRadioCheck.change(function(event) {
      $('.fieldset-wrapper').removeClass('focus');
      $(this)
        .parents('.fieldset-wrapper:first')
        .addClass('focus');
    });
    
    // Maybe automatically set to focus the first element ?
    //$('.fieldset-inner').eq(0).addClass('focus');
    
    $('fieldset:has(fieldset)').addClass('has-child-fieldsets');
  }
  
  function setErrorForLabel() {
    $('input.error, select.error').prev('label').addClass('label-error');
  }
  
  function makeSlideshow() {
    
    var $slideShow = $('.view-slideshow');
    
    $.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) {
      $(pager).find('li a')
        .removeClass('current')
        .filter( 'a:eq(' + currSlideIndex + ')' )
        .addClass('current');
    };

    $slideShow.before('<div class="nav-slideshow-wrapper"><ul class="nav-slideshow"></div>');
    $('.nav-slideshow').append('<a href="#" id="prev">Prev</a>').append('<a href="#" id="next">Next</a>');
    $slideShow.cycle({
      fx:       'fade', //fade, scrollLeft, uncover
      pager:    '.nav-slideshow',
      next:     '#next', 
      prev:     '#prev',
      timeout:  6000,
      pagerAnchorBuilder: function(idx, slide)  { 
        //console.log(idx);
        myClass = (idx==0)? 'current' : '';
        return '<li><a class="' + myClass + '" href="#">' + idx + '</a></li>'; 
      }
      
    });
    $('.nav-slideshow #next').appendTo('.nav-slideshow');
  }
  
  // Plugin to make doormat element the same hight
  // use on the parent and pass the child as a selector
  jQuery.fn.extend({
    
    makeDoormatsSameHeight: function(doormatSelector){
      var highestHeight = 0;
      $doormats = this.find(doormatSelector);
      $doormats.each(function(index, val) {
        if(highestHeight < $(val).height()) {
          highestHeight = $(val).height();
        }
      });
      // Apply the heighest to them all
      $doormats.height(highestHeight);
      
      return this;
    }
    
  });
  
  /*
    Do javascript only if element is on the page
  */
  Drupal.behaviors.cancerzen = {
    
    attach: function (context) {

      $('body').removeClass('no-js'); 
      $('body').addClass('js');
      
      // do animation on hover of homepage boxes
      // only going to do this on homepage
      if ($('body').hasClass('front')) {
        doHomePageHover();  
      };
      
      // Make all the doormats the same height as the
      // highest doormat
      if ($('div.doormats').length) {
        $('div.doormats')
          .makeDoormatsSameHeight('.field-name-field-doormat-text');
      };
      // This is for the special case panel region "third col is single item"
      if ($('#has-1-child-right').length) {
        // Take the first two cols and set their children to the same height
        $('#has-1-child-right div.minidoormat-left, #has-1-child-right div.minidoormat-middle')
          .makeDoormatsSameHeight('.panel-pane:first-child .pane-content');
        // Make each col the same height  
        makeColSameHeight();
      };
      if ($('.field-name-field-t05-doormats')) {
        $('.field-name-field-t05-doormats')
          .makeDoormatsSameHeight('.field-name-field-mini-doormat-text');
      };
      
      // Create the yellow focus background
      if ($('fieldset input').length) {
        makeFieldsetsFocused();
      }
      
      // Make a slideshow
      if ($('.view-slideshow').length) {
        makeSlideshow();
      };
      
      //Some error stuff that we can only really do in js
      setErrorForLabel();
      
      $helpbox = $('ul.helpline-box');
      $helpbox.find('li:first-child').addClass('first');
      $helpbox.find('li:last-child').addClass('last');
    }
  };

})(jQuery);

;

