function getCookie( cookieName ) {
    var cookieJar = document.cookie.split( "; " );
    for( var x = 0; x < cookieJar.length; x++ ) {
        var oneCookie = cookieJar[x].split( "=" );
        if( oneCookie[0] == escape( cookieName ) ) { return oneCookie[1] ? unescape( oneCookie[1] ) : ''; }
    }
    return null;
}

function setCookie( cookieName, cookieValue, lifeTime, path, domain, isSecure ) {
    if( !cookieName ) { return false; }
    if( lifeTime == "delete" ) { lifeTime = -10; }

    document.cookie = escape( cookieName ) + "=" + escape( cookieValue ) +
        ( lifeTime ? ";expires=" + ( new Date( ( new Date() ).getTime() + ( 864000 * lifeTime ) ) ).toGMTString() : "" ) +
        ( path ? ";path=" + path : "") + ( domain ? ";domain=" + domain : "") +
        ( isSecure ? ";secure" : "");
    
    if( lifeTime < 0 ) { if( typeof( getCookie( cookieName ) ) == "string" ) { return false; } return true; }
    if( typeof( getCookie( cookieName ) ) == "string" ) { return true; } return false;
}



(function ($) {
  
  function initSearch() {
    // checkboxen mit anzeigen/verstecken funktionalität versehen
    $('.search_cb').each(function () {
      var name = $(this).attr('id').split('_')[1];
      (function (s) {
        $('#cb_' + s).change(function () {
          (this.checked)
            ? $('#' + s).slideDown('fast')
            : $('#' + s).hide();
        });        
      })(name);
    });

    // initial update
    $('.search_cb').each(function () {
      var cb = getCookie($(this).attr('id'));
      $(this).attr('checked', cb === null || cb == 'true' ? 'checked' : '');
      $(this).change();
    });
    
    // wenn eine checkbox geändert wird, daten für alle checkboxen abspeichern
    // egtl. gar ned nötig, aber wayne
    $('.search_cb').change(function () {
      $('.search_cb').each(function () {
        setCookie($(this).attr('id'), $(this).attr('checked'));
      });
    });
  }
  
  function initCommentModal() {
    $("a[rel^='prettyPhoto']").prettyPhoto({
      modal: true,
      callback: function () {
        window.location.reload();
      }
    });
    
  }
  
  $(document).ready(function () {
    initSearch();
    initCommentModal();
  });
}(jQuery));

