/* =========================================================

// jquery.innerfade.js

// Datum: 2008-02-14
// Firma: Medienfreunde Hofmann & Baldes GbR
// Author: Torsten Baldes
// Mail: t.baldes@medienfreunde.com
// Web: http://medienfreunde.com

// based on the work of Matt Oakes http://portfolio.gizone.co.uk/applications/slideshow/
// and Ralf S. Engelschall http://trainofthoughts.org/

// ========================================================= */
function facebookAuth() {
	window.location = "/register/facebook";
}
function validate_async(form, cb) {
	var illegalChars = /\W/; // allow letters, numbers, and underscores
	if (illegalChars.test(form.username)) {
        cb({username: 'Enkel letters, cijfers en underscores toegelaten'});
    }
	else {
	  $.getJSON('http://www.partyindustries.be/register/username/' + form.username + '&callback=?', 
		function(response) {
	      if (response.error) {
	        // Username isn't taken, let the form submit
	        cb();
	      }
		  cb({username: 'Deze gebruikersnaam is al bezet'});
		});
	}
}

/*
--------------------------------
Infinite Scroll
--------------------------------
+ https://github.com/paulirish/infinitescroll
+ version 2.0b2.110713
+ Copyright 2011 Paul Irish & Luke Shumard
+ Licensed under the MIT license

+ Documentation: http://infinite-scroll.com/

*/

(function (window, $, undefined) {

	$.infinitescroll = function infscr(options, callback, element) {

		this.element = $(element);
		this._create(options, callback);

	};

	$.infinitescroll.defaults = {
		loading: {
			finished: undefined,
			finishedMsg: "<br /><em>Proficiat, je hebt het einde bereikt!</em>",
			img: "http://s1.partyindustries.be/img/ajax-loader.gif",
			msg: null,
			msgText: "<em>Volgende reeks ophalen...</em>",
			selector: null,
			speed: 'fast',
			start: undefined
		},
		state: {
			isDuringAjax: false,
			isInvalidPage: false,
			isDestroyed: false,
			isDone: false, // For when it goes all the way through the archive.
			isPaused: false,
			currPage: 1
		},
		callback: undefined,
		debug: false,
		behavior: undefined,
		binder: $(window), // used to cache the selector
		nextSelector: "div.navigation a:first",
		navSelector: "div.navigation",
		contentSelector: null, // rename to pageFragment
		extraScrollPx: 150,
		itemSelector: "div.post",
		animate: false,
		pathParse: undefined,
		dataType: 'html',
		appendCallback: true,
		bufferPx: 40,
		errorCallback: function () { },
		infid: 0, //Instance ID
		pixelsFromNavToBottom: undefined,
		path: undefined
	};


    $.infinitescroll.prototype = {

        /*	
        ----------------------------
        Private methods
        ----------------------------
        */

        // Bind or unbind from scroll
        _binding: function infscr_binding(binding) {

            var instance = this,
				opts = instance.options;

            // if behavior is defined and this function is extended, call that instead of default
			if (!!opts.behavior && this['_binding_'+opts.behavior] !== undefined) {
				this['_binding_'+opts.behavior].call(this);
				return;
			}

			if (binding !== 'bind' && binding !== 'unbind') {
                this._debug('Binding value  ' + binding + ' not valid')
                return false;
            }

            if (binding == 'unbind') {

                (this.options.binder).unbind('smartscroll.infscr.' + instance.options.infid);

            } else {

                (this.options.binder)[binding]('smartscroll.infscr.' + instance.options.infid, function () {
                    instance.scroll();
                });

            };

            this._debug('Binding', binding);

        },

		// Fundamental aspects of the plugin are initialized
		_create: function infscr_create(options, callback) {

            // If selectors from options aren't valid, return false
            if (!this._validate(options)) { return false; }
            // Define options and shorthand
            var opts = this.options = $.extend(true, {}, $.infinitescroll.defaults, options),
				// get the relative URL - everything past the domain name.
				relurl = /(.*?\/\/).*?(\/.*)/,
				path = $(opts.nextSelector).attr('href');

            // contentSelector is 'page fragment' option for .load() / .ajax() calls
            opts.contentSelector = opts.contentSelector || this.element;

            // loading.selector - if we want to place the load message in a specific selector, defaulted to the contentSelector
            opts.loading.selector = opts.loading.selector || opts.contentSelector;

            // if there's not path, return
            if (!path) { this._debug('Navigation selector not found'); return; }

            // Set the path to be a relative URL from root.
            opts.path = this._determinepath(path);

            // Define loading.msg
            opts.loading.msg = $('<div id="infscr-loading"><img alt="Loading..." src="' + opts.loading.img + '" /><div>' + opts.loading.msgText + '</div></div>');

            // Preload loading.img
            (new Image()).src = opts.loading.img;

            // distance from nav links to bottom
            // computed as: height of the document + top offset of container - top offset of nav link
            opts.pixelsFromNavToBottom = $(document).height() - $(opts.navSelector).offset().top;

			// determine loading.start actions
            opts.loading.start = opts.loading.start || function() {

				$(opts.navSelector).hide();
				opts.loading.msg
					.appendTo(opts.loading.selector)
					.show(opts.loading.speed, function () {
	                	beginAjax(opts);
	            });
			};

			// determine loading.finished actions
			opts.loading.finished = opts.loading.finished || function() {
				opts.loading.msg.fadeOut('normal');
			};

            // callback loading
            opts.callback = function(instance,data) {
				if (!!opts.behavior && instance['_callback_'+opts.behavior] !== undefined) {
					instance['_callback_'+opts.behavior].call($(opts.contentSelector)[0], data);
				}
				if (callback) {
					callback.call($(opts.contentSelector)[0], data);
				}
			};

            this._setup();

        },

        // Console log wrapper
        _debug: function infscr_debug() {

			if (this.options.debug) {
                return window.console && console.log.call(console, arguments);
            }

        },

        // find the number to increment in the path.
        _determinepath: function infscr_determinepath(path) {

            var opts = this.options;

			// if behavior is defined and this function is extended, call that instead of default
			if (!!opts.behavior && this['_determinepath_'+opts.behavior] !== undefined) {
				this['_determinepath_'+opts.behavior].call(this,path);
				return;
			}

            if (!!opts.pathParse) {

                this._debug('pathParse manual');
                return opts.pathParse;

            } else {

                // page= is used in drupal too but second page is page=1 not page=2:
                // thx Jerod Fritz, vladikoff
                if (path.match(/^(.*)1(-page)/)) {
                    path = path.match(/^(.*)1(-page)/).slice(1);
                    return path;
                }
                if (path.match(/^(.*)([0-9]+)(-page)/)) {
                    path = path.match(/^(.*)([0-9]+)(-page)/).slice(1);
                    //opts.state.currPage = path.substr(path.indexOf(','),path.indexOf(',', path.indexOf(',') +1)) + ',-page';
                    //path = path.substr(0,path.indexOf(',')) + ",-page";
                    opts.state.currPage = path[1];
                    path.splice(1, 1);
                    return path;
                } else {
                    this._debug('Sorry, we couldn\'t parse your Next (Previous Posts) URL. Verify your the css selector points to the correct A tag. If you still get this error: yell, scream, and kindly ask for help at infinite-scroll.com.');
                    // Get rid of isInvalidPage to allow permalink to state
                    opts.state.isInvalidPage = true;  //prevent it from running on this page.
                }
            }
            this._debug('determinePath', path);
            return path;

        },

        // Custom error
        _error: function infscr_error(xhr) {

            var opts = this.options;

			// if behavior is defined and this function is extended, call that instead of default
			if (!!opts.behavior && this['_error_'+opts.behavior] !== undefined) {
				this['_error_'+opts.behavior].call(this,xhr);
				return;
			}

            if (xhr !== 'destroy' && xhr !== 'end') {
                xhr = 'unknown';
            }

            this._debug('Error', xhr);

            if (xhr == 'end') {
                this._showdonemsg();
            }

            opts.state.isDone = true;
            opts.state.currPage = 1; // if you need to go back to this instance
            opts.state.isPaused = false;
            this._binding('unbind');

        },

        // Load Callback
        _loadcallback: function infscr_loadcallback(box, data) {

            var opts = this.options,
	    		callback = this.options.callback, // GLOBAL OBJECT FOR CALLBACK
	    		result = (opts.state.isDone) ? 'done' : (!opts.appendCallback) ? 'no-append' : 'append',
	    		frag;

			// if behavior is defined and this function is extended, call that instead of default
			if (!!opts.behavior && this['_loadcallback_'+opts.behavior] !== undefined) {
				this['_loadcallback_'+opts.behavior].call(this,box,data);
				return;
			}

            switch (result) {

                case 'done':

                    this._showdonemsg();
                    return false;

                    break;

                case 'no-append':

                    if (opts.dataType == 'html') {
                        data = '<div>' + data + '</div>';
                        data = $(data).find(opts.itemSelector);
                    };

                    break;

                case 'append':

                    var children = box.children();

                    // if it didn't return anything
                    if (children.length == 0) {
                        return this._error('end');
                    }


                    // use a documentFragment because it works when content is going into a table or UL
                    frag = document.createDocumentFragment();
                    while (box[0].firstChild) {
                        frag.appendChild(box[0].firstChild);
                    }

                    this._debug('contentSelector', $(opts.contentSelector)[0])
                    $(opts.contentSelector)[0].appendChild(frag);
                    // previously, we would pass in the new DOM element as context for the callback
                    // however we're now using a documentfragment, which doesnt havent parents or children,
                    // so the context is the contentContainer guy, and we pass in an array
                    //   of the elements collected as the first argument.

                    data = children.get();


                    break;

            }

            // loadingEnd function
			opts.loading.finished.call($(opts.contentSelector)[0],opts)
            

            // smooth scroll to ease in the new content
            if (opts.animate) {
                var scrollTo = $(window).scrollTop() + $('#infscr-loading').height() + opts.extraScrollPx + 'px';
                $('html,body').animate({ scrollTop: scrollTo }, 800, function () { opts.state.isDuringAjax = false; });
            }

            if (!opts.animate) opts.state.isDuringAjax = false; // once the call is done, we can allow it again.

            callback(this,data);

        },

        _nearbottom: function infscr_nearbottom() {

            var opts = this.options,
	        	pixelsFromWindowBottomToBottom = 0 + $(document).height() - (opts.binder.scrollTop()) - $(window).height();

            // if behavior is defined and this function is extended, call that instead of default
			if (!!opts.behavior && this['_nearbottom_'+opts.behavior] !== undefined) {
				this['_nearbottom_'+opts.behavior].call(this);
				return;
			}

			this._debug('math:', pixelsFromWindowBottomToBottom, opts.pixelsFromNavToBottom);

            // if distance remaining in the scroll (including buffer) is less than the orignal nav to bottom....
            return (pixelsFromWindowBottomToBottom - opts.bufferPx < opts.pixelsFromNavToBottom);

        },

		// Pause / temporarily disable plugin from firing
        _pausing: function infscr_pausing(pause) {

            var opts = this.options;

            // if behavior is defined and this function is extended, call that instead of default
			if (!!opts.behavior && this['_pausing_'+opts.behavior] !== undefined) {
				this['_pausing_'+opts.behavior].call(this,pause);
				return;
			}

			// If pause is not 'pause' or 'resume', toggle it's value
            if (pause !== 'pause' && pause !== 'resume' && pause !== null) {
                this._debug('Invalid argument. Toggling pause value instead');
            };

            pause = (pause && (pause == 'pause' || pause == 'resume')) ? pause : 'toggle';

            switch (pause) {
                case 'pause':
                    opts.state.isPaused = true;
                    break;

                case 'resume':
                    opts.state.isPaused = false;
                    break;

                case 'toggle':
                    opts.state.isPaused = !opts.state.isPaused;
                    break;
            }

            this._debug('Paused', opts.state.isPaused);
            return false;

        },

		// Behavior is determined
		// If the behavior option is undefined, it will set to default and bind to scroll
		_setup: function infscr_setup() {

			var opts = this.options;

			// if behavior is defined and this function is extended, call that instead of default
			if (!!opts.behavior && this['_setup_'+opts.behavior] !== undefined) {
				this['_setup_'+opts.behavior].call(this);
				return;
			}

			this._binding('bind');

			return false;

		},

        // Show done message
        _showdonemsg: function infscr_showdonemsg() {

            var opts = this.options;

			// if behavior is defined and this function is extended, call that instead of default
			if (!!opts.behavior && this['_showdonemsg_'+opts.behavior] !== undefined) {
				this['_showdonemsg_'+opts.behavior].call(this);
				return;
			}

            opts.loading.msg
	    		.find('img')
	    		.hide()
	    		.parent()
	    		.find('div').html(opts.loading.finishedMsg).animate({ opacity: 1 }, 5000, function () {
	    		    $(this).parent().fadeOut('normal');
	    		});

            // user provided callback when done    
            opts.errorCallback.call($(opts.contentSelector)[0],'done');

        },

		// grab each selector option and see if any fail
        _validate: function infscr_validate(opts) {

            for (var key in opts) {
                if (key.indexOf && key.indexOf('Selector') > -1 && $(opts[key]).length === 0) {
                    this._debug('Your ' + key + ' found no elements.');
                    return false;
                }
                return true;
            }

        },

        /*	
        ----------------------------
        Public methods
        ----------------------------
        */

		// Bind to scroll
		bind: function infscr_bind() {
			this._binding('bind');
		},

        // Destroy current instance of plugin
        destroy: function infscr_destroy() {

            this.options.state.isDestroyed = true;
            return this._error('destroy');

        },

		// Set pause value to false
		pause: function infscr_pause() {
			this._pausing('pause');
		},

		// Set pause value to false
		resume: function infscr_resume() {
			this._pausing('resume');
		},

        // Retrieve next set of content items
        retrieve: function infscr_retrieve(pageNum) {

            var instance = this,
				opts = instance.options,
				path = opts.path,
				box, frag, desturl, method, condition,
	    		pageNum = pageNum || null,
				getPage = (!!pageNum) ? pageNum : opts.state.currPage;
				beginAjax = function infscr_ajax(opts) {

					

	                instance._debug('heading into ajax', path);

	                // if we're dealing with a table we can't use DIVs
	                box = $(opts.contentSelector).is('table') ? $('<tbody/>') : $('<div/>');

	                desturl = path.join(opts.state.currPage);
	                
	             // increment the URL bit. e.g. /page/3/
	                opts.state.currPage++;
	                
	             
					
					

	                method = (opts.dataType == 'html' || opts.dataType == 'json') ? opts.dataType : 'html+callback';
	                if (opts.appendCallback && opts.dataType == 'html') method += '+callback'

	                switch (method) {

	                    case 'html+callback':

	                        instance._debug('Using HTML via .load() method');
	                        box.load(desturl + ' ' + opts.itemSelector, null, function infscr_ajax_callback(responseText) {
	                            instance._loadcallback(box, responseText);
	                        });

	                        break;

	                    case 'html':
	                    case 'json':

	                        instance._debug('Using ' + (method.toUpperCase()) + ' via $.ajax() method');
	                        $.ajax({
	                            // params
	                            url: desturl,
	                            dataType: opts.dataType,
	                            complete: function infscr_ajax_callback(jqXHR, textStatus) {
	                                condition = (typeof (jqXHR.isResolved) !== 'undefined') ? (jqXHR.isResolved()) : (textStatus === "success" || textStatus === "notmodified");
	                                (condition) ? instance._loadcallback(box, jqXHR.responseText) : instance._error('end');
	                            }
	                        });

	                        break;
	                }
	                if(!opts.state.isDone) {
	                	// SEO URL
	                	var thispager = getPage;
	                	thispager--;
	 	               var hashe=path.join(thispager);//window.location.hash;
	 		            var id=hashe.substring(1);
	 		            if (typeof(window.history.pushState) == 'function'){
	 		                window.history.pushState(null,id,hashe);
	 		            } else {
	 		                window.location.hash = '#!'+hashe;
	 		            }
	                	
	                }
				};

			// if behavior is defined and this function is extended, call that instead of default
			if (!!opts.behavior && this['retrieve_'+opts.behavior] !== undefined) {
				this['retrieve_'+opts.behavior].call(this,pageNum);
				return;
			}

            
			// for manual triggers, if destroyed, get out of here
			if (opts.state.isDestroyed) {
                this._debug('Instance is destroyed');
                return false;
            };

            // we dont want to fire the ajax multiple times
            opts.state.isDuringAjax = true;

            opts.loading.start.call($(opts.contentSelector)[0],opts);

        },

        // Check to see next page is needed
        scroll: function infscr_scroll() {

            var opts = this.options,
				state = opts.state;

            // if behavior is defined and this function is extended, call that instead of default
			if (!!opts.behavior && this['scroll_'+opts.behavior] !== undefined) {
				this['scroll_'+opts.behavior].call(this);
				return;
			}

			if (state.isDuringAjax || state.isInvalidPage || state.isDone || state.isDestroyed || state.isPaused) return;

            if (!this._nearbottom()) return;

            this.retrieve();

        },

		// Toggle pause value
		toggle: function infscr_toggle() {
			this._pausing();
		},

		// Unbind from scroll
		unbind: function infscr_unbind() {
			this._binding('unbind');
		},

		// update options
		update: function infscr_options(key) {
			if ($.isPlainObject(key)) {
				this.options = $.extend(true,this.options,key);
			}
		}

    }


    /*	
    ----------------------------
    Infinite Scroll function
    ----------------------------
	
    Borrowed logic from the following...
	
    jQuery UI
    - https://github.com/jquery/jquery-ui/blob/master/ui/jquery.ui.widget.js
	
    jCarousel
    - https://github.com/jsor/jcarousel/blob/master/lib/jquery.jcarousel.js
	
    Masonry
    - https://github.com/desandro/masonry/blob/master/jquery.masonry.js		
	
    */

    $.fn.infinitescroll = function infscr_init(options, callback) {


        var thisCall = typeof options;

        switch (thisCall) {

            // method 
            case 'string':

                var args = Array.prototype.slice.call(arguments, 1);

                this.each(function () {

                    var instance = $.data(this, 'infinitescroll');

                    if (!instance) {
                        // not setup yet
                        // return $.error('Method ' + options + ' cannot be called until Infinite Scroll is setup');
						return false;
                    }
                    if (!$.isFunction(instance[options]) || options.charAt(0) === "_") {
                        // return $.error('No such method ' + options + ' for Infinite Scroll');
						return false;
                    }

                    // no errors!
                    instance[options].apply(instance, args);

                });

                break;

            // creation 
            case 'object':

                this.each(function () {

                    var instance = $.data(this, 'infinitescroll');

                    if (instance) {

                        // update options of current instance
                        instance.update(options);

                    } else {

                        // initialize new instance
                        $.data(this, 'infinitescroll', new $.infinitescroll(options, callback, this));

                    }

                });

                break;

        }

        return this;

    };



    /* 
    * smartscroll: debounced scroll event for jQuery *
    * https://github.com/lukeshumard/smartscroll
    * Based on smartresize by @louis_remi: https://github.com/lrbabe/jquery.smartresize.js *
    * Copyright 2011 Louis-Remi & Luke Shumard * Licensed under the MIT license. *
    */

    var event = $.event,
		scrollTimeout;

    event.special.smartscroll = {
        setup: function () {
            $(this).bind("scroll", event.special.smartscroll.handler);
        },
        teardown: function () {
            $(this).unbind("scroll", event.special.smartscroll.handler);
        },
        handler: function (event, execAsap) {
            // Save the context
            var context = this,
		      args = arguments;

            // set correct event type
            event.type = "smartscroll";

            if (scrollTimeout) { clearTimeout(scrollTimeout); }
            scrollTimeout = setTimeout(function () {
                $.event.handle.apply(context, args);
            }, execAsap === "execAsap" ? 0 : 100);
        }
    };

    $.fn.smartscroll = function (fn) {
        return fn ? this.bind("smartscroll", fn) : this.trigger("smartscroll", ["execAsap"]);
    };


})(window, jQuery);


(function($) {

	$.fn.innerfade = function(options) {
		return this.each(function() {
			$.innerfade(this, options);
		});
	};

	$.innerfade = function(container, options) {
		var settings = {
			'animationtype' : 'fade',
			'speed' : 'normal',
			'type' : 'sequence',
			'timeout' : 2000,
			'containerheight' : 'auto',
			'runningclass' : 'innerfade',
			'children' : null
		};
		if (options)
			$.extend(settings, options);
		if (settings.children === null)
			var elements = $(container).children();
		else
			var elements = $(container).children(settings.children);
		if (elements.length > 1) {
			$(container).css('position', 'relative').css('height',
					settings.containerheight).addClass(settings.runningclass);
			for ( var i = 0; i < elements.length; i++) {
				$(elements[i]).css('z-index', String(elements.length - i)).css(
						'position', 'absolute').hide();
			}
			;
			if (settings.type == "sequence") {
				setTimeout(function() {
					$.innerfade.next(elements, settings, 1, 0);
				}, settings.timeout);
				$(elements[0]).show();
			} else if (settings.type == "random") {
				var last = Math.floor(Math.random() * (elements.length));
				setTimeout(
						function() {
							do {
								current = Math.floor(Math.random()
										* (elements.length));
							} while (last == current);
							$.innerfade.next(elements, settings, current, last);
						}, settings.timeout);
				$(elements[last]).show();
			} else if (settings.type == 'random_start') {
				settings.type = 'sequence';
				var current = Math.floor(Math.random() * (elements.length));
				setTimeout(function() {
					$.innerfade.next(elements, settings, (current + 1)
							% elements.length, current);
				}, settings.timeout);
				$(elements[current]).show();
			} else {
				alert('Innerfade-Type must either be \'sequence\', \'random\' or \'random_start\'');
			}
		}
	};

	$.innerfade.next = function(elements, settings, current, last) {
		if (settings.animationtype == 'slide') {
			$(elements[last]).slideUp(settings.speed);
			$(elements[current]).slideDown(settings.speed);
		} else if (settings.animationtype == 'fade') {
			$(elements[last]).fadeOut(settings.speed);
			$(elements[current]).fadeIn(settings.speed, function() {
				removeFilter($(this)[0]);
			});
		} else
			alert('Innerfade-animationtype must either be \'slide\' or \'fade\'');
		if (settings.type == "sequence") {
			if ((current + 1) < elements.length) {
				current = current + 1;
				last = current - 1;
			} else {
				current = 0;
				last = elements.length - 1;
			}
		} else if (settings.type == "random") {
			last = current;
			while (current == last)
				current = Math.floor(Math.random() * elements.length);
		} else
			alert('Innerfade-Type must either be \'sequence\', \'random\' or \'random_start\'');
		setTimeout((function() {
			$.innerfade.next(elements, settings, current, last);
		}), settings.timeout);
	};

})(jQuery);

// **** remove Opacity-Filter in ie ****
function removeFilter(element) {
	if (element.style.removeAttribute) {
		element.style.removeAttribute('filter');
	}
}

/*
 * Auto Expanding Text Area (1.2.2) by Chrys Bader (www.chrysbader.com)
 * chrysb@gmail.com
 * 
 * Version 1.2.3 update by Richard Vallee richardvallee@gmail.com
 * 
 * Special thanks to: Jake Chapa - jake@hybridstudio.com John Resig -
 * jeresig@gmail.com
 * 
 * Copyright (c) 2008 Chrys Bader (www.chrysbader.com) Licensed under the GPL
 * (GPL-LICENSE.txt) license.
 * 
 * 
 * NOTE: This script requires jQuery to work. Download jQuery at www.jquery.com
 * 
 */

(function(jQuery) {

	var self = null;

	jQuery.fn.autogrow = function(o) {
		return this.each(function() {
			new jQuery.autogrow(this, o);
		});
	};

	/**
	 * The autogrow object.
	 * 
	 * @constructor
	 * @name jQuery.autogrow
	 * @param Object
	 *            e The textarea to create the autogrow for.
	 * @param Hash
	 *            o A set of key/value pairs to set as configuration properties.
	 * @cat Plugins/autogrow
	 */

	jQuery.autogrow = function(e, o) {
		this.options = o || {};
		this.dummy = null;
		this.interval = null;
		this.line_height = this.options.lineHeight
				|| parseInt(jQuery(e).css('line-height'));
		this.min_height = this.options.minHeight
				|| parseInt(jQuery(e).css('min-height'));
		this.max_height = this.options.maxHeight
				|| parseInt(jQuery(e).css('max-height'));
		;
		this.textarea = jQuery(e);
		this.expand_tolerance = (!isNaN(this.options.expandTolerance) && this.options.expandTolerance > 0) ? this.options.expandTolerance
				: 4;

		if (isNaN(this.line_height))
			this.line_height = 0;

		// Only one textarea activated at a time, the one being used
		this.init();
	};

	jQuery.autogrow.fn = jQuery.autogrow.prototype = {
		autogrow : '1.2.3'
	};

	jQuery.autogrow.fn.extend = jQuery.autogrow.extend = jQuery.extend;

	jQuery.autogrow.fn
			.extend( {
				init : function() {
					var self = this;
					this.textarea.css( {
						overflow : 'hidden',
						display : 'block'
					});
					this.textarea.bind('focus', function() {
						self.startExpand()
					}).bind('blur', function() {
						self.stopExpand()
					});
					this.checkExpand();
				},

				startExpand : function() {
					var self = this;
					this.interval = window.setInterval(function() {
						self.checkExpand()
					}, 400);
				},

				stopExpand : function() {
					clearInterval(this.interval);
				},

				checkExpand : function() {
					if (this.dummy == null) {
						this.dummy = jQuery('<div></div>');
						this.dummy.css( {
							'font-size' : this.textarea.css('font-size'),
							'font-family' : this.textarea.css('font-family'),
							'width' : this.textarea.css('width'),
							'padding' : this.textarea.css('padding'),
							'line-height' : this.line_height + 'px',
							'overflow-x' : 'hidden',
							'position' : 'absolute',
							'top' : 0,
							'left' : -9999
						}).appendTo('body');
					} else {
						// If the dummy was already created, show it as it is
						// hidden after expansion
						this.dummy.show();
					}

					// Strip HTML tags
					var html = this.textarea.val().replace(/(<|>)/g, '');

					// IE is different, as per usual
					if (jQuery.browser.msie) {
						html = html.replace(/\n/g, '<BR/>new');
					} else {
						html = html.replace(/\n/g, '<br/>new');
					}

					if (this.dummy.html() != html) {
						this.dummy.html(html);
						if (this.max_height > 0
								&& (this.dummy.height()
										+ (this.expand_tolerance * this.line_height) > this.max_height)) {
							this.textarea.css('overflow-y', 'auto');
							if (this.textarea.height() < this.max_height) {
								this.textarea
										.animate(
												{
													height : (this.max_height + (this.expand_tolerance * this.line_height)) + 'px'
												}, 100);
							}
						} else {
							this.textarea.css('overflow-y', 'hidden');
							if (this.textarea.height() < this.dummy.height()
									+ (this.expand_tolerance * this.line_height)
									|| (this.dummy.height() < this.textarea
											.height())) {
								if (this.dummy.height() < this.min_height) {
									this.textarea
											.animate(
													{
														height : (this.min_height + (this.expand_tolerance * this.line_height)) + 'px'
													}, 100);
								} else {
									this.textarea
											.animate(
													{
														height : (this.dummy
																.height() + (this.expand_tolerance * this.line_height)) + 'px'
													}, 100);
								}
							}
						}
					}

					// Hide the dummy, as otherwise it overflows the body when
					// the content is long
					this.dummy.hide();
				}

			});
})(jQuery);

$(document).ready(function() {
	    jQuery(window).scroll(function () {  
	        var scrll = jQuery(document).scrollTop();
			if (scrll > 280) {
				var cssObj = {
				  'position' : 'fixed',
				  'top' : '10px'
				}
				jQuery(".fixedSidebar").css(cssObj);
			} else if (scrll <= 280) {
				var cssObj = {
				  'position' : 'relative'
				}
				jQuery(".fixedSidebar").css(cssObj);
			}
	    });  

	if($('.pagination').length > 0) {
		$('#pagingDiv').infinitescroll({
	
			navSelector  	: ".pagination",
			nextSelector 	: "#next-page",
			itemSelector 	: "#pagingDiv"
		});
	}


			// PAGING
				$(".pagerPic")
						.click(
								function() {
									var myLoc = $(this).attr('href').toString();
									var myLoc2 = myLoc.replace(/#foto/, '');

									$("#pagingDiv").html(
											"<br /><br /><br /><br />");
									$("#pagingDiv").addClass("lbLoading");
									$("#pagingDiv")
											.load(
													myLoc2,
													function() {
														$
																.getScript("http://www.partyindustries.be/js/jquery.plugins.js");
														$("#pagingDiv")
																.removeClass(
																		"lbLoading");
													});
									var hashe=$(this).attr('href');//window.location.hash;
						            var id=hashe.substring(1);
						            if (typeof(window.history.pushState) == 'function'){
						                window.history.pushState(null,id,hashe);
						            } else {
						                window.location.hash = '#!'+hashe;
						            }
									return false;
								});

				// PAGING
				$(".pager")
						.click(
								function() {
									var myLoc = $(this).attr('href').toString();
									var myLoc2 = myLoc.replace(/#foto/, '');

									$("#pagingDiv").html(
											"<br /><br /><br /><br />");
									$("#pagingDiv").addClass("lbLoading");
									$("#pagingDiv")
											.load(
													myLoc2,
													function() {
														$
																.getScript("http://www.partyindustries.be/js/jquery.plugins.js");
														$("#pagingDiv")
																.removeClass(
																		"lbLoading");
													});
								
									var hashe=$(this).attr('href');//window.location.hash;
						            var id=hashe.substring(1);
						            if (typeof(window.history.pushState) == 'function'){
						                window.history.pushState(null,id,hashe);
						            } else {
						                window.location.hash = '#!'+hashe;
						            }
						            
									return false;
								});

				$(document)
						.keydown(
								function(e) {
									var keyCode = e.keyCode || e.which, arrow = {
										left : 37,
										up : 38,
										right : 39,
										down : 40
									};

									switch (keyCode) {
									case arrow.left:
										var myLoc = $("#picPrev").attr('href')
												.toString();
										var myLoc2 = myLoc.replace(/#foto/, '');

										$("#pagingDiv").html(
												"<br /><br /><br /><br />");
										$("#pagingDiv").addClass("lbLoading");
										$("#pagingDiv")
												.load(
														myLoc2,
														function() {
															$
																	.getScript("http://www.partyindustries.be/js/jquery.plugins.js");
															$("#pagingDiv")
																	.removeClass(
																			"lbLoading");
														});

							            var id=myLoc.substring(1);
							            if (typeof(window.history.pushState) == 'function'){
							                window.history.pushState(null,id,myLoc);
							            } else {
							                window.location.hash = '#!'+myLoc;
							            }
							            
										return false;
										break;
									case arrow.right:
									case arrow.left:
										var myLoc = $("#picNext").attr('href')
												.toString();
										var myLoc2 = myLoc.replace(/#foto/, '');

										$("#pagingDiv").html(
												"<br /><br /><br /><br />");
										$("#pagingDiv").addClass("lbLoading");
										$("#pagingDiv")
												.load(
														myLoc2,
														function() {
															$
																	.getScript("http://www.partyindustries.be/js/jquery.plugins.js");
															$("#pagingDiv")
																	.removeClass(
																			"lbLoading");
														});

							            var id=myLoc.substring(1);
							            if (typeof(window.history.pushState) == 'function'){
							                window.history.pushState(null,id,myLoc);
							            } else {
							                window.location.hash = '#!'+myLoc;
							            }
							            
										return false;
										break;
									}
								});

				// EXPANDABLE TEXTAREA
				$('textarea').autogrow( {
					minHeight : 50,
					lineHeight : 17
				});

				// LINKS
				$('#content a, #sitemap a, #copyright a').click(
						function() {
							if (document.images) {
								(new Image()).src = "/links/aid="
										+ $(this).attr('title') + "&loc="
										+ document.location + "&url="
										+ $(this).attr('href');
							}
						});

				$('.slide').innerfade( {
					animationtype : 'slide',
					speed : 750,
					timeout : 5000,
					type : 'sequence',
					containerheight : '100px'
				});
				$('.fade').innerfade( {
					speed : 'slow',
					timeout : 4000,
					type : 'sequence',
					containerheight : '200px'
				});
				$('.fadeAanraders').innerfade( {
					speed : 'slow',
					timeout : 4000,
					type : 'sequence',
					containerheight : '120px'
				});
				$('.fadeNewsTicker').innerfade( {
					speed : 'slow',
					timeout : 4000,
					type : 'sequence',
					containerheight : '14px'
				});
				$('.fadeMov').innerfade( {
					speed : 'slow',
					timeout : 4000,
					type : 'sequence',
					containerheight : '130px'
				});
				$('.fadeCal').innerfade( {
					animationtype : 'slide',
					speed : 750,
					timeout : 5000,
					type : 'random',
					containerheight : '83px'
				});

				$("div#searchBar").slideUp("fast");
				$("#searchButton").click(function() {
					// if($("div#mainMenu").find("div#searchBar:hidden")){$("div#searchBar").slideDown("slow");}
						// else{$("div#searchBar").slideUp("slow");}

						if ($("div#searchBar").is(":visible")) {
							$("div#searchBar").slideUp("slow");
						} else {
							$("div#searchBar").slideDown("slow");
						}
					});
				
});

