$(function() {
  
  /* search default text replace 
  function switchText(){
  if ($(this).val() == $(this).attr('title'))
  $(this).val('');
  else if ($.trim($(this).val()) == '')
  $(this).val($(this).attr('title'));
}
  
  $("input[type=text][title!='']").each(function() {
  if ($.trim($(this).val()) == '') $(this).val($(this).attr('title'));
});
  $('input[type=text]').each(function() {
  if ($.trim($(this).val()) == '') $(this).val($(this).attr('title'));
}).focus(switchText).blur(switchText);
  */
  
  /* Buttons Menu */
  var nthChildTest = Modernizr.testStyles("#modernizr div {width:100px} #modernizr :last-child{width:200px;display:block}", function(elem) {
        return elem.lastChild.offsetWidth > elem.firstChild.offsetWidth;
    }, 1);
  
  if (!nthChildTest) {
    $("#menu li:nth-child(1)").css({ "background": "#fff url(/_layout/images/icons/button-home.png)         no-repeat 50% 5px"   });
    $("#menu li:nth-child(2)").css({ "background": "#fff url(/_layout/images/icons/button-schiesssport.png) no-repeat 50% 10px"  });
    $("#menu li:nth-child(3)").css({ "background": "#fff url(/_layout/images/icons/button-tradition.png)    no-repeat 50% 2px"   });
    $("#menu li:nth-child(4)").css({ "background": "#fff url(/_layout/images/icons/button-jugend.png)       no-repeat 50% 3px"   });
    $("#menu li:nth-child(5)").css({ "background": "#fff url(/_layout/images/icons/button-verein.png)       no-repeat 50% 7px"   });
    $("#menu li:nth-child(6)").css({ "background": "#fff url(/_layout/images/icons/button-media.png)        no-repeat 50% 15px"  });
  }
  
  /* lightbox */
  function formatTitle(title, currentArray, currentIndex, currentOpts) {
    return '<div id="fancybox-title-clone"><span><a href="javascript:;" onclick="$.fancybox.close();"><img src="http://culrich.dyndns.org/_layout/images/slimbox/closelabel.gif" /></a></span>' + (title && title.length ? '<b>' + title + '</b>' : '' ) + 'Image ' + (currentIndex + 1) + ' of ' + currentArray.length + '</div>';
  }
  
  $.fn.makeFancy = function(transitionType) {
    return $(this).fancybox({
      'transitionIn'  : transitionType,
      'transitionOut' : transitionType,
      'speedIn'       : 600,
      'speedOut'      : 200,
      'centerOnScroll': 'true',
      'showCloseButton'  : false,
      'titlePosition'     : 'inside',
      'titleFormat'    : formatTitle
    });
  }
    
    $('a[rel=lightbox]').makeFancy('elastic');
  $('.thumbs a').makeFancy('elastic');
  $('.carousel a').makeFancy('elastic');
  
  /*jCarouselLite */
  $(".carousel").jCarouselLite({
    btnNext: ".carousel .next",
    btnPrev: ".carousel .prev",
    visible: 4,
    circular: false,
    scroll: 1,
    speed: 600
  });
  
  /* comment bubble */
  if ($.cookie("showBubble") != "false") {
    $(".bubble").delay(800).fadeIn('slow');
    $(".bubble > .close").click(function() {
      $(this).parent().hide();
      $.cookie("showBubble","false",{ expires: 1, path: '/' });
    });
  }
  
  /* Alte Browser Warnung */
  if ( !Modernizr.boxshadow || !Modernizr.rgba || !Modernizr.borderradius ) {
    $("body").prepend("<div class='warning'>Sie verwenden einen veralteten Browser, wodurch es zu Darstellungsfehlern kommen kann.<br />Bitte aktualisieren Sie Ihren Browser.</div>");
  }
  
  /* Checkbox Replacement */
  $('input[type=checkbox]').each(function() {
     $(this).wrap(function() {
        return ($(this).is(':checked')) ? '<span class="custom_checkbox selected" />' : '<span class="custom_checkbox" />';
     });
  });
  $('.custom_checkbox input[type=checkbox]').click(function () {
    $(this).parent().toggleClass('selected');
  });  
  
});

