_$MEDIA_URLS = {"img/fancybox/fancy_shadow_n.png": ["/static/img/fancybox/fancy_shadow_n-89c8901f510a852dd47804148aae7835fe6d1c90.png"], "img/bt_galerie.png": ["/static/img/bt_galerie-9f463034e7c86f196fe403933d2b113075c7776f.png"], "img/logo_salitos.png": ["/static/img/logo_salitos-5d6472afbd2f6cd11d76c608b65b878faa984c76.png"], "img/logo.png": ["/static/img/logo-7ab86333e70c0ffa5dc632c9015f46faeae75659.png"], "img/sound_mute.png": ["/static/img/sound_mute-6f9c88714e694a1c65fda83ac09813703b529244.png"], "img/bt_ticketshop.png": ["/static/img/bt_ticketshop-ff914e213425b1aeba92bc2a4d73d1eeba5e1439.png"], "sound.wav": ["/static/sound-dc0299084a3270af5ec986ca91652ba8a3c3dcae.wav"], "img/bt_newsletter.png": ["/static/img/bt_newsletter-9c23da4a6b2ce1aa5a155840240fdce633ef4b0a.png"], "img/fancybox/fancy_title_main.png": ["/static/img/fancybox/fancy_title_main-61975d1e8e794bcd370b0454133a06f87dd71727.png"], "img/logo_skyy-vodka.png": ["/static/img/logo_skyy-vodka-b606e4de0907c7664c5dd99949e3b07b96d1eeab.png"], "img/logo_smirnoff.png": ["/static/img/logo_smirnoff-4bedfe4ffb0520945cb6eb95c1e2bb943735415c.png"], "img/bt_team.png": ["/static/img/bt_team-4e84c87b7a60b2eaa3141d6eb09c70f4226f2ec7.png"], "img/bt_video_down.png": ["/static/img/bt_video_down-2fa53cba37aab56dfb2b9022c2f42e3fb6d6500b.png"], "img/fancybox/fancy_shadow_nw.png": ["/static/img/fancybox/fancy_shadow_nw-35949ece9e829543695659097bf05df88f40d77a.png"], "img/logo_carlsberg.png": ["/static/img/logo_carlsberg-851adac4a3a79fdeb262929268aae8a139dd71cb.png"], "img/patch_the-dome.png": ["/static/img/patch_the-dome-b98c3ae1215d9de89a039dc95cdfaf270b7820ee.png"], "sound.mp3": ["/static/sound-c8bebe0f01f84480a2ee183261dbe8fc5a486f74.mp3"], "img/spinner.gif": ["/static/img/spinner-af698a35d7644b62a97e5cb4ef634311307746bd.gif"], "img/fancybox/fancy_nav_right.png": ["/static/img/fancybox/fancy_nav_right-8d5ff123a5963b37002f17258cb329443db633c8.png"], "img/fancybox/fancy_shadow_se.png": ["/static/img/fancybox/fancy_shadow_se-4aea65523227284f85e3855464e3971248bc7fec.png"], "img/background.png": ["/static/img/background-aa3ee1e9de84fb502e24da52fe6acff0de2153c8.png"], "img/bt_welcome_down.png": ["/static/img/bt_welcome_down-ac7d92509d569452e180f2854f356840807a5137.png"], "img/fancybox/fancy_shadow_sw.png": ["/static/img/fancybox/fancy_shadow_sw-1378bf3a8aabc28d3741ba15833edc4df3bb9cb5.png"], "img/icon_info.png": ["/static/img/icon_info-0534fa3ef7e35ef1e58ba0e2f37c71d3d4dfd799.png"], "img/bt_impressum.png": ["/static/img/bt_impressum-af1db581655708ec32ed9ae1c91a5d5d2459e2df.png"], "img/naked_avatar.jpg": ["/static/img/naked_avatar-5de65818fd31d98763106de5d66120207cb7ac7c.jpg"], "img/favicon.ico": ["/static/img/favicon-fc72905a63bb20bc300dd5b5945e350935d7424f.ico"], "img/icon_bt_down.png": ["/static/img/icon_bt_down-4b79328f31dc6f5281972e50d1afa7c4c07a984a.png"], "img/fancybox/fancy_title_right.png": ["/static/img/fancybox/fancy_title_right-1c629202bbfb7f8f0c5897a7932710519aedb9b0.png"], "img/fancybox/fancy_shadow_ne.png": ["/static/img/fancybox/fancy_shadow_ne-db53c1c60a086880621937f9ac37f020b67dde5d.png"], "img/fancybox/fancy_shadow_e.png": ["/static/img/fancybox/fancy_shadow_e-b90f98c299d40e2c047adbc7ff59ba9b08c92c8a.png"], "img/fancybox/fancy_progress.png": ["/static/img/fancybox/fancy_progress-0bea335b39e8ec091850a0c6ec6671525ef6cd2c.png"], "img/fancybox/fancy_right.png": ["/static/img/fancybox/fancy_right-90282b4a33dd7af5b5ba9169d85f7e298e2139ea.png"], "img/bt_team_down.png": ["/static/img/bt_team_down-8c41920651309cbd738377eb791416473e411fb4.png"], "img/bt_impressum_down.png": ["/static/img/bt_impressum_down-6132855df3ce6a6e5654310583995720db0e3e67.png"], "img/bt_events_down.png": ["/static/img/bt_events_down-262c60bc4694507f2921837bd695743c5bc0e9b5.png"], "img/bt_welcome.png": ["/static/img/bt_welcome-dee96d130b7d4834455df683da2a5ef53e011460.png"], "img/spinner_small.gif": ["/static/img/spinner_small-aa138db0fc5fda6d4c78c01bb651a86944639a10.gif"], "img/logo_red-bull.png": ["/static/img/logo_red-bull-efc9eb475da3529da15e40eaaf51c9134804c2e0.png"], "img/logo_ballerina-to-go.png": ["/static/img/logo_ballerina-to-go-bc605179aec1785a8069b7791b8aeb77b4d754a0.png"], "img/ornament_left.png": ["/static/img/ornament_left-34739a0a13136b16dc2f0cb6dc9466a7dd3715a7.png"], "img/fancybox/fancy_loading.png": ["/static/img/fancybox/fancy_loading-c886c8e7fe3f27b077506afd9ec05f7d260db2b5.png"], "img/fancybox/fancy_title_over.png": ["/static/img/fancybox/fancy_title_over-78554e1809d1f0bf32ac585501aad6a39652a948.png"], "sound.ogg": ["/static/sound-8ea6ce7850637f0e64ddb356b83df4912a0f6312.ogg"], "img/bt_newsletter_down.png": ["/static/img/bt_newsletter_down-79634525387f6198ec38b7331c7eeb4022445be1.png"], "main.css": ["/static/main-1f8bbf866b272cd06fe445db927d88b1740cc7e4.css"], "img/icon_right.png": ["/static/img/icon_right-b587001150c313cc465d5a79f3e1fc5f9f677280.png"], "img/sound.png": ["/static/img/sound-8145af8c55a321c0e2111324ee92851987a862a6.png"], "img/bt_location.png": ["/static/img/bt_location-786e326f92a826a3951837c9937491cedecd2975.png"], "img/logo_scavi-ray.png": ["/static/img/logo_scavi-ray-91b9a32b7ee215247a206be63a3c545003c5fb7c.png"], "img/bt_video.png": ["/static/img/bt_video-f16f96697fc21907c47ef5280e614154fc126c00.png"], "img/bt_reservierung.png": ["/static/img/bt_reservierung-2ea2d5251f54d71f8be1eddcfbdb5895f1fc3a99.png"], "img/fancybox/fancy_closebox.png": ["/static/img/fancybox/fancy_closebox-6227e5d22184d5f4a01aa29aa35f92717c6e838b.png"], "img/video_thumb.png": ["/static/img/video_thumb-24bd4a808d95e5ff0a8cec74055e1a4abecd2b49.png"], "img/fancybox/fancy_shadow_w.png": ["/static/img/fancybox/fancy_shadow_w-c0720e6adca6f302d267ea42d187bfb44b02c0cd.png"], "img/bt_kontakt_down.png": ["/static/img/bt_kontakt_down-435d63f75489fe71241c08f9176eeb999a6c23f5.png"], "player.swf": ["/static/player-6b860f0fcbd68022f58da27b9539dd56724261aa.swf"], "img/fancybox/fancy_title_left.png": ["/static/img/fancybox/fancy_title_left-54a02621389aaaac4922ac474470054acf970a47.png"], "img/ornament_right.png": ["/static/img/ornament_right-f351dd8a680855fc41a95b5b458c1c97c7371bcb.png"], "img/fancybox/blank.gif": ["/static/img/fancybox/blank-2daeaa8b5f19f0bc209d976c02bd6acb51b00b0a.gif"], "img/fb_social-button.png": ["/static/img/fb_social-button-e071ee731b50676d9d9a03f9f832f26b84bc21ce.png"], "img/fancybox/fancy_close.png": ["/static/img/fancybox/fancy_close-9869afeaf6ac83da7798a26e558b5f4324d1153a.png"], "img/fancybox/fancy_nav_left.png": ["/static/img/fancybox/fancy_nav_left-9a24f56be5c42dfb8bf4726d1181f91a4312ab08.png"], "img/icon_bt_up.png": ["/static/img/icon_bt_up-0b4fcbc3de1cf1c8151828f19be84fa18211f458.png"], "img/bt_kontakt.png": ["/static/img/bt_kontakt-e4fa698889ae1882689095b1b9c81dba20a4c82d.png"], "img/icon_left.png": ["/static/img/icon_left-ff6261277d5cf97695fc57b8e1bb2166a83e49f9.png"], "img/bt_location_down.png": ["/static/img/bt_location_down-fe801b68fa18b34fb1665bda4baa994bb04c81bb.png"], "img/fancybox/fancy_left.png": ["/static/img/fancybox/fancy_left-1bba5d5bbe7524cb088796c62baf87db65bf387a.png"], "img/logo_schwarze-dose.png": ["/static/img/logo_schwarze-dose-a5681050a47ed91f59918b9fc77c812eb6fc531d.png"], "img/bt_galerie_down.png": ["/static/img/bt_galerie_down-76edc1606411fef692903f53cba4e5abaafa63c4.png"], "img/bt_ticketshop_down.png": ["/static/img/bt_ticketshop_down-fb5bf09feb24a2e42884aebfd5b3100ae83e88ca.png"], "img/logo_warsteiner.png": ["/static/img/logo_warsteiner-952c3c9cced9d472a422ec79eff3f208b80484bd.png"], "img/bt_reservierung_down.png": ["/static/img/bt_reservierung_down-dc2e08f432bf2c38dedece50cdb7b08861c2f107.png"], "img/bt_events.png": ["/static/img/bt_events-bda1d4912a470e4cfc1a22050eecb59e3fecab0b.png"], "img/fancybox/fancy_shadow_s.png": ["/static/img/fancybox/fancy_shadow_s-a817ccadf826a55d58a34acb6f07cae971e70f1f.png"]};

media_urls = function(key) {
  var urls = _$MEDIA_URLS[key];
  if (!urls)
    throw 'Could not resolve media url ' + key;
  return urls;
};

media_url = function(key) {
  var urls = media_urls(key);
  if (urls.length == 1)
    return urls[0];
  throw 'media_url() only works with keys that point to a single entry (e.g. an image), but not bundles. Use media_urls() instead.';
};


/*
 * jQuery history plugin
 * 
 * The MIT License
 * 
 * Copyright (c) 2006-2009 Taku Sano (Mikage Sawatari)
 * Copyright (c) 2010 Takayuki Miwa
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

(function($) {
    var locationWrapper = {
        put: function(hash, win) {
            (win || window).location.hash = this.encoder(hash);
        },
        get: function(win) {
            var hash = ((win || window).location.hash).replace(/^#/, '');
            try {
                return $.browser.mozilla ? hash : decodeURIComponent(hash);
            }
            catch (error) {
                return hash;
            }
        },
        encoder: encodeURIComponent
    };

    var iframeWrapper = {
        id: "__jQuery_history",
        init: function() {
            var html = '<iframe id="'+ this.id +'" style="display:none" src="javascript:false;" />';
            $("body").prepend(html);
            return this;
        },
        _document: function() {
            return $("#"+ this.id)[0].contentWindow.document;
        },
        put: function(hash) {
            var doc = this._document();
            doc.open();
            doc.close();
            locationWrapper.put(hash, doc);
        },
        get: function() {
            return locationWrapper.get(this._document());
        }
    };

    function initObjects(options) {
        options = $.extend({
                unescape: false
            }, options || {});

        locationWrapper.encoder = encoder(options.unescape);

        function encoder(unescape_) {
            if(unescape_ === true) {
                return function(hash){ return hash; };
            }
            if(typeof unescape_ == "string" &&
               (unescape_ = partialDecoder(unescape_.split("")))
               || typeof unescape_ == "function") {
                return function(hash) { return unescape_(encodeURIComponent(hash)); };
            }
            return encodeURIComponent;
        }

        function partialDecoder(chars) {
            var re = new RegExp($.map(chars, encodeURIComponent).join("|"), "ig");
            return function(enc) { return enc.replace(re, decodeURIComponent); };
        }
    }

    var implementations = {};

    implementations.base = {
        callback: undefined,
        type: undefined,

        check: function() {},
        load:  function(hash) {},
        init:  function(callback, options) {
            initObjects(options);
            self.callback = callback;
            self._options = options;
            self._init();
        },

        _init: function() {},
        _options: {}
    };

    implementations.timer = {
        _appState: undefined,
        _init: function() {
            var current_hash = locationWrapper.get();
            self._appState = current_hash;
            self.callback(current_hash);
            setInterval(self.check, 100);
        },
        check: function() {
            var current_hash = locationWrapper.get();
            if(current_hash != self._appState) {
                self._appState = current_hash;
                self.callback(current_hash);
            }
        },
        load: function(hash) {
            if(hash != self._appState) {
                locationWrapper.put(hash);
                self._appState = hash;
                self.callback(hash);
            }
        }
    };

    implementations.iframeTimer = {
        _appState: undefined,
        _init: function() {
            var current_hash = locationWrapper.get();
            self._appState = current_hash;
            iframeWrapper.init().put(current_hash);
            self.callback(current_hash);
            setInterval(self.check, 100);
        },
        check: function() {
            var iframe_hash = iframeWrapper.get(),
                location_hash = locationWrapper.get();

            if (location_hash != iframe_hash) {
                if (location_hash == self._appState) {    // user used Back or Forward button
                    self._appState = iframe_hash;
                    locationWrapper.put(iframe_hash);
                    self.callback(iframe_hash); 
                } else {                              // user loaded new bookmark
                    self._appState = location_hash;  
                    iframeWrapper.put(location_hash);
                    self.callback(location_hash);
                }
            }
        },
        load: function(hash) {
            if(hash != self._appState) {
                locationWrapper.put(hash);
                iframeWrapper.put(hash);
                self._appState = hash;
                self.callback(hash);
            }
        }
    };

    implementations.hashchangeEvent = {
        _init: function() {
            self.callback(locationWrapper.get());
            $(window).bind('hashchange', self.check);
        },
        check: function() {
            self.callback(locationWrapper.get());
        },
        load: function(hash) {
            locationWrapper.put(hash);
        }
    };

    var self = $.extend({}, implementations.base);

    if($.browser.msie && ($.browser.version < 8 || document.documentMode < 8)) {
        self.type = 'iframeTimer';
    } else if("onhashchange" in window) {
        self.type = 'hashchangeEvent';
    } else {
        self.type = 'timer';
    }

    $.extend(self, implementations[self.type]);
    $.history = self;
})(jQuery);


/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
 *
 * Uses the built in easing capabilities added In jQuery 1.1
 * to offer multiple easing options
 *
 * TERMS OF USE - jQuery Easing
 * 
 * Open source under the BSD License. 
 * 
 * Copyright © 2008 George McGinley Smith
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
*/

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});

/*
 *
 * TERMS OF USE - EASING EQUATIONS
 * 
 * Open source under the BSD License. 
 * 
 * Copyright © 2001 Robert Penner
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
 */

/*
 * FancyBox - jQuery Plugin
 * Simple and fancy lightbox alternative
 *
 * Examples and documentation at: http://fancybox.net
 * 
 * Copyright (c) 2008 - 2010 Janis Skarnelis
 *
 * Version: 1.3.1 (05/03/2010)
 * Requires: jQuery v1.3+
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */

(function($) {

    var tmp, loading, overlay, wrap, outer, inner, close, nav_left, nav_right,

    selectedIndex = 0, selectedOpts = {}, selectedArray = [], currentIndex = 0, currentOpts = {}, currentArray = [],

    ajaxLoader = null, imgPreloader = new Image(), imgRegExp = /\.(jpg|gif|png|bmp|jpeg)(.*)?$/i, swfRegExp = /[^\.]\.(swf)\s*$/i,

    loadingTimer, loadingFrame = 1,

    start_pos, final_pos, busy = false, shadow = 20, fx = $.extend($('<div/>')[0], {
        prop: 0
    }), titleh = 0,

    isIE6 = !$.support.opacity && !window.XMLHttpRequest,

    /*
		 * Private methods 
		 */

    fancybox_abort = function() {
        loading.hide();

        imgPreloader.onerror = imgPreloader.onload = null;

        if (ajaxLoader) {
            ajaxLoader.abort();
        }

        tmp.empty();
    },

    fancybox_error = function() {
        if ($.isFunction(selectedOpts.onError)) {
            selectedOpts.onError();
        } else {
            $.fancybox('<p id="fancybox_error">The requested content cannot be loaded.<br />Please try again later.</p>', {
                'scrolling'		: 'no',
                'padding'		: 20,
                'transitionIn'	: 'none',
                'transitionOut'	: 'none'
            });
        }
    },

    fancybox_get_viewport = function() {
        return [ $(window).width(), $(window).height(), $(document).scrollLeft(), $(document).scrollTop() ];
    },

    fancybox_get_zoom_to = function () {
        var view	= fancybox_get_viewport(),
        to		= {},

        margin = currentOpts.margin,
        resize = currentOpts.autoScale,

        horizontal_space	= (shadow + margin) * 2,
        vertical_space		= (shadow + margin) * 2,
        double_padding		= (currentOpts.padding * 2),
				
        ratio;

        if (currentOpts.width.toString().indexOf('%') > -1) {
            to.width = ((view[0] * parseFloat(currentOpts.width)) / 100) - (shadow * 2) ;
            resize = false;

        } else {
            to.width = currentOpts.width + double_padding;
        }

        if (currentOpts.height.toString().indexOf('%') > -1) {
            to.height = ((view[1] * parseFloat(currentOpts.height)) / 100) - (shadow * 2);
            resize = false;

        } else {
            to.height = currentOpts.height + double_padding;
        }

        if (resize && (to.width > (view[0] - horizontal_space) || to.height > (view[1] - vertical_space))) {
            if (selectedOpts.type == 'image' || selectedOpts.type == 'swf') {
                horizontal_space	+= double_padding;
                vertical_space		+= double_padding;

                ratio = Math.min(Math.min( view[0] - horizontal_space, currentOpts.width) / currentOpts.width, Math.min( view[1] - vertical_space, currentOpts.height) / currentOpts.height);

                to.width	= Math.round(ratio * (to.width	- double_padding)) + double_padding;
                to.height	= Math.round(ratio * (to.height	- double_padding)) + double_padding;

            } else {
                to.width	= Math.min(to.width,	(view[0] - horizontal_space));
                to.height	= Math.min(to.height,	(view[1] - vertical_space));
            }
        }

        to.top	= view[3] + ((view[1] - (to.height	+ (shadow * 2 ))) * 0.5);
        to.left	= view[2] + ((view[0] - (to.width	+ (shadow * 2 ))) * 0.5);

        if (currentOpts.autoScale === false) {
            to.top	= Math.max(view[3] + margin, to.top);
            to.left	= Math.max(view[2] + margin, to.left);
        }

        return to;
    },

    fancybox_format_title = function(title) {
        if (title && title.length) {
            switch (currentOpts.titlePosition) {
                case 'inside':
                    return title;
                case 'over':
                    return '<span id="fancybox-title-over">' + title + '</span>';
                default:
                    return '<span id="fancybox-title-wrap"><span id="fancybox-title-left"></span><span id="fancybox-title-main">' + title + '</span><span id="fancybox-title-right"></span></span>';
            }
        }

        return false;
    },

    fancybox_process_title = function() {
        var title	= currentOpts.title,
        width	= final_pos.width - (currentOpts.padding * 2),
        titlec	= 'fancybox-title-' + currentOpts.titlePosition;
				
        $('#fancybox-title').remove();

        titleh = 0;

        if (currentOpts.titleShow === false) {
            return;
        }

        title = $.isFunction(currentOpts.titleFormat) ? currentOpts.titleFormat(title, currentArray, currentIndex, currentOpts) : fancybox_format_title(title);

        if (!title || title === '') {
            return;
        }

        $('<div id="fancybox-title" class="' + titlec + '" />').css({
            'width'			: width,
            'paddingLeft'	: currentOpts.padding,
            'paddingRight'	: currentOpts.padding
        }).html(title).appendTo('body');

        switch (currentOpts.titlePosition) {
            case 'inside':
                titleh = $("#fancybox-title").outerHeight(true) - currentOpts.padding;
                final_pos.height += titleh;
                break;

            case 'over':
                $('#fancybox-title').css('bottom', currentOpts.padding);
                break;

            default:
                $('#fancybox-title').css('bottom', $("#fancybox-title").outerHeight(true) * -1);
                break;
        }

        $('#fancybox-title').appendTo( outer ).hide();
    },

    fancybox_set_navigation = function() {
        $(document).unbind('keydown.fb').bind('keydown.fb', function(e) {
            if (e.keyCode == 27 && currentOpts.enableEscapeButton) {
                e.preventDefault();
                $.fancybox.close();

            } else if (e.keyCode == 37) {
                e.preventDefault();
                $.fancybox.prev();

            } else if (e.keyCode == 39) {
                e.preventDefault();
                $.fancybox.next();
            }
        });

        if ($.fn.mousewheel) {
            wrap.unbind('mousewheel.fb');

            if (currentArray.length > 1) {
                wrap.bind('mousewheel.fb', function(e, delta) {
                    e.preventDefault();

                    if (busy || delta === 0) {
                        return;
                    }

                    if (delta > 0) {
                        $.fancybox.prev();
                    } else {
                        $.fancybox.next();
                    }
                });
            }
        }

        if (!currentOpts.showNavArrows) {
            return;
        }

        if ((currentOpts.cyclic && currentArray.length > 1) || currentIndex !== 0) {
            nav_left.show();
        }

        if ((currentOpts.cyclic && currentArray.length > 1) || currentIndex != (currentArray.length -1)) {
            nav_right.show();
        }
    },

    fancybox_preload_images = function() {
        var href,
        objNext;
				
        if ((currentArray.length -1) > currentIndex) {
            href = currentArray[ currentIndex + 1 ].href;

            if (typeof href !== 'undefined' && href.match(imgRegExp)) {
                objNext = new Image();
                objNext.src = href;
            }
        }

        if (currentIndex > 0) {
            href = currentArray[ currentIndex - 1 ].href;

            if (typeof href !== 'undefined' && href.match(imgRegExp)) {
                objNext = new Image();
                objNext.src = href;
            }
        }
    },

    _finish = function () {
        inner.css('overflow', (currentOpts.scrolling == 'auto' ? (currentOpts.type == 'image' || currentOpts.type == 'iframe' || currentOpts.type == 'swf' ? 'hidden' : 'auto') : (currentOpts.scrolling == 'yes' ? 'auto' : 'visible')));

        if (!$.support.opacity) {
            inner.get(0).style.removeAttribute('filter');
            wrap.get(0).style.removeAttribute('filter');
        }

        $('#fancybox-title').show();

        if (currentOpts.hideOnContentClick)	{
            inner.one('click', $.fancybox.close);
        }
        if (currentOpts.hideOnOverlayClick)	{
            overlay.one('click', $.fancybox.close);
        }

        if (currentOpts.showCloseButton) {
            close.show();
        }

        fancybox_set_navigation();

        $(window).bind("resize.fb", $.fancybox.center);

        if (currentOpts.centerOnScroll) {
            $(window).bind("scroll.fb", $.fancybox.center);
        } else {
            $(window).unbind("scroll.fb");
        }

        if ($.isFunction(currentOpts.onComplete)) {
            currentOpts.onComplete(currentArray, currentIndex, currentOpts);
        }

        busy = false;

        fancybox_preload_images();
    },

    fancybox_draw = function(pos) {
        var width	= Math.round(start_pos.width	+ (final_pos.width	- start_pos.width)	* pos),
        height	= Math.round(start_pos.height	+ (final_pos.height	- start_pos.height)	* pos),

        top		= Math.round(start_pos.top	+ (final_pos.top	- start_pos.top)	* pos),
        left	= Math.round(start_pos.left	+ (final_pos.left	- start_pos.left)	* pos);

        wrap.css({
            'width'		: width		+ 'px',
            'height'	: height	+ 'px',
            'top'		: top		+ 'px',
            'left'		: left		+ 'px'
        });

        width	= Math.max(width - currentOpts.padding * 2, 0);
        height	= Math.max(height - (currentOpts.padding * 2 + (titleh * pos)), 0);

        inner.css({
            'width'		: width		+ 'px',
            'height'	: height	+ 'px'
        });

        if (typeof final_pos.opacity !== 'undefined') {
            wrap.css('opacity', (pos < 0.5 ? 0.5 : pos));
        }
    },

    fancybox_get_obj_pos = function(obj) {
        var pos		= obj.offset();

        pos.top		+= parseFloat( obj.css('paddingTop') )	|| 0;
        pos.left	+= parseFloat( obj.css('paddingLeft') )	|| 0;

        pos.top		+= parseFloat( obj.css('border-top-width') )	|| 0;
        pos.left	+= parseFloat( obj.css('border-left-width') )	|| 0;

        pos.width	= obj.width();
        pos.height	= obj.height();

        return pos;
    },

    fancybox_get_zoom_from = function() {
        var orig = selectedOpts.orig ? $(selectedOpts.orig) : false,
        from = {},
        pos,
        view;

        if (orig && orig.length) {
            pos = fancybox_get_obj_pos(orig);

            from = {
                width	: (pos.width	+ (currentOpts.padding * 2)),
                height	: (pos.height	+ (currentOpts.padding * 2)),
                top		: (pos.top		- currentOpts.padding - shadow),
                left	: (pos.left		- currentOpts.padding - shadow)
            };
				
        } else {
            view = fancybox_get_viewport();

            from = {
                width	: 1,
                height	: 1,
                top		: view[3] + view[1] * 0.5,
                left	: view[2] + view[0] * 0.5
            };
        }

        return from;
    },

    fancybox_show = function() {
        loading.hide();

        if (wrap.is(":visible") && $.isFunction(currentOpts.onCleanup)) {
            if (currentOpts.onCleanup(currentArray, currentIndex, currentOpts) === false) {
                $.event.trigger('fancybox-cancel');

                busy = false;
                return;
            }
        }

        currentArray	= selectedArray;
        currentIndex	= selectedIndex;
        currentOpts		= selectedOpts;

        inner.get(0).scrollTop	= 0;
        inner.get(0).scrollLeft	= 0;

        if (currentOpts.overlayShow) {
            if (isIE6) {
                $('select:not(#fancybox-tmp select)').filter(function() {
                    return this.style.visibility !== 'hidden';
                }).css({
                    'visibility':'hidden'
                }).one('fancybox-cleanup', function() {
                    this.style.visibility = 'inherit';
                });
            }

            overlay.css({
                'background-color'	: currentOpts.overlayColor,
                'opacity'			: currentOpts.overlayOpacity
            }).unbind().show();
        }

        final_pos = fancybox_get_zoom_to();

        fancybox_process_title();

        if (wrap.is(":visible")) {
            $( close.add( nav_left ).add( nav_right ) ).hide();

            var pos = wrap.position(),
            equal;

            start_pos = {
                top		:	pos.top ,
                left	:	pos.left,
                width	:	wrap.width(),
                height	:	wrap.height()
            };

            equal = (start_pos.width == final_pos.width && start_pos.height == final_pos.height);

            inner.fadeOut(currentOpts.changeFade, function() {
                var finish_resizing = function() {
                    inner.html( tmp.contents() ).fadeIn(currentOpts.changeFade, _finish);
                };
					
                $.event.trigger('fancybox-change');

                inner.empty().css('overflow', 'hidden');

                if (equal) {
                    inner.css({
                        top			: currentOpts.padding,
                        left		: currentOpts.padding,
                        width		: Math.max(final_pos.width	- (currentOpts.padding * 2), 1),
                        height		: Math.max(final_pos.height	- (currentOpts.padding * 2) - titleh, 1)
                    });
						
                    finish_resizing();

                } else {
                    inner.css({
                        top			: currentOpts.padding,
                        left		: currentOpts.padding,
                        width		: Math.max(start_pos.width	- (currentOpts.padding * 2), 1),
                        height		: Math.max(start_pos.height	- (currentOpts.padding * 2), 1)
                    });
						
                    fx.prop = 0;

                    $(fx).animate({
                        prop: 1
                    }, {
                        duration	: currentOpts.changeSpeed,
                        easing		: currentOpts.easingChange,
                        step		: fancybox_draw,
                        complete	: finish_resizing
                    });
                }
            });

            return;
        }

        wrap.css('opacity', 1);

        if (currentOpts.transitionIn == 'elastic') {
            start_pos = fancybox_get_zoom_from();

            inner.css({
                top			: currentOpts.padding,
                left		: currentOpts.padding,
                width		: Math.max(start_pos.width	- (currentOpts.padding * 2), 1),
                height		: Math.max(start_pos.height	- (currentOpts.padding * 2), 1)
            })
            .html( tmp.contents() );

            wrap.css(start_pos).show();

            if (currentOpts.opacity) {
                final_pos.opacity = 0;
            }

            fx.prop = 0;

            $(fx).animate({
                prop: 1
            }, {
                duration	: currentOpts.speedIn,
                easing		: currentOpts.easingIn,
                step		: fancybox_draw,
                complete	: _finish
            });

        } else {
            inner.css({
                top			: currentOpts.padding,
                left		: currentOpts.padding,
                width		: Math.max(final_pos.width	- (currentOpts.padding * 2), 1),
                height		: Math.max(final_pos.height	- (currentOpts.padding * 2) - titleh, 1)
            })
            .html( tmp.contents() );

            wrap.css( final_pos ).fadeIn( currentOpts.transitionIn == 'none' ? 0 : currentOpts.speedIn, _finish );
        }
    },

    fancybox_process_inline = function() {
        tmp.width(	selectedOpts.width );
        tmp.height(	selectedOpts.height );

        if (selectedOpts.width	== 'auto') {
            selectedOpts.width = tmp.width();
        }
        if (selectedOpts.height	== 'auto') {
            selectedOpts.height	= tmp.height();
        }

        fancybox_show();
    },
		
    fancybox_process_image = function() {
        busy = true;

        selectedOpts.width	= imgPreloader.width;
        selectedOpts.height	= imgPreloader.height;

        $("<img />").attr({
            'id'	: 'fancybox-img',
            'src'	: imgPreloader.src,
            'alt'	: selectedOpts.title
        }).appendTo( tmp );

        fancybox_show();
    },

    fancybox_start = function() {
        fancybox_abort();

        var obj	= selectedArray[ selectedIndex ],
        href,
        type,
        title,
        str,
        emb,
        selector,
        data;

        selectedOpts = $.extend({}, $.fn.fancybox.defaults, (typeof $(obj).data('fancybox') == 'undefined' ? selectedOpts : $(obj).data('fancybox')));
        title = obj.title || $(obj).title || selectedOpts.title || '';
			
        if (obj.nodeName && !selectedOpts.orig) {
            selectedOpts.orig = $(obj).children("img:first").length ? $(obj).children("img:first") : $(obj);
        }

        if (title === '' && selectedOpts.orig) {
            title = selectedOpts.orig.attr('alt');
        }

        if (obj.nodeName && (/^(?:javascript|#)/i).test(obj.href)) {
            href = selectedOpts.href || null;
        } else {
            href = selectedOpts.href || obj.href || null;
        }

        if (selectedOpts.type) {
            type = selectedOpts.type;

            if (!href) {
                href = selectedOpts.content;
            }
				
        } else if (selectedOpts.content) {
            type	= 'html';

        } else if (href) {
            if (href.match(imgRegExp)) {
                type = 'image';

            } else if (href.match(swfRegExp)) {
                type = 'swf';

            } else if ($(obj).hasClass("iframe")) {
                type = 'iframe';

            } else if (href.match(/#/)) {
                obj = href.substr(href.indexOf("#"));

                type = $(obj).length > 0 ? 'inline' : 'ajax';
            } else {
                type = 'ajax';
            }
        } else {
            type = 'inline';
        }

        selectedOpts.type	= type;
        selectedOpts.href	= href;
        selectedOpts.title	= title;

        if (selectedOpts.autoDimensions && selectedOpts.type !== 'iframe' && selectedOpts.type !== 'swf') {
            selectedOpts.width		= 'auto';
            selectedOpts.height		= 'auto';
        }

        if (selectedOpts.modal) {
            selectedOpts.overlayShow		= true;
            selectedOpts.hideOnOverlayClick	= false;
            selectedOpts.hideOnContentClick	= false;
            selectedOpts.enableEscapeButton	= false;
            selectedOpts.showCloseButton	= false;
        }

        if ($.isFunction(selectedOpts.onStart)) {
            if (selectedOpts.onStart(selectedArray, selectedIndex, selectedOpts) === false) {
                busy = false;
                return;
            }
        }

        tmp.css('padding', (shadow + selectedOpts.padding + selectedOpts.margin));

        $('.fancybox-inline-tmp').unbind('fancybox-cancel').bind('fancybox-change', function() {
            $(this).replaceWith(inner.children());
        });

        switch (type) {
            case 'html' :
                tmp.html( selectedOpts.content );
                fancybox_process_inline();
                break;

            case 'inline' :
                $('<div class="fancybox-inline-tmp" />').hide().insertBefore( $(obj) ).bind('fancybox-cleanup', function() {
                    $(this).replaceWith(inner.children());
                }).bind('fancybox-cancel', function() {
                    $(this).replaceWith(tmp.children());
                });

                $(obj).appendTo(tmp);

                fancybox_process_inline();
                break;

            case 'image':
                busy = false;

                $.fancybox.showActivity();

                imgPreloader = new Image();

                imgPreloader.onerror = function() {
                    fancybox_error();
                };

                imgPreloader.onload = function() {
                    imgPreloader.onerror = null;
                    imgPreloader.onload = null;
                    fancybox_process_image();
                };

                imgPreloader.src = href;
		
                break;

            case 'swf':
                str = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + selectedOpts.width + '" height="' + selectedOpts.height + '"><param name="movie" value="' + href + '"></param>';
                emb = '';
					
                $.each(selectedOpts.swf, function(name, val) {
                    str += '<param name="' + name + '" value="' + val + '"></param>';
                    emb += ' ' + name + '="' + val + '"';
                });

                str += '<embed src="' + href + '" type="application/x-shockwave-flash" width="' + selectedOpts.width + '" height="' + selectedOpts.height + '"' + emb + '></embed></object>';

                tmp.html(str);

                fancybox_process_inline();
                break;

            case 'ajax':
                selector	= href.split('#', 2);
                data		= selectedOpts.ajax.data || {};

                if (selector.length > 1) {
                    href = selector[0];

                    if (typeof data == "string") {
                        data += '&selector=' + selector[1];
                    } else {
                        data.selector = selector[1];
                    }
                }

                busy = false;
                $.fancybox.showActivity();

                ajaxLoader = $.ajax($.extend(selectedOpts.ajax, {
                    url		: href,
                    data	: data,
                    error	: fancybox_error,
                    success : function(data, textStatus, XMLHttpRequest) {
                        if (ajaxLoader.status == 200) {
                            tmp.html( data );
                            fancybox_process_inline();
                        }
                    }
                }));

                break;

            case 'iframe' :
                $('<iframe id="fancybox-frame" name="fancybox-frame' + new Date().getTime() + '" frameborder="0" hspace="0" scrolling="' + selectedOpts.scrolling + '" src="' + selectedOpts.href + '"></iframe>').appendTo(tmp);
                fancybox_show();
                break;
        }
    },

    fancybox_animate_loading = function() {
        if (!loading.is(':visible')){
            clearInterval(loadingTimer);
            return;
        }

        $('div', loading).css('top', (loadingFrame * -40) + 'px');

        loadingFrame = (loadingFrame + 1) % 12;
    },

    fancybox_init = function() {
        if ($("#fancybox-wrap").length) {
            return;
        }

        $('body').append(
            tmp			= $('<div id="fancybox-tmp"></div>'),
            loading		= $('<div id="fancybox-loading"><div></div></div>'),
            overlay		= $('<div id="fancybox-overlay"></div>'),
            wrap		= $('<div id="fancybox-wrap"></div>')
            );

        if (!$.support.opacity) {
            wrap.addClass('fancybox-ie');
            loading.addClass('fancybox-ie');
        }

        outer = $('<div id="fancybox-outer"></div>')
        .append('<div class="fancy-bg" id="fancy-bg-n"></div><div class="fancy-bg" id="fancy-bg-ne"></div><div class="fancy-bg" id="fancy-bg-e"></div><div class="fancy-bg" id="fancy-bg-se"></div><div class="fancy-bg" id="fancy-bg-s"></div><div class="fancy-bg" id="fancy-bg-sw"></div><div class="fancy-bg" id="fancy-bg-w"></div><div class="fancy-bg" id="fancy-bg-nw"></div>')
        .appendTo( wrap );

        outer.append(
            inner		= $('<div id="fancybox-inner"></div>'),
            close		= $('<a id="fancybox-close"></a>'),

            nav_left	= $('<a href="javascript:;" id="fancybox-left"><span class="fancy-ico" id="fancybox-left-ico"></span></a>'),
            nav_right	= $('<a href="javascript:;" id="fancybox-right"><span class="fancy-ico" id="fancybox-right-ico"></span></a>')
            );

        close.click($.fancybox.close);
        loading.click($.fancybox.cancel);

        nav_left.click(function(e) {
            e.preventDefault();
            $.fancybox.prev();
        });

        nav_right.click(function(e) {
            e.preventDefault();
            $.fancybox.next();
        });

        if (isIE6) {
            overlay.get(0).style.setExpression('height',	"document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px'");
            loading.get(0).style.setExpression('top',		"(-20 + (document.documentElement.clientHeight ? document.documentElement.clientHeight/2 : document.body.clientHeight/2 ) + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop )) + 'px'");

            outer.prepend('<iframe id="fancybox-hide-sel-frame" src="javascript:\'\';" scrolling="no" frameborder="0" ></iframe>');
        }
    };

    /*
	 * Public methods 
	 */

    $.fn.fancybox = function(options) {
        $(this)
        .data('fancybox', $.extend({}, options, ($.metadata ? $(this).metadata() : {})))
        .unbind('click.fb').bind('click.fb', function(e) {
            e.preventDefault();

            if (busy) {
                return;
            }

            busy = true;

            $(this).blur();

            selectedArray	= [];
            selectedIndex	= 0;

            var rel = $(this).attr('rel') || '';

            if (!rel || rel == '' || rel === 'nofollow') {
                selectedArray.push(this);

            } else {
                selectedArray	= $("a[rel=" + rel + "], area[rel=" + rel + "]");
                selectedIndex	= selectedArray.index( this );
            }

            fancybox_start();

            return false;
        });

        return this;
    };

    $.fancybox = function(obj) {
        if (busy) {
            return;
        }

        busy = true;

        var opts = typeof arguments[1] !== 'undefined' ? arguments[1] : {};

        selectedArray	= [];
        selectedIndex	= opts.index || 0;

        if ($.isArray(obj)) {
            for (var i = 0, j = obj.length; i < j; i++) {
                if (typeof obj[i] == 'object') {
                    $(obj[i]).data('fancybox', $.extend({}, opts, obj[i]));
                } else {
                    obj[i] = $({}).data('fancybox', $.extend({
                        content : obj[i]
                        }, opts));
                }
            }

            selectedArray = jQuery.merge(selectedArray, obj);

        } else {
            if (typeof obj == 'object') {
                $(obj).data('fancybox', $.extend({}, opts, obj));
            } else {
                obj = $({}).data('fancybox', $.extend({
                    content : obj
                }, opts));
            }

            selectedArray.push(obj);
        }

        if (selectedIndex > selectedArray.length || selectedIndex < 0) {
            selectedIndex = 0;
        }

        fancybox_start();
    };

    $.fancybox.showActivity = function() {
        clearInterval(loadingTimer);

        loading.show();
        loadingTimer = setInterval(fancybox_animate_loading, 66);
    };

    $.fancybox.hideActivity = function() {
        loading.hide();
    };

    $.fancybox.next = function() {
        return $.fancybox.pos( currentIndex + 1);
    };
	
    $.fancybox.prev = function() {
        return $.fancybox.pos( currentIndex - 1);
    };

    $.fancybox.pos = function(pos) {
        if (busy) {
            return;
        }

        pos = parseInt(pos, 10);

        if (pos > -1 && currentArray.length > pos) {
            selectedIndex = pos;
            fancybox_start();
        }

        if (currentOpts.cyclic && currentArray.length > 1 && pos < 0) {
            selectedIndex = currentArray.length - 1;
            fancybox_start();
        }

        if (currentOpts.cyclic && currentArray.length > 1 && pos >= currentArray.length) {
            selectedIndex = 0;
            fancybox_start();
        }

        return;
    };

    $.fancybox.cancel = function() {
        if (busy) {
            return;
        }

        busy = true;

        $.event.trigger('fancybox-cancel');

        fancybox_abort();

        if (selectedOpts && $.isFunction(selectedOpts.onCancel)) {
            selectedOpts.onCancel(selectedArray, selectedIndex, selectedOpts);
        }

        busy = false;
    };

    // Note: within an iframe use - parent.$.fancybox.close();
    $.fancybox.close = function() {
        if (busy || wrap.is(':hidden')) {
            return;
        }

        busy = true;

        if (currentOpts && $.isFunction(currentOpts.onCleanup)) {
            if (currentOpts.onCleanup(currentArray, currentIndex, currentOpts) === false) {
                busy = false;
                return;
            }
        }

        fancybox_abort();

        $(close.add( nav_left ).add( nav_right )).hide();

        $('#fancybox-title').remove();

        wrap.add(inner).add(overlay).unbind();

        $(window).unbind("resize.fb scroll.fb");
        $(document).unbind('keydown.fb');

        function _cleanup() {
            overlay.fadeOut('fast');

            wrap.hide();

            $.event.trigger('fancybox-cleanup');

            inner.empty();

            if ($.isFunction(currentOpts.onClosed)) {
                currentOpts.onClosed(currentArray, currentIndex, currentOpts);
            }

            currentArray	= selectedOpts	= [];
            currentIndex	= selectedIndex	= 0;
            currentOpts		= selectedOpts	= {};

            busy = false;
        }

        inner.css('overflow', 'hidden');

        if (currentOpts.transitionOut == 'elastic') {
            start_pos = fancybox_get_zoom_from();

            var pos = wrap.position();

            final_pos = {
                top		:	pos.top ,
                left	:	pos.left,
                width	:	wrap.width(),
                height	:	wrap.height()
            };

            if (currentOpts.opacity) {
                final_pos.opacity = 1;
            }

            fx.prop = 1;

            $(fx).animate({
                prop: 0
            }, {
                duration	: currentOpts.speedOut,
                easing		: currentOpts.easingOut,
                step		: fancybox_draw,
                complete	: _cleanup
            });

        } else {
            wrap.fadeOut( currentOpts.transitionOut == 'none' ? 0 : currentOpts.speedOut, _cleanup);
        }
    };

    $.fancybox.resize = function() {
        var c, h;
		
        if (busy || wrap.is(':hidden')) {
            return;
        }

        busy = true;

        c = inner.wrapInner("<div style='overflow:auto'></div>").children();
        h = c.height();

        wrap.css({
            height:	h + (currentOpts.padding * 2) + titleh
            });
        inner.css({
            height:	h
        });

        c.replaceWith(c.children());

        $.fancybox.center();
    };

    $.fancybox.center = function() {
        busy = true;

        var view	= fancybox_get_viewport(),
        margin	= currentOpts.margin,
        to		= {};

        to.top	= view[3] + ((view[1] - ((wrap.height() - titleh) + (shadow * 2 ))) * 0.5);
        to.left	= view[2] + ((view[0] - (wrap.width() + (shadow * 2 ))) * 0.5);

        to.top	= Math.max(view[3] + margin, to.top);
        to.left	= Math.max(view[2] + margin, to.left);

        wrap.css(to);

        busy = false;
    };

    $.fn.fancybox.defaults = {
        padding				:	10,
        margin				:	20,
        opacity				:	false,
        modal				:	false,
        cyclic				:	false,
        scrolling			:	'auto',	// 'auto', 'yes' or 'no'

        width				:	560,
        height				:	340,

        autoScale			:	true,
        autoDimensions		:	true,
        centerOnScroll		:	false,

        ajax				:	{},
        swf					:	{
            wmode: 'transparent'
        },

        hideOnOverlayClick	:	true,
        hideOnContentClick	:	false,

        overlayShow			:	true,
        overlayOpacity		:	0.3,
        overlayColor		:	'#666',

        titleShow			:	true,
        titlePosition		:	'inside',	// 'outside', 'inside' or 'over'
        titleFormat			:	null,

        transitionIn		:	'elastic',	// 'elastic', 'fade' or 'none'
        transitionOut		:	'elastic',	// 'elastic', 'fade' or 'none'

        speedIn				:	300,
        speedOut			:	300,

        changeSpeed			:	300,
        changeFade			:	'fast',

        easingIn			:	'swing',
        easingOut			:	'swing',

        showCloseButton		:	true,
        showNavArrows		:	true,
        enableEscapeButton	:	true,

        onStart				:	null,
        onCancel			:	null,
        onComplete			:	null,
        onCleanup			:	null,
        onClosed			:	null,
        onError                         :       null
    };

    $(document).ready(function() {
        fancybox_init();
    });

})(jQuery);

/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 5/25/2009
 * @author Ariel Flesler
 * @version 1.4.2
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);

if (Modernizr.audio) {
    var audio = $('audio').get(0);
    if(audio) {
      $(audio).bind('play',function() {
        $("#player").attr('src', media_url('img/sound.png'));  
      }).bind('pause ended', function() {
        $("#player").attr('src', media_url('img/sound_mute.png'));  
      });  
         
      $("#player").click(function() {    
        if (audio.paused) { audio.play(); }
        else { audio.pause(); }    
      });

      $(function() {
        //audio.play();
      });
  }
}


var current
var count
var constants = {
    'listWidth' : 0,
    'flyerWidth' : 150,
    'flyerHeight': 210,
    'zoomFactor' : 1.4,
    'duration' : 1000
};

function initGallery() {
    // Ãœberschrift stylen
    $("h2.gallery-monat")
    .prepend("<image src=\"" + media_url('img/ornament_left.png') + "\" alt=\"\" width=60 height=25 style=\"margin-right: 15px\" />")
    .append("<image src=\"" + media_url('img/ornament_right.png') + "\" alt=\"\" width=60 height=25 style=\"margin-left: 15px\" />");

    //Navigation mit clickEvent hinzufÃ¼gen
    $('#gallery_overview')
    .after('<p id="gallery_info"><span id="gallery_info_name"></span> <span id="gallery_info_date"></span><span style="clear: both" /></p>')
    .after('<p id="flyer_navi"><a id="gallery_previous"><img src=\"' + media_url('img/icon_left.png') + '\" alt=\"Zur&uuml;ck\" width=18 height=20 /></a> <a id="gallery_next"><img src=\"' + media_url('img/icon_right.png') + '\" alt=\"Weiter\" width=18 height=20 /></a></p>');
    $('#gallery_next').css('float', 'right').click(function(){
        showNextFlyer();
    });
    $('#gallery_previous').css('float', 'left').click(function(){
        showPrevFlyer();
    });
    $('#flyer_navi').css({
        marginLeft: 'auto',
        marginRight: 'auto',
        position:'relative',
        top: -131,
        width:300,
        zIndex:101
    })

    //HÃ¶he der ul anpassen
    $('#gallery_overview').css({
        'height' : (constants['flyerHeight']) + 20,
        'position' : 'relative'
    });

    constants['listWidth'] = $('#gallery_overview').width();

    //Infos verstecken
    $('#gallery_overview li .gallery_description').hide();

    //Flyer positionieren
    count = $('#gallery_overview li').length;
    current = count-1;
    $('#gallery_overview li').each(function(index){
        $(this).css({
            'position' : 'absolute',
            'backgroundColor' : 'black',
            'lineHeight' : 0,
            'zIndex' : 100 - count + index
        }).find('img').css({
            width : constants['flyerWidth'] / constants['zoomFactor'],
            height : constants['flyerHeight'] / constants['zoomFactor'],
            'opacity' : 0.4
        });
        if (index < current) {
            $(this).css('left', 20);
        } else if (index == current) {
            $(this).find('img').css({
                'width' : constants['flyerWidth'],
                'height' : constants['flyerHeight'],
                'opacity' : 1
            });
            $(this).css('left', (591 / 2) - (constants['flyerWidth'] / 2));
        } else if (index > current) {
            $(this).css('left', 500);
        }
    });

    //Infos auslesen und anzeigen
    $('#gallery_info_name').html($('#gallery_overview li').eq(current).find('.gallery_name').html());
    $('#gallery_info_date').html($('#gallery_overview li').eq(current).find('.gallery_date').html());

    //Hover fÃ¼r Galeriebilder (AUS)
    //    $('a.gallery-image').mouseenter(function(){
    //        var oldTop = $(this).position().top;
    //        var oldLeft = $(this).position().left;
    //        var oldHeight = $(this).height();
    //        var oldWidth = $(this).width();
    //
    //        var zoom = $(this).clone().css({
    //            position : 'absolute',
    //            top: oldTop,
    //            left: oldLeft
    //        }).appendTo($(this).parent());
    //        zoom.animate({
    //            width: oldWidth * constants['zoomFactor'],
    //            height: oldHeight * constants['zoomFactor'],
    //            top: oldTop - (oldHeight * (constants['zoomFactor'] - 1) * 0.5),
    //            left: oldLeft - (oldWidth * (constants['zoomFactor'] - 1) * 0.5)
    //        }, 200);
    //        zoom.mouseleave(function(){
    //            $(this).animate({
    //                width: 92,
    //                height: 84,
    //                top: oldTop,
    //                left: oldLeft
    //            }, 200, function(){
    //                $(this).remove()
    //            })
    //        });
    //    });

    //Link-Funktionen
    $('.date-picker a').click(function(event) {
        event.preventDefault();
        jQuery.history.load($(this).attr('href'));
    });

    $('#gallery_overview a').click(function(event) {
        event.preventDefault();
        jQuery.history.load($(this).attr('href'));
    });

    //Galeriebild anzeigen

    /*
    $('a.gallery-image').fancybox({
        'zoomSpeedIn' : 600,
        'zoomSpeedOut' : 500,
        'easingIn' : 'easeOutBack',
        'easingOut' : 'easeInBack',
        'type' : 'image',
    });
    */

    $('a.gallery-image').click(function(e) {
      e.preventDefault();
      var hash = currentURL + "!fancybox" + $(this).attr('href');
      jQuery.history.load(hash);
    });

}

function showNextFlyer() {
    if (current + 1 < count) {
        $('#gallery_overview li').eq(current).stop().animate({
            left : 20
        }, constants['duration']);
        $('#gallery_overview li').eq(current).find('img').stop().animate({
            width : constants['flyerWidth'] / constants['zoomFactor'],
            height : constants['flyerHeight'] / constants['zoomFactor'],
            opacity : 0.4
        }, constants['duration']);

        current++;

        $('#gallery_overview li').eq(current).stop().animate({
            left : (591 / 2) - (constants['flyerWidth'] / 2)
        }, constants['duration']);
        $('#gallery_overview li').eq(current).find('img').stop().animate({
            width : constants['flyerWidth'],
            height : constants['flyerHeight'],
            opacity : 1
        }, constants['duration']);

        $('#gallery_info').fadeOut(400, function() {
            $('#gallery_info_name').html($('#gallery_overview li').eq(current).find('.gallery_name').html());
            $('#gallery_info_date').html($('#gallery_overview li').eq(current).find('.gallery_date').html());
            $('#gallery_info').fadeIn();
        });

        $('#gallery_overview li').css('zIndex', function(index){
            return 100 - Math.abs(current - index);
        });
    }
}

function showPrevFlyer() {
    if (current - 1 >= 0) {
        $('#gallery_overview li').eq(current).stop().animate({
            left : 500
        }, constants['duration']);
        $('#gallery_overview li').eq(current).find('img').stop().animate({
            width : constants['flyerWidth'] / constants['zoomFactor'],
            height : constants['flyerHeight'] / constants['zoomFactor'],
            opacity : 0.4
        }, constants['duration']);

        current--;

        $('#gallery_overview li').eq(current).stop().animate({
            left : (591 / 2) - (constants['flyerWidth'] / 2)
        }, constants['duration']);
        $('#gallery_overview li').eq(current).find('img').stop().animate({
            width : constants['flyerWidth'],
            height : constants['flyerHeight'],
            opacity : 1
        }, constants['duration']);

        $('#gallery_info').fadeOut(400, function() {
            $('#gallery_info_name').html($('#gallery_overview li').eq(current).find('.gallery_name').html());
            $('#gallery_info_date').html($('#gallery_overview li').eq(current).find('.gallery_date').html());
            $('#gallery_info').fadeIn();
        });

        $('#gallery_overview li').css('zIndex', function(index){
            return 100 - Math.abs(current - index);
        });
    }
}



/* Author: Philipp Kreutzer
 * 
 * NAKED JS
*/

var sites
var popup_shown = false;

var currentURL = "";
var galleryIndex = 0;

// TODO: Include Piwik Tracking

// Ensure CSRF Protection for AJAX POST
$(document).ajaxSend(function(event, xhr, settings) {
    function getCookie(name) {
        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;
    }
    function sameOrigin(url) {
        // url could be relative or scheme relative or absolute
        var host = document.location.host; // host + port
        var protocol = document.location.protocol;
        var sr_origin = '//' + host;
        var origin = protocol + sr_origin;
        // Allow absolute or scheme relative URLs to same origin
        return (url == origin || url.slice(0, origin.length + 1) == origin + '/') ||
            (url == sr_origin || url.slice(0, sr_origin.length + 1) == sr_origin + '/') ||
            // or any other URL that isn't scheme relative or absolute i.e relative.
            !(/^(\/\/|http:|https:).*/.test(url));
    }
    function safeMethod(method) {
        return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
    }

    if (!safeMethod(settings.type) && sameOrigin(settings.url)) {
        xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
    }
});


var spinner_image = new Image();
$(spinner_image).attr({
    'src': media_url('img/spinner.gif'),
    'id': 'content_loading',
    'width': '38',
    'height': '38'
}).css({
    'margin-top': '220px'
});

var is_loading = false;

function getRewrittenSite(url){
    url = url.split('?');
    query = url[1];
    url = url[0];
    site = sites["index"];
    if (url != null) {
        var content = url.substr(0, url.length - 5);
        var extension = url.substr(url.length - 4);
        if (extension == "html" && content in sites){
            site = sites[content];
            if(query) {
                site['query'] = query;
            } else {
                site['query'] = '';
            }
        } else {
            site = sites["error"];
        }
    }

    return site;
}

function actualiseForms() {
  return
    $('#content form').each(function() {
        new_site = getRewrittenSite($(this).attr("action"));
        
        var new_url = new_site['filename'];
        //        console.log($(this).attr("action"))
        //        console.log(new_url);
        
        $(this).ajaxForm({
            target: '#content',
            url: new_url,
            success: onContentLoad
        });
    });
}

function flip(image, new_source){
    var wrapper = $(image).parent('a');
    var image_width = $(image).attr('width');

    var reset_css = {}
    reset_css['display'] = wrapper.css('display');
    reset_css['text-align'] = wrapper.css('text-align');
    reset_css['width'] = 'auto';

    wrapper.css({
        'display': 'block',
        'text-align': 'center',
        'width': image_width
    });
    image.css({
        'margin-left': 'auto',
        'margin-right': 'auto',
        'margin-top': '0',
        'margin-bottom': '0'
    });
    $(image).animate({
        width: 0
    }, 'fast', 'easeOutSine', function(){
        $(image).css('opacity', 0);
        $(image).attr('src', new_source);
	$(image).css('opacity', 1);
        $(image).animate({
            width: image_width
        }, 600, 'easeOutBounce', function(){
            wrapper.css(reset_css);
            image.css("display", "inline");
        });
    });
}

function fade(image, new_source){
    var wrapper = $(image).parent('a');
    var image_width = $(image).attr('width');

    var reset_css = {}
    reset_css['background-image'] = 'none';

    wrapper.css({
        'display': 'block',
        'width': image_width,
        'background-image': 'url(' + $(image).attr('src') + ')'
    });

    var new_image = new Image();
    $(new_image).load(function(){
        $(image).remove();
        $(this).hide();
        wrapper.append(this);
        $(this).fadeIn('slow',function(){
            $(wrapper).css(reset_css);
        });
    }).attr('src', new_source);
}


function onContentLoad(){
    actualiseForms();
    
    //initializing Lightbox
    $('a.termin-flyer').fancybox({
        'zoomSpeedIn' : 600,
        'zoomSpeedOut' : 500,
        'type' : 'image',
        'easingIn' : 'easeOutBack',
        'easingOut' : 'easeInBack'
    });

    $('a.termin-flyer[href^="http://www.youtube.com/watch?v="]').click(function() {
        $.fancybox({
            'autoScale'		: false,
            'transitionIn'          : 'none',
            'transitionOut'         : 'none',
            'title'			: this.title,
            'width'                 : 680,
            'height'		: 495,
            'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
            'type'			: 'swf'
        });
        return false;
    });


    $('.termin-event').has('.termin-beschreibung').each(function(index){
        new_id = "termin-beschreibung-" + index;
        $(this).find('h4').first()
        .append(' <a href="#' + new_id + '"><img src="' + media_url('img/icon_info.png') + '" alt="Info" height="15" width="15" /></a>');
        $(this).find('.termin-beschreibung').first().attr('id', new_id);
        $(this).find('h4').first().children("a").fancybox({
            'width' : 400
        });
    });

//    $('a.gallery-image').fancybox({
//        'zoomSpeedIn' : 600,
//        'zoomSpeedOut' : 500,
//        'easingIn' : 'easeOutBack',
//        'easingOut' : 'easeInBack'
//    });

    $('a.internal-link').each(function(){
        $(this).click(function(event){
            event.preventDefault();
            var url = $(this).attr("href");
            jQuery.history.load(url);
        });
    });

    // generate LikeButtons

    $('p.like-button').each(function() {
      var $par = $(this);
      var url = window.location.hash.substr(1);
      if ($par.has('.hash').length) {
        var regex = /([\S]*)!hash:(\S*)|\S*/;
        var result = regex.exec(url);
        if (result[1] != undefined) {
          url = result[1];
        }
        url = url + '!hash:' + $par.children('.hash').text();
      }
      
      getLikeButton($par.children('.title').text(), url, $par.children('.image_url').text(), function(data) {
        $par.replaceWith(data);
      }); 
    });

    //Termin Effects
    $("p.termin-monat-heading")
    .prepend("<image src=\"" + media_url('img/ornament_left.png') + "\" alt=\"\" width=60 height=25 style=\"margin-right: 15px\" />")
    .append("<image src=\"" + media_url('img/ornament_right.png') + "\" alt=\"\" width=60 height=25 style=\"margin-left: 15px\" />");

    //Gallery hiding and Effects
    $('div.gallery a.gallery-heading').click(function(event){
        event.preventDefault();
        if ($(this).next(".gallery-images").length > 0){
            $(this).next(".gallery-images").hide("blind", {}, "slow", function(){
                $(this).prev("a.gallery-heading").children("h2").children("img").attr("src", "images/icon_bt_down.png");
                $('a.gallery-image').fancybox({
                    'zoomSpeedIn' : 600,
                    'zoomSpeedOut' : 500,
                    'easingIn' : 'easeOutBack',
                    'easingOut' : 'easeInBack'
                });
                $(this).remove();
            });
        } else {
            var url = "gallery.php" + $(this).attr('href') + "&images_only=true";
            $(this).children("h2").children("img").attr("src", "images/spinner_small.gif");
            $(this).after("<div class=\"gallery-images\" />")
            .next(".gallery-images").hide()
            .load(url,'',function(){
                $(this).show("blind", {}, "slow", function(){
                    $(this).append("<br style=\"clear:both\" />");
                    $('a.gallery-image').fancybox({
                        'zoomSpeedIn' : 600,
                        'zoomSpeedOut' : 500,
                        'easingIn' : 'easeOutBack',
                        'easingOut' : 'easeInBack'
                    });
                    $(this).prev().children("h2").children("img").attr("src", "images/icon_bt_up.png");
                });
            });
        }
    });

    initGallery();
}

function loadContent(url, anchor, callback) {
  /*
    var google_url = "/" + url;

    url = getRewrittenSite(url);
    var title = "NAKED ESSEN :: " + url['title'];
    var query = url['query']
    url = url['filename'];
    if(query && query != '') {
        url += '?' + query;
    }

    is_loading = true;
    */
    
    if (url == currentURL) {
      if (typeof callback === "function") {
        callback();
      }
      return;
    } else {
      currentURL = url;
    }
    
    $('#content_box').prepend(spinner_image);
	      
    $('#content').slideUp(500, 'swing', function(){
      $.ajax({
	  type: "GET",
	  url: url,
	  success: function(data){
	      var title = data.match(/\<title\>(.*)\<\/title\>/)[1];
          var content = $('#content', data).html();
	      
	      
          var old_button = $("nav ul a img[src*='_down']");
          var new_button = $(anchor).filter("nav ul a").children("img");

          if($(new_button).length == 0) {
            var new_href = url //$(anchor).attr("href");
            if (new_href == "/") {
              new_button = $('nav ul a[href=\''+ new_href + '\']').children("img");
            } else {
              new_button = $('nav ul a[href^=\''+ new_href + '\']').children("img");
            }
          }

          var effect = 'clip';
          var options = {};
          var speed = 'slow';

          if($(old_button).attr("src") != $(new_button).attr("src")) {
              var old_source = $(new_button).attr("src");
              // get image source for new down-button
              if (old_source) {
                  //var new_source = old_source.replace(/(bt_.*)\.png(.*)/,'$1_down.png$2')
                  var imgRegExp = new RegExp('<img.*?alt="' + $(new_button).attr('alt') + '".*?>', "gi")
                  var new_source = $(data.match(imgRegExp)[0]).attr('src');
                  flip(new_button, new_source);
              }

              old_source = $(old_button).attr("src");
              if (old_source) {
                  //new_source = old_source.replace(/(bt_.*)_down\.png(.*)/,'$1.png$2')
                  imgRegExp = new RegExp('<img.*?alt="' + $(old_button).attr('alt') + '".*?>', "gi")
                  new_source = $(data.match(imgRegExp)[0]).attr('src');
                  flip(old_button, new_source);
              }
          } else {
              flip(new_button, $(new_button).attr('src'));
          }
	      
          //alert(content);
	      $('#content').html(content);
          document.title = title;
          
          if (typeof callback === "function") {
            callback();
          }

          // PIWIK
          try {
            piwikTracker.setCustomUrl(url);
            piwikTracker.setDocumentTitle(title);
            piwikTracker.trackPageView();
            piwikTracker.enableLinkTracking();
          }catch(err) {
            //Piwik funktioniert nicht
          }

	      onContentLoad();
	      $('#content_loading').remove();
	      $('#content').slideDown(500, 'swing', 'slow');
	  }
      });
    });
    
}

function getLikeButton(title, url, image, callback) {
  $.post('/fb/like_button/', { title: title, url: url, image_url: image}, callback);
}

$(function(){

    // Animate navigation items
    $('nav ul a').each(function(){
        $(this).click(function(event){
            event.preventDefault();
            var url = $(this).attr("href")
            //loadContent(url, $(this));
            jQuery.history.load(url);
        });
				
        $(this).hover(function(){
            $(this).animate({
                left: "12px"
            }, 200, "swing");
        },
        function(){
            $(this).animate({
                left: "0px"
            }, 400);
        });
    });

    function jump() {
          $(this).animate({
            top: '-35',
          }, 200, 'easeOutSine');
          $(this).animate({
            top: '-25',
          }, 200,'easeInSine', function() {
            $(this).queue(jump);
            $(this).dequeue();
          });
    }

    // Animate Social Button
    $('#social-button').hover(function() {
          $(this).queue(jump);
          $(this).dequeue();
        },
        function() {
          $(this).stop(true, false);
        });

    // initialize jquery history plugin
    $.history.init(function(hash){
        if(hash == "") {
            // initialize your app
            jQuery.history.load('/');
        } else {
            // restore the state from hash
            // first look for fancybox content
            var regex = /([\S]*)!fancybox(\S*)|\S*/;
            var result = regex.exec(hash);
            if (result[1] == undefined){
              var regex = /([\S]*)!hash:(\S*)|\S*/;
              var result = regex.exec(hash);
              if (result[1] == undefined) {
                loadContent(hash);
                $.fancybox.close();
              } else {
                loadContent(result[1], null, function() {
                  console.log('scrolling to ' + result[2]);
                  $.scrollTo('#'+result[2])
                });
                $.fancybox.close();
              }
            } else {
              loadContent(result[1], null, function() {
                // get anchor with specified href
                var anchor = $('a').filter(function() {
                  if($(this).attr('href') == result[2]){
                    return true;
                  } else {
                    return false;
                  }
                });
                if(anchor.length == 1) {
                  //try to get rel attribute to create gallery
                  var rel = anchor.attr('rel');
                  if (rel == "") {
                    $.fancybox({
                        'zoomSpeedIn' : 600,
                        'zoomSpeedOut' : 500,
                        'easingIn' : 'easeOutBack',
                        'easingOut' : 'easeInBack',
                        'type' : 'image',
                        'href' : result[2],
                        'onClosed' : function() {
                          window.location.hash = result[1];
                        },
                    });
                  } else {
                    if (typeof gallery !== "undefined") {
                      var oldIndex = galleryIndex;
                      galleryIndex = gallery.index(anchor);
                      if (oldIndex == galleryIndex) { return; }
                      if (galleryIndex != -1) {
                        $.fancybox.pos(galleryIndex);
                        return;
                      }
                    }
                    gallery = $('a[rel=' + rel + ']');
                    gallery.fancybox({
                        'zoomSpeedIn' : 600,
                        'zoomSpeedOut' : 500,
                        'easingIn' : 'easeOutBack',
                        'easingOut' : 'easeInBack',
                        'type' : 'image',
                        'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
                          return '<p class="like-button"><span class="title">' + title + '</span><span class="image_url">' + $('img#fancybox-img').attr('src') + '</span></p>'
                        },
                        'onComplete' : function(gallery, index, current) {
                          galleryIndex = index;
                          jQuery.history.load(currentURL + '!fancybox' + $(gallery[index]).attr('href'));
                          $('p.like-button').each(function() {
                            var $par = $(this);
                            var url = window.location.hash.substr(1);
                            
                            getLikeButton($par.children('.title').text(), url, $par.children('.image_url').text(), function(data) {
                              $par.replaceWith(data);
                            }); 
                          });
                        },
                        'onClosed' : function() {
                          window.location.hash = result[1];
                          gallery = undefined;
                        },
                    });

                    anchor.trigger('click');
                  }
              }
           });
        }
        }
    },
    { unescape: ",/" });

    onContentLoad();
});

