﻿/* thickbox */
/*
* Thickbox 3 - One Box To Rule Them All.
* By Cody Lindley (http://www.codylindley.com)
* Copyright (c) 2007 cody lindley
* Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
*/

var tb_pathToImage = "/images/loadingAnimation.gif";

eval(function(p, a, c, k, e, r) { e = function(c) { return (c < a ? '' : e(parseInt(c / a))) + ((c = c % a) > 35 ? String.fromCharCode(c + 29) : c.toString(36)) }; if (!''.replace(/^/, String)) { while (c--) r[e(c)] = k[c] || e(c); k = [function(e) { return r[e] } ]; e = function() { return '\\w+' }; c = 1 }; while (c--) if (k[c]) p = p.replace(new RegExp('\\b' + e(c) + '\\b', 'g'), k[c]); return p } ('$(o).2S(9(){1u(\'a.18, 3n.18, 3i.18\');1w=1p 1t();1w.L=2H});9 1u(b){$(b).s(9(){6 t=X.Q||X.1v||M;6 a=X.u||X.23;6 g=X.1N||P;19(t,a,g);X.2E();H P})}9 19(d,f,g){3m{3(2t o.v.J.2i==="2g"){$("v","11").r({A:"28%",z:"28%"});$("11").r("22","2Z");3(o.1Y("1F")===M){$("v").q("<U 5=\'1F\'></U><4 5=\'B\'></4><4 5=\'8\'></4>");$("#B").s(G)}}n{3(o.1Y("B")===M){$("v").q("<4 5=\'B\'></4><4 5=\'8\'></4>");$("#B").s(G)}}3(1K()){$("#B").1J("2B")}n{$("#B").1J("2z")}3(d===M){d=""}$("v").q("<4 5=\'K\'><1I L=\'"+1w.L+"\' /></4>");$(\'#K\').2y();6 h;3(f.O("?")!==-1){h=f.3l(0,f.O("?"))}n{h=f}6 i=/\\.2s$|\\.2q$|\\.2m$|\\.2l$|\\.2k$/;6 j=h.1C().2h(i);3(j==\'.2s\'||j==\'.2q\'||j==\'.2m\'||j==\'.2l\'||j==\'.2k\'){1D="";1G="";14="";1z="";1x="";R="";1n="";1r=P;3(g){E=$("a[@1N="+g+"]").36();25(D=0;((D<E.1c)&&(R===""));D++){6 k=E[D].u.1C().2h(i);3(!(E[D].u==f)){3(1r){1z=E[D].Q;1x=E[D].u;R="<1e 5=\'1X\'>&1d;&1d;<a u=\'#\'>2T &2R;</a></1e>"}n{1D=E[D].Q;1G=E[D].u;14="<1e 5=\'1U\'>&1d;&1d;<a u=\'#\'>&2O; 2N</a></1e>"}}n{1r=1b;1n="1t "+(D+1)+" 2L "+(E.1c)}}}S=1p 1t();S.1g=9(){S.1g=M;6 a=2x();6 x=a[0]-1M;6 y=a[1]-1M;6 b=S.z;6 c=S.A;3(b>x){c=c*(x/b);b=x;3(c>y){b=b*(y/c);c=y}}n 3(c>y){b=b*(y/c);c=y;3(b>x){c=c*(x/b);b=x}}13=b+30;1a=c+2G;$("#8").q("<a u=\'\' 5=\'1L\' Q=\'1o\'><1I 5=\'2F\' L=\'"+f+"\' z=\'"+b+"\' A=\'"+c+"\' 23=\'"+d+"\'/></a>"+"<4 5=\'2D\'>"+d+"<4 5=\'2C\'>"+1n+14+R+"</4></4><4 5=\'2A\'><a u=\'#\' 5=\'Z\' Q=\'1o\'>1l</a> 1k 1j 1s</4>");$("#Z").s(G);3(!(14==="")){9 12(){3($(o).N("s",12)){$(o).N("s",12)}$("#8").C();$("v").q("<4 5=\'8\'></4>");19(1D,1G,g);H P}$("#1U").s(12)}3(!(R==="")){9 1i(){$("#8").C();$("v").q("<4 5=\'8\'></4>");19(1z,1x,g);H P}$("#1X").s(1i)}o.1h=9(e){3(e==M){I=2w.2v}n{I=e.2u}3(I==27){G()}n 3(I==3k){3(!(R=="")){o.1h="";1i()}}n 3(I==3j){3(!(14=="")){o.1h="";12()}}};16();$("#K").C();$("#1L").s(G);$("#8").r({Y:"T"})};S.L=f}n{6 l=f.2r(/^[^\\?]+\\??/,\'\');6 m=2p(l);13=(m[\'z\']*1)+30||3h;1a=(m[\'A\']*1)+3g||3f;W=13-30;V=1a-3e;3(f.O(\'2j\')!=-1){1E=f.1B(\'3d\');$("#15").C();3(m[\'1A\']!="1b"){$("#8").q("<4 5=\'2f\'><4 5=\'1H\'>"+d+"</4><4 5=\'2e\'><a u=\'#\' 5=\'Z\' Q=\'1o\'>1l</a> 1k 1j 1s</4></4><U 1W=\'0\' 2d=\'0\' L=\'"+1E[0]+"\' 5=\'15\' 1v=\'15"+1f.2c(1f.1y()*2b)+"\' 1g=\'1m()\' J=\'z:"+(W+29)+"p;A:"+(V+17)+"p;\' > </U>")}n{$("#B").N();$("#8").q("<U 1W=\'0\' 2d=\'0\' L=\'"+1E[0]+"\' 5=\'15\' 1v=\'15"+1f.2c(1f.1y()*2b)+"\' 1g=\'1m()\' J=\'z:"+(W+29)+"p;A:"+(V+17)+"p;\'> </U>")}}n{3($("#8").r("Y")!="T"){3(m[\'1A\']!="1b"){$("#8").q("<4 5=\'2f\'><4 5=\'1H\'>"+d+"</4><4 5=\'2e\'><a u=\'#\' 5=\'Z\'>1l</a> 1k 1j 1s</4></4><4 5=\'F\' J=\'z:"+W+"p;A:"+V+"p\'></4>")}n{$("#B").N();$("#8").q("<4 5=\'F\' 3c=\'3b\' J=\'z:"+W+"p;A:"+V+"p;\'></4>")}}n{$("#F")[0].J.z=W+"p";$("#F")[0].J.A=V+"p";$("#F")[0].3a=0;$("#1H").11(d)}}$("#Z").s(G);3(f.O(\'37\')!=-1){$("#F").q($(\'#\'+m[\'26\']).1T());$("#8").24(9(){$(\'#\'+m[\'26\']).q($("#F").1T())});16();$("#K").C();$("#8").r({Y:"T"})}n 3(f.O(\'2j\')!=-1){16();3($.1q.35){$("#K").C();$("#8").r({Y:"T"})}}n{$("#F").34(f+="&1y="+(1p 33().32()),9(){16();$("#K").C();1u("#F a.18");$("#8").r({Y:"T"})})}}3(!m[\'1A\']){o.21=9(e){3(e==M){I=2w.2v}n{I=e.2u}3(I==27){G()}}}}31(e){}}9 1m(){$("#K").C();$("#8").r({Y:"T"})}9 G(){$("#2Y").N("s");$("#Z").N("s");$("#8").2X("2W",9(){$(\'#8,#B,#1F\').2V("24").N().C()});$("#K").C();3(2t o.v.J.2i=="2g"){$("v","11").r({A:"1Z",z:"1Z"});$("11").r("22","")}o.1h="";o.21="";H P}9 16(){$("#8").r({2U:\'-\'+20((13/2),10)+\'p\',z:13+\'p\'});3(!(1V.1q.2Q&&1V.1q.2P<7)){$("#8").r({38:\'-\'+20((1a/2),10)+\'p\'})}}9 2p(a){6 b={};3(!a){H b}6 c=a.1B(/[;&]/);25(6 i=0;i<c.1c;i++){6 d=c[i].1B(\'=\');3(!d||d.1c!=2){39}6 e=2a(d[0]);6 f=2a(d[1]);f=f.2r(/\\+/g,\' \');b[e]=f}H b}9 2x(){6 a=o.2M;6 w=1S.2o||1R.2o||(a&&a.1Q)||o.v.1Q;6 h=1S.1P||1R.1P||(a&&a.2n)||o.v.2n;1O=[w,h];H 1O}9 1K(){6 a=2K.2J.1C();3(a.O(\'2I\')!=-1&&a.O(\'3o\')!=-1){H 1b}}', 62, 211, '|||if|div|id|var||TB_window|function||||||||||||||else|document|px|append|css|click||href|body||||width|height|TB_overlay|remove|TB_Counter|TB_TempArray|TB_ajaxContent|tb_remove|return|keycode|style|TB_load|src|null|unbind|indexOf|false|title|TB_NextHTML|imgPreloader|block|iframe|ajaxContentH|ajaxContentW|this|display|TB_closeWindowButton||html|goPrev|TB_WIDTH|TB_PrevHTML|TB_iframeContent|tb_position||thickbox|tb_show|TB_HEIGHT|true|length|nbsp|span|Math|onload|onkeydown|goNext|Esc|or|close|tb_showIframe|TB_imageCount|Close|new|browser|TB_FoundURL|Key|Image|tb_init|name|imgLoader|TB_NextURL|random|TB_NextCaption|modal|split|toLowerCase|TB_PrevCaption|urlNoQuery|TB_HideSelect|TB_PrevURL|TB_ajaxWindowTitle|img|addClass|tb_detectMacXFF|TB_ImageOff|150|rel|arrayPageSize|innerHeight|clientWidth|self|window|children|TB_prev|jQuery|frameborder|TB_next|getElementById|auto|parseInt|onkeyup|overflow|alt|unload|for|inlineId||100||unescape|1000|round|hspace|TB_closeAjaxWindow|TB_title|undefined|match|maxHeight|TB_iframe|bmp|gif|png|clientHeight|innerWidth|tb_parseQuery|jpeg|replace|jpg|typeof|which|keyCode|event|tb_getPageSize|show|TB_overlayBG|TB_closeWindow|TB_overlayMacFFBGHack|TB_secondLine|TB_caption|blur|TB_Image|60|tb_pathToImage|mac|userAgent|navigator|of|documentElement|Prev|lt|version|msie|gt|ready|Next|marginLeft|trigger|fast|fadeOut|TB_imageOff|hidden||catch|getTime|Date|load|safari|get|TB_inline|marginTop|continue|scrollTop|TB_modal|class|TB_|45|440|40|630|input|188|190|substr|try|area|firefox'.split('|'), 0, {}));

/* jquery ui stars */
/*
* jQuery UI Stars v3.0.1
* http://plugins.jquery.com/project/Star_Rating_widget
*
* Copyright (c) 2010 Marek "Orkan" Zajac (orkans@gmail.com)
* Dual licensed under the MIT and GPL licenses.
* http://docs.jquery.com/License
*
* $Rev: 164 $
* $Date:: 2010-05-01 #$
* $Build: 35 (2010-05-01)
*
* Depends:
*	jquery.ui.core.js
*	jquery.ui.widget.js
*
*/
/*!
* jQuery UI Stars v3.0.1
* http://plugins.jquery.com/project/Star_Rating_widget
*
* Copyright (c) 2010 Marek "Orkan" Zajac (orkans@gmail.com)
* Dual licensed under the MIT and GPL licenses.
* http://docs.jquery.com/License
*
* $Rev: 164 $
* $Date:: 2010-05-01 #$
* $Build: 35 (2010-05-01)
*
* Depends:
*	jquery.ui.core.js
*	jquery.ui.widget.js
*
*/
(function($) {

    $.widget('ui.stars', {
        options: {
            inputType: 'radio', // [radio|select]
            split: 0, // decrease number of stars by splitting each star into pieces [2|3|4|...]
            disabled: false, // set to [true] to make the stars initially disabled
            cancelTitle: 'Cancel Rating',
            cancelValue: 0, // default value of Cancel btn.
            cancelShow: true,
            disableValue: true, // set to [false] to not disable the hidden input when Cancel btn is clicked, so the value will present in POST data.
            oneVoteOnly: false,
            showTitles: false,
            captionEl: null, // jQuery object - target for text captions 
            callback: null, // function(ui, type, value, event)

            /*
            * CSS classes
            */
            starWidth: 16, // width of the star image
            cancelClass: 'ui-stars-cancel',
            starClass: 'ui-stars-star',
            starOnClass: 'ui-stars-star-on',
            starHoverClass: 'ui-stars-star-hover',
            starDisabledClass: 'ui-stars-star-disabled',
            cancelHoverClass: 'ui-stars-cancel-hover',
            cancelDisabledClass: 'ui-stars-cancel-disabled'
        },

        _create: function() {
            var self = this, o = this.options, starId = 0;
            this.element.data('former.stars', this.element.html());

            o.isSelect = o.inputType == 'select';
            this.$form = $(this.element).closest('form');
            this.$selec = o.isSelect ? $('select', this.element) : null;
            this.$rboxs = o.isSelect ? $('option', this.$selec) : $(':radio', this.element);

            /*
            * Map all inputs from $rboxs array to Stars elements
            */
            this.$stars = this.$rboxs.map(function(i) {
                var el = {
                    value: this.value,
                    title: (o.isSelect ? this.text : this.title) || this.value,
                    isDefault: (o.isSelect && this.defaultSelected) || this.defaultChecked
                };

                if (i == 0) {
                    o.split = typeof o.split != 'number' ? 0 : o.split;
                    o.val2id = [];
                    o.id2val = [];
                    o.id2title = [];
                    o.name = o.isSelect ? self.$selec.get(0).name : this.name;
                    o.disabled = o.disabled || (o.isSelect ? $(self.$selec).attr('disabled') : $(this).attr('disabled'));
                }

                /*
                * Consider it as a Cancel button?
                */
                if (el.value == o.cancelValue) {
                    o.cancelTitle = el.title;
                    return null;
                }

                o.val2id[el.value] = starId;
                o.id2val[starId] = el.value;
                o.id2title[starId] = el.title;

                if (el.isDefault) {
                    o.checked = starId;
                    o.value = o.defaultValue = el.value;
                    o.title = el.title;
                }

                var $s = $('<div/>').addClass(o.starClass);
                var $a = $('<a/>').attr('title', o.showTitles ? el.title : '').text(el.value);

                /*
                * Prepare division settings
                */
                if (o.split) {
                    var oddeven = (starId % o.split);
                    var stwidth = Math.floor(o.starWidth / o.split);
                    $s.width(stwidth);
                    $a.css('margin-left', '-' + (oddeven * stwidth) + 'px');
                }

                starId++;
                return $s.append($a).get(0);
            });

            /*
            * How many Stars?
            */
            o.items = starId;

            /*
            * Remove old content
            */
            o.isSelect ? this.$selec.remove() : this.$rboxs.remove();

            /*
            * Append Stars interface
            */
            this.$cancel = $('<div/>').addClass(o.cancelClass).append($('<a/>').attr('title', o.showTitles ? o.cancelTitle : '').text(o.cancelValue));
            o.cancelShow &= !o.disabled && !o.oneVoteOnly;
            o.cancelShow && this.element.append(this.$cancel);
            this.element.append(this.$stars);

            /*
            * Initial selection
            */
            if (o.checked === undefined) {
                o.checked = -1;
                o.value = o.defaultValue = o.cancelValue;
                o.title = '';
            }

            /*
            * The only FORM element, that has been linked to the stars control. The value field is updated on each Star click event
            */
            this.$value = $("<input type='hidden' name='" + o.name + "' value='" + o.value + "' />");
            this.element.append(this.$value);


            /*
            * Attach stars event handler
            */
            this.$stars.bind('click.stars', function(e) {
                if (!o.forceSelect && o.disabled) return false;

                var i = self.$stars.index(this);
                o.checked = i;
                o.value = o.id2val[i];
                o.title = o.id2title[i];
                self.$value.attr({ disabled: o.disabled ? 'disabled' : '', value: o.value });

                fillTo(i, false);
                self._disableCancel();

                !o.forceSelect && self.callback(e, 'star');
            })
		.bind('mouseover.stars', function() {
		    if (o.disabled) return false;
		    var i = self.$stars.index(this);
		    fillTo(i, true);
		})
		.bind('mouseout.stars', function() {
		    if (o.disabled) return false;
		    fillTo(self.options.checked, false);
		});


            /*
            * Attach cancel event handler
            */
            this.$cancel.bind('click.stars', function(e) {
                if (!o.forceSelect && (o.disabled || o.value == o.cancelValue)) return false;

                o.checked = -1;
                o.value = o.cancelValue;
                o.title = '';

                self.$value.val(o.value);
                o.disableValue && self.$value.attr({ disabled: 'disabled' });

                fillNone();
                self._disableCancel();

                !o.forceSelect && self.callback(e, 'cancel');
            })
		.bind('mouseover.stars', function() {
		    if (self._disableCancel()) return false;
		    self.$cancel.addClass(o.cancelHoverClass);
		    fillNone();
		    self._showCap(o.cancelTitle);
		})
		.bind('mouseout.stars', function() {
		    if (self._disableCancel()) return false;
		    self.$cancel.removeClass(o.cancelHoverClass);
		    self.$stars.triggerHandler('mouseout.stars');
		});


            /*
            * Attach onReset event handler to the parent FORM
            */
            this.$form.bind('reset.stars', function() {
                !o.disabled && self.select(o.defaultValue);
            });


            /*
            * Clean up to avoid memory leaks in certain versions of IE 6
            */
            $(window).unload(function() {
                self.$cancel.unbind('.stars');
                self.$stars.unbind('.stars');
                self.$form.unbind('.stars');
                self.$selec = self.$rboxs = self.$stars = self.$value = self.$cancel = self.$form = null;
            });


            /*
            * Star selection helpers
            */
            function fillTo(index, hover) {
                if (index != -1) {
                    var addClass = hover ? o.starHoverClass : o.starOnClass;
                    var remClass = hover ? o.starOnClass : o.starHoverClass;
                    self.$stars.eq(index).prevAll('.' + o.starClass).andSelf().removeClass(remClass).addClass(addClass);
                    self.$stars.eq(index).nextAll('.' + o.starClass).removeClass(o.starHoverClass + ' ' + o.starOnClass);
                    self._showCap(o.id2title[index]);
                }
                else fillNone();
            };
            function fillNone() {
                self.$stars.removeClass(o.starOnClass + ' ' + o.starHoverClass);
                self._showCap('');
            };


            /*
            * Finally, set up the Stars
            */
            this.select(o.value);
            o.disabled && this.disable();

        },

        /*
        * Private functions
        */
        _disableCancel: function() {
            var o = this.options, disabled = o.disabled || o.oneVoteOnly || (o.value == o.cancelValue);
            if (disabled) this.$cancel.removeClass(o.cancelHoverClass).addClass(o.cancelDisabledClass);
            else this.$cancel.removeClass(o.cancelDisabledClass);
            this.$cancel.css('opacity', disabled ? 0.5 : 1);
            return disabled;
        },
        _disableAll: function() {
            var o = this.options;
            this._disableCancel();
            if (o.disabled) this.$stars.filter('div').addClass(o.starDisabledClass);
            else this.$stars.filter('div').removeClass(o.starDisabledClass);
        },
        _showCap: function(s) {
            var o = this.options;
            if (o.captionEl) o.captionEl.text(s);
        },

        /*
        * Public functions
        */
        value: function() {
            return this.options.value;
        },
        select: function(val) {
            var o = this.options, e = (val == o.cancelValue) ? this.$cancel : this.$stars.eq(o.val2id[val]);
            o.forceSelect = true;
            e.triggerHandler('click.stars');
            o.forceSelect = false;
        },
        selectID: function(id) {
            var o = this.options, e = (id == -1) ? this.$cancel : this.$stars.eq(id);
            o.forceSelect = true;
            e.triggerHandler('click.stars');
            o.forceSelect = false;
        },
        enable: function() {
            this.options.disabled = false;
            this._disableAll();
        },
        disable: function() {
            this.options.disabled = true;
            this._disableAll();
        },
        destroy: function() {
            this.$form.unbind('.stars');
            this.$cancel.unbind('.stars').remove();
            this.$stars.unbind('.stars').remove();
            this.$value.remove();
            this.element.unbind('.stars').html(this.element.data('former.stars')).removeData('stars');
            return this;
        },
        callback: function(e, type) {
            var o = this.options;
            o.callback && o.callback(this, type, o.value, e);
            o.oneVoteOnly && !o.disabled && this.disable();
        }
    });

    $.extend($.ui.stars, {
        version: '3.0.1'
    });

})(jQuery);


/* jquery treeview */
/*
* Treeview 1.4 - jQuery plugin to hide and show branches of a tree
* 
* http://bassistance.de/jquery-plugins/jquery-plugin-treeview/
* http://docs.jquery.com/Plugins/Treeview
*
* Copyright (c) 2007 Jörn Zaefferer
*
* Dual licensed under the MIT and GPL licenses:
*   http://www.opensource.org/licenses/mit-license.php
*   http://www.gnu.org/licenses/gpl.html
*
* Revision: $Id: jquery.treeview.js 4684 2008-02-07 19:08:06Z joern.zaefferer $
*
*/
; (function($) {

    $.extend($.fn, {
        swapClass: function(c1, c2) {
            var c1Elements = this.filter('.' + c1);
            this.filter('.' + c2).removeClass(c2).addClass(c1);
            c1Elements.removeClass(c1).addClass(c2);
            return this;
        },
        replaceClass: function(c1, c2) {
            return this.filter('.' + c1).removeClass(c1).addClass(c2).end();
        },
        hoverClass: function(className) {
            className = className || "hover";
            return this.hover(function() {
                $(this).addClass(className);
            }, function() {
                $(this).removeClass(className);
            });
        },
        heightToggle: function(animated, callback) {
            animated ?
				this.animate({ height: "toggle" }, animated, callback) :
				this.each(function() {
				    jQuery(this)[jQuery(this).is(":hidden") ? "show" : "hide"]();
				    if (callback)
				        callback.apply(this, arguments);
				});
        },
        heightHide: function(animated, callback) {
            if (animated) {
                this.animate({ height: "hide" }, animated, callback);
            } else {
                this.hide();
                if (callback)
                    this.each(callback);
            }
        },
        prepareBranches: function(settings) {
            if (!settings.prerendered) {
                // mark last tree items
                this.filter(":last-child:not(ul)").addClass(CLASSES.last);
                // collapse whole tree, or only those marked as closed, anyway except those marked as open
                this.filter((settings.collapsed ? "" : "." + CLASSES.closed) + ":not(." + CLASSES.open + ")").find(">ul").hide();
            }
            // return all items with sublists
            return this.filter(":has(>ul)");
        },
        applyClasses: function(settings, toggler) {
            this.filter(":has(>ul):not(:has(>a))").find(">span").click(function(event) {
                toggler.apply($(this).next());
            }).add($("a", this)).hoverClass();

            if (!settings.prerendered) {
                // handle closed ones first
                this.filter(":has(>ul:hidden)")
						.addClass(CLASSES.expandable)
						.replaceClass(CLASSES.last, CLASSES.lastExpandable);

                // handle open ones
                this.not(":has(>ul:hidden)")
						.addClass(CLASSES.collapsable)
						.replaceClass(CLASSES.last, CLASSES.lastCollapsable);

                // create hitarea
                this.prepend("<div class=\"" + CLASSES.hitarea + "\"/>").find("div." + CLASSES.hitarea).each(function() {
                    var classes = "";
                    $.each($(this).parent().attr("class").split(" "), function() {
                        classes += this + "-hitarea ";
                    });
                    $(this).addClass(classes);
                });
            }

            // apply event to hitarea
            this.find("div." + CLASSES.hitarea).click(toggler);
        },
        treeview: function(settings) {

            settings = $.extend({
                cookieId: "treeview"
            }, settings);

            if (settings.add) {
                return this.trigger("add", [settings.add]);
            }

            if (settings.toggle) {
                var callback = settings.toggle;
                settings.toggle = function() {
                    return callback.apply($(this).parent()[0], arguments);
                };
            }

            // factory for treecontroller
            function treeController(tree, control) {
                // factory for click handlers
                function handler(filter) {
                    return function() {
                        // reuse toggle event handler, applying the elements to toggle
                        // start searching for all hitareas
                        toggler.apply($("div." + CLASSES.hitarea, tree).filter(function() {
                            // for plain toggle, no filter is provided, otherwise we need to check the parent element
                            return filter ? $(this).parent("." + filter).length : true;
                        }));
                        return false;
                    };
                }
                // click on first element to collapse tree
                $("a:eq(0)", control).click(handler(CLASSES.collapsable));
                // click on second to expand tree
                $("a:eq(1)", control).click(handler(CLASSES.expandable));
                // click on third to toggle tree
                $("a:eq(2)", control).click(handler());
            }

            // handle toggle event
            function toggler() {
                $(this)
					.parent()
                // swap classes for hitarea
					.find(">.hitarea")
						.swapClass(CLASSES.collapsableHitarea, CLASSES.expandableHitarea)
						.swapClass(CLASSES.lastCollapsableHitarea, CLASSES.lastExpandableHitarea)
					.end()
                // swap classes for parent li
					.swapClass(CLASSES.collapsable, CLASSES.expandable)
					.swapClass(CLASSES.lastCollapsable, CLASSES.lastExpandable)
                // find child lists
					.find(">ul")
                // toggle them
					.heightToggle(settings.animated, settings.toggle);
                if (settings.unique) {
                    $(this).parent()
						.siblings()
                    // swap classes for hitarea
						.find(">.hitarea")
							.replaceClass(CLASSES.collapsableHitarea, CLASSES.expandableHitarea)
							.replaceClass(CLASSES.lastCollapsableHitarea, CLASSES.lastExpandableHitarea)
						.end()
						.replaceClass(CLASSES.collapsable, CLASSES.expandable)
						.replaceClass(CLASSES.lastCollapsable, CLASSES.lastExpandable)
						.find(">ul")
						.heightHide(settings.animated, settings.toggle);
                }
            }

            function serialize() {
                function binary(arg) {
                    return arg ? 1 : 0;
                }
                var data = [];
                branches.each(function(i, e) {
                    data[i] = $(e).is(":has(>ul:visible)") ? 1 : 0;
                });
                $.cookie(settings.cookieId, data.join(""));
            }

            function deserialize() {
                var stored = $.cookie(settings.cookieId);
                if (stored) {
                    var data = stored.split("");
                    branches.each(function(i, e) {
                        $(e).find(">ul")[parseInt(data[i]) ? "show" : "hide"]();
                    });
                }
            }

            // add treeview class to activate styles
            this.addClass("treeview");

            // prepare branches and find all tree items with child lists
            var branches = this.find("li").prepareBranches(settings);

            switch (settings.persist) {
                case "cookie":
                    var toggleCallback = settings.toggle;
                    settings.toggle = function() {
                        serialize();
                        if (toggleCallback) {
                            toggleCallback.apply(this, arguments);
                        }
                    };
                    deserialize();
                    break;
                case "location":
                    var current = this.find("a").filter(function() { return this.href.toLowerCase() == location.href.toLowerCase(); });
                    if (current.length) {
                        current.addClass("selected").parents("ul, li").add(current.next()).show();
                    }
                    break;
            }

            branches.applyClasses(settings, toggler);

            // if control option is set, create the treecontroller and show it
            if (settings.control) {
                treeController(this, settings.control);
                $(settings.control).show();
            }

            return this.bind("add", function(event, branches) {
                $(branches).prev()
					.removeClass(CLASSES.last)
					.removeClass(CLASSES.lastCollapsable)
					.removeClass(CLASSES.lastExpandable)
				.find(">.hitarea")
					.removeClass(CLASSES.lastCollapsableHitarea)
					.removeClass(CLASSES.lastExpandableHitarea);
                $(branches).find("li").andSelf().prepareBranches(settings).applyClasses(settings, toggler);
            });
        }
    });

    // classes used by the plugin
    // need to be styled via external stylesheet, see first example
    var CLASSES = $.fn.treeview.classes = {
        open: "open",
        closed: "closed",
        expandable: "expandable",
        expandableHitarea: "expandable-hitarea",
        lastExpandableHitarea: "lastExpandable-hitarea",
        collapsable: "collapsable",
        collapsableHitarea: "collapsable-hitarea",
        lastCollapsableHitarea: "lastCollapsable-hitarea",
        lastCollapsable: "lastCollapsable",
        lastExpandable: "lastExpandable",
        last: "last",
        hitarea: "hitarea"
    };

    // provide backwards compability
    $.fn.Treeview = $.fn.treeview;

})(jQuery);

/* main */
$(document).ready(function() {
    $("#ulCategories").treeview({ animated: "fast", collapsed: true, unique: true, persist: "location" });
    
    $('.rating').children(':first-child').stars({
        inputType: "select",
        cancelShow: false,
        callback: function(ui, type, value) {
            var parent = ui.element.parent();
            var orgvalue = ui.$selec.attr('orgvalue');
            $(parent).find('.ratinguser').hide();
            $(parent).find('input[type=hidden]').val(value);
            $(parent).find('.ratingbutton').click();
            setTimeout('$("#' + $(parent).children(':first-child').attr('id') + '").stars("select", ' + orgvalue + ');', 2000);
        }
    });

    $('.writecommentlink').click(function(ev) {
        $('.writecomment').slideDown(600);
        ev.preventDefault();
    });

    $("a[sharewith]").click(function(ev) {
        var rel = $(this).attr("sharewith");
        var url = encodeURIComponent(self.location.href);
        var title = encodeURIComponent($("title:first").html());
        rel = rel.replace("{u}", url);
        rel = rel.replace("{t}", title);
        self.location.href = rel;
        return false;
    });
});

function submitSnippet() {
    var Msg = $('.chattextbox').val();
    $.ajax({
        url: '/chat/process?op=add&msg=' + escape(Msg), cache: false,
        success: function(data) {
            loadConversation(0);
        }
    });

    $('.chattextbox').val("");
}

function loadConversation(allMsgs) {
    $.ajax({
        url: '/chat/process?op=get&all=' + allMsgs, cache: false,
        success: function(data) {
            var Snip = data;
            Snip = Snip.split('<br/>');

            for (var i = 0; i < Snip.length; i++) {
                var Snippet = Snip[i];
                if (Snippet.indexOf('###disable###') != -1) {
                    $('.groovybutton').attr('disabled', 'disabled');
                    $('.chattextbox').attr('disabled', 'disabled');
                    Snippet = Snippet.replace(/###disable###/gi, '');
                    Snippet = Snippet.replace(/###disable###/gi, '');
                }
                if (Snippet.indexOf('###enable###') != -1) {
                    $('.groovybutton').removeAttr('disabled');
                    $('.chattextbox').removeAttr('disabled');
                    Snippet = Snippet.replace(/###enable###/gi, '');
                    Snippet = Snippet.replace(/###enable###/gi, '');
                }
                if (Snippet.indexOf('###newchat###') != -1) {
                    Snippet = Snippet.replace(/###newchat###/gi, '&nbsp;&nbsp;&nbsp;<input type="button" class="groovybutton" onclick="javascript:window.location.href=\'/chat/room?new=1\'" value="Start New Chat"/>');
                }
                if (Snippet.indexOf('###overwrite###') == -1)
                    $('.chatbox').append(Snippet);
                else {
                    Snippet = Snippet.replace(/###overwrite###/gi, '');
                    $('.chatbox').html(Snippet);
                }
                
                if (Snippet != '')
                    $('.chatbox').append('<br/>');
            }

            $('.chattextbox').unbind('keypress');
            $('.chattextbox').keypress(function(e) {
                if (e.keyCode == 13) {
                    submitSnippet();
                    e.preventDefault();
                    return false;
                }
            });

            $('.chatbox').animate({ scrollTop: $('.chatbox')[0].scrollHeight });
            $('.chattextbox').focus();
            window.setTimeout('loadConversation(0);', 5000);
        }
    });
}

function setCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function getCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}

