/* =======================[- Initialization -]============================ */
// a more accessible "hover" function
jQuery.fn.extend({
  hover: function(fnOver, fnOut) {
    return this.bind('mouseenter mouseover focus',fnOver).bind('mouseleave mouseout blur', fnOut);
  }
});
 
$(document).ready(function(){
  // enables lightbox
  initLightbox();
  // make checkboxes look nice
  initCheckboxes();
  // make radiobuttons look nice
  initRadiobuttons();
  }); 
 
/* =======================[- Functions -]============================ */
/*
 initLightbox
 --------------
 enables lightbox for all anchors with rel="lightbox" 
*/
function initLightbox() {
  // apply lightbox to anchor with rel="lightbox"
  $(function() {
    $('a[rel^=lightbox]').lightBox();
    $('a[rel^=exposeThumbnails]').lightBox({sourceAttribute:'rel',selectorMatches:'.exposeThumbnails > a'});
  });
}
 
/* 
 initCheckboxes
 --------------
 makes all checkboxes clickable and sets the initial state 
*/ 
function initCheckboxes() {
  $("input[@type='checkbox']").each(function() {
    // add event handler
    $(this).click(function () { 
      toggleCheckBox(this); 
    });
    // init checkboxes
    toggleCheckBox(this);        
  });
}
/* 
 initRadiobuttons
 --------------
 makes all radiobuttons clickable and sets the initial state 
*/ 
function initRadiobuttons() {
  $("input[@type='radio']").each(function() {
    // add event handler
    $(this).click(function () { 
      toggleRadioButton(this); 
    });
    // init checkboxes
    toggleRadioButton(this);        
  });
}
            
/* 
 toggleCheckBox(elem)
 --------------------
 toggles the enhanced (nice looking) checkboxes by changing the css properties
 and classes 
*/ 
function toggleCheckBox(elem) {
  $(elem).parent().removeAttr("style");
  var cssObj = 
  {
    filter: "alpha(opacity=0)",
    opacity: "0.0",
    zIndex: "100"
  }
  $(elem).css(cssObj);
  var chk = elem;
  if (chk.checked) {
    $(elem).parent().removeClass("CheckBoxleer"); 
    $(elem).parent().addClass("CheckBox");
  } else {
    $(elem).parent().removeClass("CheckBox");
    $(elem).parent().addClass("CheckBoxleer");
  }
}
 
/* 
 toggleRadiobutton(elem)
 --------------------
 toggles the enhanced (nice looking) radiobuttons by changing the css properties
 and classes 
*/ 
function toggleRadioButton(elem) {
  $(elem).parent().removeAttr("style");
  var cssObj = 
  {
    filter: "alpha(opacity=0)",
    opacity: "0.0",
    zIndex: "100"
  }
  $(elem).css(cssObj);
  var chk = elem;
  if (chk.checked) {
    $(elem).parent().removeClass("Radioleer"); 
    $(elem).parent().addClass("Radio");
    
  } else {
    $(elem).parent().removeClass("Radio");
    $(elem).parent().addClass("Radioleer");
  }
  
  // uncheck all in same group (with same name)
  var name = $(elem).attr("name");
  $("input[@type='radio'][@name='"+name+"']").each(function() {
      var chk2 = this;
      if (chk2.checked) {
          $(this).parent().removeClass("Radioleer"); 
          $(this).parent().addClass("Radio");
      } else {
          $(this).parent().removeClass("Radio");
          $(this).parent().addClass("Radioleer");
      }
  });
}