//=============================================================================
// www.erlenwiese.de         (c) Martin Schmidt, Alsfeld
//-----------------------------------------------------------------------------
//
// $Id: cookie.js 210 2010-06-02 18:13:53Z Martin Schmidt $
//=============================================================================

//-----------------------------------------------------------------------------
function Cookie()
//-----------------------------------------------------------------------------
{
  this.read = function () {
      if ($.cookie(this.Name) !== null)
      {
        var cookie = $.getJSONCookie(this.Name);
        for (var value in cookie)
        {
          if (typeof this.Data[value] != "undefined") {
            this.Data[value] = cookie[value];
          }
        }
      }
    };
  this.write = function () {
      if (this.Data) $.setJSONCookie(this.Name, this.Data, "");
    };
  this.del = function () {
      $.removeJSONCookie(this.Name);
    };
}

//-----------------------------------------------------------------------------
function CCookieOptionen ()
//-----------------------------------------------------------------------------
{
  this.Name = "Optionen";
  this.Data = { Ueberblenden: true,              // Weiches Überblenden bei Diashow ja/nein
                Dauer: 7,                        // Standzeit eines Fotos in der Diashow
                AnzahlFotos: 30,                 // Anzahl Fotos in den Spezial Galerien
                KommentareAnzeigen: true,        // Kommentare zu den Fotos, falls vorhanden, anzeigen
                BesucheZaehlen: true,            // Es wird gezählt, wie oft ein Foto angesehen wurde
                LetzterBesuch: ["", ""],         // Zeitstempel des letzten Beuschs (wird benötigt, um auf neue Fotos aufmerksam zu machen)
                PanoramaAnimation: false,        // Die Panorama Animation wird automatisch gestartet
                PanoramaGeschwindigkeit: 10,     // Animationsgeschwindigkeit
                NaviDlg: {                       // Position des Navigationsdialogs
                  left: 0,
                  top: 0
                },
                SortDlg: {                       // Position des Navigationsdialogs
                  left: 0,
                  top: 0
                }
              };

  this.read();
}

CCookieOptionen.prototype = new Cookie();

//-----------------------------------------------------------------------------
function CCookieBesucher ()
//-----------------------------------------------------------------------------
{
  this.Name = "Besucher";
  this.Data = { Name: "",
                Wohnort: "",
                EMail: "",
                Web: "",
                Position: {
                  Breite: "",
                  Laenge: "",
                  Zielort: ""
                },
                Nachricht: ""
              };

  this.read();
}

CCookieBesucher.prototype = new Cookie();

//-----------------------------------------------------------------------------
function CCookieSuchen ()
//-----------------------------------------------------------------------------
{
  this.Name = "Suchen";
  this.Data = { Begriffe: "",                    // Suchbegriff
                Methode: "",                     // Suchmethode: mindestens einen / alle
                Robot: "",                       // Suchmaschine: erlenwiese / Google
                KameraID: 0,
                ObjektivID: 0,
                Brennweite: 0,
                Blende: 0,
                Belichtungszeit: "",
                ISO: 0
              };

  this.read();
}

CCookieSuchen.prototype = new Cookie();

//-----------------------------------------------------------------------------
function CCookieSuchIDs ()
//-----------------------------------------------------------------------------
{
  this.Name = "SuchIDs";
  this.Data = { IDs: [] };

  this.read();
}

CCookieSuchIDs.prototype = new Cookie();

//-----------------------------------------------------------------------------
function CCookieFavoriten ()
//-----------------------------------------------------------------------------
{
  this.Name = "Favoriten";
  this.Data = { FotoIDs: [] };

  this.add = function (id) {
      if (this.Data)
      {
        var i;
        this.read();
        for (i = 0; i < this.Data.FotoIDs.length; i++) {
          if (this.Data.FotoIDs[i] == id) return;
        }
        this.Data.FotoIDs.push(id);
        this.write();
      }
    };
  this.remove = function (id) {
      if (this.Data)
      {
        var i;
        this.read();
        for (i = 0; i < this.Data.FotoIDs.length; i++) {
          if (this.Data.FotoIDs[i] == id) {
            this.Data.FotoIDs.splice(i, 1);
            if (this.Data.FotoIDs.length === 0) {
              $.removeJSONCookie(this.Name);
            } else {
              this.write();
            }
            return;
          }
        }
      }
    };
  this.toggle = function (id) {
      if (this.Data)
      {
        var i;
        this.read();
        for (i = 0; i < this.Data.FotoIDs.length; i++) {
          if (this.Data.FotoIDs[i] == id) {
            this.Data.FotoIDs.splice(i, 1);
            if (this.Data.FotoIDs.length === 0) {
              $.removeJSONCookie(this.Name);
            } else {
              this.write();
            }
            return;
          }
        }
        this.Data.FotoIDs.push(id);
        this.write();
      }
    };
  this.isset = function (id) {
      if (this.Data)
      {
        var i;
        this.read();
        for (i = 0; i < this.Data.FotoIDs.length; i++) {
          if (this.Data.FotoIDs[i] == id) return true;
        }
        return false;
      }
    };

  this.read();
}

CCookieFavoriten.prototype = new Cookie();

//-----------------------------------------------------------------------------
/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options = $.extend({}, options); // clone object since it's unexpected behavior if the expired property were changed
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // NOTE Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

//-----------------------------------------------------------------------------
/*
    http://www.JSON.org/json2.js
    2009-08-17
*/
"use strict";if(!this.JSON){this.JSON={}}(function(){function f(n){return n<10?"0"+n:n}if(typeof Date.prototype.toJSON!=="function"){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf()}}var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==="string"?c:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+string+'"'}function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==="object"&&typeof value.toJSON==="function"){value=value.toJSON(key)}if(typeof rep==="function"){value=rep.call(holder,key,value)}switch(typeof value){case"string":return quote(value);case"number":return isFinite(value)?String(value):"null";case"boolean":case"null":return String(value);case"object":if(!value){return"null"}gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==="[object Array]"){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||"null"}v=partial.length===0?"[]":gap?"[\n"+gap+partial.join(",\n"+gap)+"\n"+mind+"]":"["+partial.join(",")+"]";gap=mind;return v}if(rep&&typeof rep==="object"){length=rep.length;for(i=0;i<length;i+=1){k=rep[i];if(typeof k==="string"){v=str(k,value);if(v){partial.push(quote(k)+(gap?": ":":")+v)}}}}else{for(k in value){if(Object.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?": ":":")+v)}}}}v=partial.length===0?"{}":gap?"{\n"+gap+partial.join(",\n"+gap)+"\n"+mind+"}":"{"+partial.join(",")+"}";gap=mind;return v}}if(typeof JSON.stringify!=="function"){JSON.stringify=function(value,replacer,space){var i;gap="";indent="";if(typeof space==="number"){for(i=0;i<space;i+=1){indent+=" "}}else{if(typeof space==="string"){indent=space}}rep=replacer;if(replacer&&typeof replacer!=="function"&&(typeof replacer!=="object"||typeof replacer.length!=="number")){throw new Error("JSON.stringify")}return str("",{"":value})}}if(typeof JSON.parse!=="function"){JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==="object"){for(k in value){if(Object.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v}else{delete value[k]}}}}return reviver.call(holder,key,value)}cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})}if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,""))){j=eval("("+text+")");return typeof reviver==="function"?walk({"":j},""):j}throw new SyntaxError("JSON.parse")}}}());

//-----------------------------------------------------------------------------
/**
 * JSON Cookie - jquery.jsoncookie.js
 *
 * Sets and retreives native JavaScript objects as cookies.
 * Depends on the object serialization framework provided by JSON2.
 *
 * Dependencies: jQuery, jQuery Cookie, JSON2
 *
 * @project JSON Cookie
 * @author Randall Morey
 * @version 0.9
 */
(function ($) {
  var isObject = function (x) {
    return (typeof x === 'object') && !(x instanceof Array) && (x !== null);
  };

  $.extend({
    getJSONCookie: function (cookieName) {
      var cookieData = $.cookie(cookieName);
      var x = {};
      if (cookieData) {
        try {
          x = JSON.parse(cookieData);
        }
        catch (e) {
          x = {};
        }
      }
      return x;
    },
    setJSONCookie: function (cookieName, data, options) {
      var cookieData = '';

      options = $.extend({
        expires: 1461,
        path: '/'
      }, options);

      if (!isObject(data)) {  // data must be a true object to be serialized
        throw new Error('JSONCookie data must be an object');
      }

      cookieData = JSON.stringify(data);

      return $.cookie(cookieName, cookieData, options);
    },
    removeJSONCookie: function (cookieName) {
      return $.cookie(cookieName, null, { path: '/' });
    },
    JSONCookie: function (cookieName, data, options) {
      if (data) {
        $.setJSONCookie(cookieName, data, options);
      }
      return $.getJSONCookie(cookieName);
    }
  });
})(jQuery);



