function d(){
    if ( window.console !== undefined && window.console !== null && window.DEBUG )
            console.debug(arguments); 
}
function ok( arg ){ return arg !== undefined && arg !== null; }
var ddd = d;

$( function() {
    
    $.ajaxSetup( { cache: false } );
    
    function ok( arg ) {
        return arg !== undefined && arg !== null;
    }
    
    function empty( arg ) {
        return ! ok( arg ) || arg == "";
    }
    
    window.$FANCYBOX_DEFAULT = {
        overlayShow: true,
        zoomSpeedIn: 300,
        overlayOpacity: 0.7,
        hideOnContentClick: false,
        centerOnScroll: false,
        padding: 10,
        callbackOnShow: function() {
            
            // redirect
            var $redirect = $( '#fancy_content input[name=redirect]' );
            if ( $redirect.length > 0 ) {
                setTimeout( function() {
                    var redirect = $redirect.val() == 'self'
                        ? document.location.pathname + document.location.search
                        : $redirect.val()
                    ;
                    if ( ! redirect.match( /^(http:\/\/|\/)/ ) ) redirect = "/"+ redirect; 
                    document.location = redirect;
                }, 500 );
                return ;
            }
            
            // having reload content ?
            $load = $( '#fancy_content input[name=load_content]' );
            if ( $load.length > 0 )
                $.reload_content( $load.val() );
            
            // setup form, if any
            $( '#fancy_content .form' ).init_content().init_form();
        },
        callbackOnClose: function() {
            $( window ).trigger( 'fancybox_closed' );
            $( '#flash_player' ).remove();
        }
    };
    
    window.$BT_OPTIONS = {
        fill: '#f22662',
        strokeStyle: '#fff',
        strokeWidth: 0,
        cssStyles: {
            background: 'url(/img/highlight-red.gif) center left repeat-x'
        },
        positions: [ 'top' ],
        cornerRadius: 0,
        /* hoverIntentOpts: {
            interval: 500,
            timeout: 500
        }, */
        showTip: function(box){
            var $content = $('.bt-content', box).hide(); /* hide the content until after the animation */
            var $canvas = $('canvas', box).hide(); /* hide the canvas for a moment */
            var origWidth = $canvas[0].width; /* jQuery's .width() doesn't work on canvas element */
            var origHeight = $canvas[0].height;
            $(box).show(); /* show the wrapper, however elements inside (canvas, content) are now hidden */
            
            $canvas
                .css({
                    width: origWidth * .5,
                    height: origHeight * .5,
                    left: origWidth * .25,
                    top: origHeight * .25,
                    opacity: .1
                })
                .show()
                .animate({
                    width: origWidth,
                    height: origHeight,
                    left: 0,
                    top: 0,
                    opacity: 1
                }, 400, 'easeOutBounce',
                    function(){$content.show()} /* show the content when animation is done */
                );
        },
        /* when using hideTip, do NOT forget 'callback' at end of animation */
        hideTip: function(box, callback){
            var $content = $('.bt-content', box).hide();
            var $canvas = $('canvas', box);
            var origWidth = $canvas[0].width;
            var origHeight = $canvas[0].height;
            $canvas
              .animate({width: origWidth * .5, height: origHeight * .5, left: origWidth * .25, top: origHeight * .25, opacity: 0}, 400, 'swing', callback); /* callback */
        }
    };
    
    
    $.extend( {
        
        open_fancybox: function( url, args ) {
            if ( !ok(args) ) args = {};
            var a = $( '<a style="display:none" href="'+ url + '">X</a>' ).appendTo( 'body' ).fancybox( $.extend( {}, $FANCYBOX_DEFAULT, {
                retreiveMethod: 'post'
            }, args ) ).click();
        },
        
        
        init_video_player: function( args ) {
        
            var player_specs = {
                time: 0,
                position: 0,
                playitem: [],
                infocache: [],
                quality: {
                    low: 200,
                    normal: 1500,
                    high: 2400
                }
            };
            var playlist_url = ( '/video/playlist/'+ args.return_path+ '.xml' ).replace( /\/\//, '/' );
            
            // print the flash
            swfobject.embedSWF( '/swf/flvplayer.3.11.hacked.6.swf', 'player', args.width, args.height, '9.0.124', false, { // flashvars
                file: playlist_url,
                lightcolor: '0xf00046',
                backcolor: '0x000000',
                frontcolor: '0xffffff',
                showfsbutton: "true",
                enablejs: 'true',
                bufferlength: 2,
                repeat: 'list',
                shuffle: 'false',
                thumbsinplaylist: 'false',
                bwfile: '/img/100k.jpg',
                bwstreams: '200,1500'+ ( args.high_quality ? ',2400' : '' )
                /* ,
                overstretch: 'false' */
            }, { // params
                allowscriptaccess: 'always',
                allowfullscreen:   'true'
            }, { // html attributes
                id:   'flash_player',
                name: 'flash_player'
            } );
            var player = $( '#flash_player' ).get(0);
            
            
            // set the listener method for the player events
            var playlist;
            window.getUpdate = function( type, val1, val2 ) {
                // timing event -> remmeber position in time
                if ( type == 'time' )
                    player_specs.time = val1;
                
                // item event -> remember position in playlist
                else if ( type == 'item' ) {
                    player_specs.item = val1;
                    
                    // show the links, swap the title, toggle the HQ button
                    var show_info = function( html ) {
                        $( '#media_info' ).after( html ).remove();
                        var $parent = $( '#flash_player' ).parents( '.form' ); 
                        $parent.find( 'h1' ).text( $( '#media_info' ).find( 'input[name=title]' ).val() );
                        var has_high_quality = $( '#media_info' ).find( 'input[name=has_high_quality]' ).val() == '1';
                        $parent.find( '#player_control .high' )[ has_high_quality ? 'show' : 'hide' ](); 
                    };
                    
                    // load info (links, title and such)
                    if ( ok( player_specs.playitem[ val1 ] ) ) {
                        var cache = player_specs.infocache[ val1 ];
                        if ( ! ok( cache ) ) {
                            $.get( '/video/info/'+ player_specs.playitem[ val1 ], function( html ) {
                                $( '#media_id' ).val( player_specs.playitem[ val1 ] );
                                player_specs.infocache[ val1 ] = html;
                                show_info( html );
                            } );
                        } 
                        else show_info( cache );
                    }
                }
            };
            
            
            
            // call the player safely .. try again while not yet loaded ..
            var player_send = function( name, value ) {
                var tries = 0, send = 0, send_ok = $.browser.msie ? 2  : 1;
                var test  = setInterval( function() {
                    try {
                        player.sendEvent( name, value );
                        send++;
                    }
                    catch(e) { tries++; }
                    if ( tries > 30 || send >= send_ok ) clearInterval( test );
                }, 300 );
            };
            window.PLAYER =  player;
            window.PLAYER_SPEC = player_specs;
            
            // bind the quality control buttons
            $( '#player_control a' ).click( function() {
                var quality = $( this ).attr( 'hash' ).replace( /^\#/, '' );
                $( '#quality_high,#quality_low,#quality_normal' ).removeClass( 'selected' );
                $( '#quality_'+ quality ).addClass( 'selected' ); 
                player.setBW( player_specs.quality[ quality ] );
                player_send( 'scrub', player_specs.time );
            } );
            
            // read the playitem and bind the trigger
            /* $( '#player_control .playitem' ).each( function( idx ) {
                player_specs.playitem[ idx ] = $( this ).val();
            } ); */
            player_specs.playitem = $( '#player_control #playitems' ).val().split( /,/ );
            
            // start up and play conditions
            setTimeout( function() {
                player_send( 'playitem', args.start_at );
            }, 300 );
        },
        
        
        reload_content: function( content ) {
            var all = content.split( /\s*\^\s*/ );
            $( all ).each( function() {
                var c = this.split( /\s*;\s*/ );
                $.get( c[1], function( data ) {
                    var $content = $( data );
                    $( '#content_'+ c[0] ).after( $content ).remove();
                    $content.init_content().init_form();
                    setTimeout( function(){
                        $content.animate( { opacity: '0.5' }, function() {
                            $( this ).animate( { opacity: '1.0' } );
                        } );
                    }, 1500 );
                    
                } );
            } );
        }
        
    } );
    
    
    $.fn.extend( {
        
        
        /* get_form_data
            read all input elements from a form and return them as hash
        */
        get_form_data: function() {
            var data = {}, checkbox_seen = {}, hidden_seen = {};
            $( 'input,select,textarea', this ).not( '[disabled=disabled],[name=]' ).each( function() {
                var name = $( this ).attr( 'name' ),
                    value = $( this ).val(),
                    type = $( this ).attr( 'type' ),
                    nn = $( this ).attr( 'nodeName' ).toLowerCase(),
                    id = $( this ).attr( 'id' )
                ;
                
                // inputs need special care
                if ( nn == 'input' ) {
                    var c = $( this ).attr( 'checked' );
                    
                    // ignore unchecked radios
                    if ( type == 'radio' && ! c ) return;
                    
                    // checkboxes ..
                    else if ( type == 'checkbox' ) {
                        
                        // having hidden data (aka default, unchecked) -> remove
                        if ( ok( hidden_seen[ name ] ) )
                            delete data[ name ];
                        
                        checkbox_seen[ name ] = true;
                        if ( c )
                            value = 1;
                        else
                            value = 0;
                    }
                    
                    // remeber seen hidden
                    else if ( type == 'hidden' && ok( id ) && id.match( /_$/ ) ) {
                        hidden_seen[ name ] = true;
                        if ( checkbox_seen[ name ] )
                            return;
                    }
                }
                else if ( nn == 'textarea' ) {
                    var rel = $( this ).attr( 'rel' );
                    if ( rel == value ) value = '';
                }
                else if ( nn == 'select' && $( this ).attr( 'multiple' ) ) {
                    var val = [];
                    if ( $( this ).hasClass( 'all-checked' ) )
                        $( 'option', this ).each( function() {
                            val.push( $( this ).val() );
                        } );
                    else
                        $( 'option', this ).each( function() {
                            if ( $( this ).attr( 'selected' ) )
                                val.push( $( this ).val() );
                        } );
                    
                    value = val;
                }
                
                
                // work on native array values
                if ( name.match( /^(.*?)\[\]$/ ) ) {
                    name = RegExp.$1;
                    if ( ok( data[ name ] ) ) {
                        if ( data[ name ] instanceof Array )
                            data[ name ].push( value );
                        else 
                            data[ name ] = [ data[ name ], value ];
                    }
                    else
                        data[ name ] = value;
                }
                
                // not new data (array)
                else if ( ok( data[ name ] ) ) {
                    // make array and add
                    if ( data[ name ] instanceof Array )
                        data[ name ].push( value );
                    else data[ name ] = [ data[ name ], value ];
                }
                
                // new data (scalar)
                else
                    data[ name ] = value;
            } );
            for ( s in data )
                if ( data[ s ] instanceof Array ) {
                    data[ s+ '[]' ] = data[ s ];
                    delete data[ s ]
                }
            return data;
        },
        
        
        /* bind_only
            assure that is bound only once!
        */
        bind_only: function( name, event, fnct ) {
            return $( this ).each( function() {
                var only = event+ '_'+ name;
                var bound = $( this ).data( only );
                if ( bound !== null )
                    $( this ).unbind( event, bound );
                $( this ).data( only, fnct );
                $( this ).bind( event, fnct );
            } );
        },
        
        /* container_loader
            draws a loader to a container
        */
        container_loader: function( remove ) {
            return $( this ).each( function() {
                if ( remove === false ) {
                    var loader = $( this ).data( 'loader' );
                    if ( loader !== null && loader !== undefined ) loader.remove();
                }
                else {
                    var off = $( this ).offset();
                    var loader = $( '<div class="loader"><div class="inner"></div></div>' ).css( {
                        width: $( this ).width(),
                        height: $( this ).height(),
                        position: 'absolute',
                        top: off.top + 'px',
                        left: off.left + 'px',
                        zInedx: 100
                    } ).appendTo( 'body' );
                    $( loader ).find( '.inner' ).css( {
                        width: $( this ).width(),
                        height: $( this ).height()
                    } );
                    $( this ).data( 'loader', loader );
                }
            } );
        },
        
        
        /* inline_loader
            draws a loader to a container
        */
        inline_loader: function( remove ) {
            if ( remove === false ) {
                var loader = $( this ).data( 'loader' );
                if ( loader !== null && loader !== undefined ) loader.remove();
                return $( this );
            }
            else {
                var loader = $( '<div class="loader"></div>' );
                $( this ).data( 'loader', loader );
                return loader;
            }
        },
        
        
        /* bind_list_load_buttons
            bind all buttons for loading lists via AJAX
        */
        bind_list_load_buttons: function() {
            return $( this ).each( function() {
                var list_id = $( this ).attr( 'rel' );
                var $container = $( this ).parents( '.list-container-ajax' );
                var $list = empty( list_id )
                    ? $container.find( '.list:first' )
                    : $( '#'+ list_id )
                ;
                
                var href = $( this ).attr( 'href' );
                $( this ).bind_only( 'list_load', 'click', function() {
                    
                    // assure not loading when clicked
                    if ( empty( href ) || href == "#" || $list.data( 'is_loading' ) === true ) return false;
                    $list.data( 'is_loading', true );
                    
                    // show loader ..
                    $list.empty().append( $list.inline_loader() );
                    
                    // .. and retreive data
                    $.get( href, function( html ) {
                        
                        var $html = $( html );
                        
                        // output new data and remove current
                        $container.before( $html );
                        $container.remove();
                        
                        // update methods in content
                        $html.init_content();
                        
                        // unset loader
                        //$list.data( 'is_loading', false );
                    } );
                    return false;
                } );
            } );
        },
        
        
        /* init_galleries
            creates a jcarousel gallery out pf multiple images ..
            type is either "vertical" or "horizontal"
        */
        init_galleries: function( type ) {
            return $( this ).each( function() {
                var container = $( this ).hasClass( 'jcarousel-container' )
                    ? $( this )
                    : $( this ).find( '.jcarousel-container' )
                ;
                container.not( '.no-carousel' ).each( function() {
                    
                    // get the type (either vertical or horizontal)
                    var type = ( /\bjcarousel-container-(vertical|horizontal)\b/.exec( $( this ).attr( 'class' ) ) )[1];
                    
                    // build jcarousel args
                    var args = {
                        scroll: type == 'vertical' ? 3 : 9,
                        vertical: type == 'vertical'
                    };
                    
                    // for verticals, the size is divided by 3, because we have a 3x3 matrix
                    if ( type == 'vertical' ) {
                        args.size = Math.ceil( $( this ).find( 'li' ).size() / 3 );
                        args.noremovecache = true;
                    }
                    
                    // init the carousel
                    $( this ).jcarousel( args );
                } );
            } );
        },
        
        
       
        /* init_form
            inits popup formular after drawing
        */
        init_form: function() {
            return $( this ).each( function() {
                try{
                var form = $( this ).attr( 'nodeName' ) == 'FORM' ? $( this ): $( this ).find( 'form' );
                
                // select fist real element
                try {
                    $( form.attr( 'elements' ) ).each( function() {
                        var nn = $( this ).attr( 'nodeName' ).toLowerCase(),
                            t = $( this ).attr( 'type' );
                        if ( nn == 'select' || nn == 'textare' || ( nn == 'input' && t != 'hidden' ) ) {
                            $( this ).focus();
                            throw "";
                        }
                    } );
                } catch(e) {}
                
                // formulars
                form.submit( function() {
                    var $this = $( this ), p = $( this ).parent();
                    var action = $this.attr( 'action' );
                    if ( action === null || action == "" )
                        return false;
                    
                    // build form data
                    var data = $this.get_form_data();
                    $this.after( p.inline_loader() ).hide();
                    
                    $.open_fancybox( action, {
                        postData: data
                    } );
                    
                    return false;
                } ); 
                
                // errors
                form.find( 'div.input' ).each( function() {
                    var error = $( '.error-message', this );
                    if ( error.length > 0 ) {
                        $( this ).css( 'marginBottom', '10px' );
                        error.css( 'display', 'block' );
                    }
                } );
                
                
                // apple the edit form extensions, if loaded
                if ( $.fn.init_edit_form !== undefined )
                    form.init_edit_form();
                }catch(e){}
            } );
        },
        
        
        /* init_random_videos
            random videos container will be filled with new random contents
        */
        init_random_videos: function() {
            return $( this ).each( function() {
                $( '.x-randomvideos', this ).each( function() {
                    
                    // get the videos
                    var videos = [];
                    $( this ).find( '.x-video' ).each( function() {
                        videos.push( $( this ).val() );
                    } );
                    
                    // init interval
                    var pos = 1, imgs = {}, out = $( '.x-video-out', this );
                    var show_image = function( img ) {
                        var old = out.find( 'img' );
                        out.append( $( img ).css( {
                            visibility: 'visible',
                            top: 0,
                            left: 0,
                            zIndex: 1,
                            opacity: '0.0',
                            width: ( $.browser.msie ? '464px' : '466px' ), // ( out.width() - 2 )+ 'px',
                            height: ( $.browser.msie ? '198px' : '200px' ) // ( out.height() - 2 )+ 'px'
                        } ).animate( { opacity: '1.0' }, function() {
                            old.remove();
                        } ) );
                    };
                    
                    var load_next, stopped = false;
                    load_next = function() {
                        setTimeout( function() {
                            if ( stopped ) return false;
                            
                            // get current video
                            var video = videos[ pos++ ];
                            
                            // show cached image
                            if ( imgs[ video ] !== undefined && imgs[ video ] == null )
                                show_image( imgs[ video ] );
                            
                            // load image and then show
                            else {
                                var img = new Image();
                                img.src = video;
                                $( img ).load( function() {
                                    imgs[ video ] = img;
                                    show_image( img );
                                } ).css( { visibility: 'hidden', position: 'absolute', zIndex: -1 } );
                            }
                            
                            // set next pos and load next
                            if ( pos +1 > videos.length ) pos = 0;
                            load_next();
                        }, 5000 );
                    };
                    
                    out.one( 'click', function() {
                        $( this ).fancybox( $.extend( {}, $FANCYBOX_DEFAULT ) );
                        $( this ).trigger( 'click' );
                        stopped = true;
                        return false;
                    } );
                    
                    load_next();
                    
                } );
            } );
        },
        
        
        /* init_list_filters
            each list has filter which could have unfoldable sub-filters
        */
        init_list_filters: function() {
            return $( this ).each( function() {
                var $current_a = $( '.filters > li > a.selected' ),
                    $current_ul = null;
                
                // each first level li
                var $lis = $( '.filters > li', this ).each( function( num ) {
                    
                    // get any sub-uls and determine wheter this is selected
                    var $sub = $( 'ul', this ), selected = $( 'a', this ).hasClass( 'selected' );
                    
                    // not having any sub -> ignoew
                    if ( $sub.length == 0 ) return;
                    
                    // current is selected (and this is after load!)
                    if ( selected && $current_ul == null ) {
                        $sub.show();
                        $current_a  = $( '>a', this );
                        $current_ul = $sub;
                    }
                    
                    // rebind click event to unfold
                    $( '>a', this ).bind_only( 'filter-sub', 'click', function() {
                        
                        // catch already open
                        if ( $sub.is( ':visible' ) ) return false;
                        
                        // fold last and remove selection
                        if ( $current_a.length > 0 ) $current_a.removeClass( 'selected' );
                        if ( ok( $current_ul ) )
                            $current_ul.css( 'overflow', 'hidden' ).slideUp();
                        
                        // set current and unfold
                        $current_a = $( this );
                        if ( $sub.find( 'a.selected' ).length == 0 )
                            $current_a.addClass( 'selected' );
                        $current_ul = $sub;
                        $current_ul.slideDown();
                        
                        return false;
                    } );
                } );
            } );
        },
        
        
        /* init_comment_and_captchas
            Setup all required captchas and comment functions
        */
        init_comment_and_captchas: function() {
            
            
            /*
                SETUP CAPTCHA CONTAINERS
            */
            $( '.captcha-container' ).each( function() {
                var container = $( this );
                var error = container.find( '.captcha-error' ).hide();
                container.get(0).toggle_captcha = function( callback ) {
                    if ( container.is( ':visible' ) )
                        callback();
                    else
                        container.slideDown();
                };
                container.find( '.captcha-reload' ).bind_only( 'captcha', 'click', function() {
                    var img = container.find( 'img:first' );
                    var src = img.attr( 'src' ).replace( /\?.+$/, '' );
                    img.attr( 'src', src+ '?t='+ ( new Date() ).getTime() );
                    return false;
                } );
            } );
            
            
            
            /*
                SETUP COMMENTS
                    with or without captcha
            */
            
            var submit_comment = function( callback ) {
                var $this = $( '#comment_box' );
                
                // remove any old timeout message
                $this.remove( '#comment_timeout' );
                
                // get the comment data
                var data = $this.get_form_data();
                data.captcha = $( '#comment_captcha input[type=text]' ).val();
                
                // having input -> write comment
                if ( data[ 'data[Comment][content]' ] != "" ) {
                    
                    // get the orig input (for timeout) and clear th inpu
                    var orig = $this.find( 'textarea' ).val( '' );
                    
                    // disable all elements
                    $this.find( 'textarea,input' ).attr( 'disabled', true );
                    
                    $.post( $this.attr( 'action' ), data, function( html ) {
                        $this.find( 'textarea,input' ).attr( 'disabled', false );
                        if ( callback instanceof Function && ! callback( html ) ) {
                            $this.find( 'textarea' ).val( data[ 'data[Comment][content]' ] );
                            return false;
                        }
                        
                        // is in timeout -> show info
                        if ( $( html ).attr( 'id' ) == 'comment_timeout' ) {
                            $this.find( 'textarea' ).val( orig );
                            var $message = $( html );
                            $this.append( $message );
                            $message.slideDown();
                            setTimeout( function() {
                                $this.find( '#comment_timeout' ).slideUp();
                            }, 6000 );
                        }
                        
                        // not in timeout -> attach comment
                        else {
                            $( '#comment_box' ).slideUp();
                            $( '#content_comments' ).css( 'display', 'none' ).after( html ).remove();
                            $( '#content_comments' ).init_content();
                            $this.find( 'textarea' ).blur();
                        }
                    } );
                }
                return false;
            };
            
            // init comment captcha
            if ( $( '#comment_captcha' ).length > 0 ) {
                $( '#comment_box' ).bind_only( 'submit_comment', 'submit', function() {
                    try {
                    var captcha = $( '#comment_captcha' ).get(0);
                    captcha.toggle_captcha( function() {
                        submit_comment( function( html ) {
                            if ( html == 'WRONG' ) {
                                $( captcha ).find( '.captcha-reload' ).trigger( 'click' );
                                $( captcha ).find( '.captcha-error' ).show();
                                return false;
                            }
                            return true;
                        } );
                        return false;
                    } );
                    } catch( e ) { alert(e); }
                    return false;
                } );
            }
            else
                $( '#comment_box' ).bind_only( 'submit_comment', 'submit', submit_comment );
            
            // run the comment remove edit functions
            if ( $.fn.init_comment_remove !== undefined )
                $( this ).init_comment_remove();
            
            
            
            
            
            /*
                VOTING CAPTCHA
            */
            if ( $( '#votebutton' ).length > 0 )
                $( '#votebutton' ).bind_only( 'captcha', 'click', function() {
                    try {
                    var captcha = $( '#'+ $( this ).attr( 'rel' ) ).get(0);
                    captcha.toggle_captcha( function() {
                        var vote_link = $( '#captcha_vote_link' ).val();
                        $.post( vote_link+ '/vote', {
                            captcha: $( captcha ).find( 'input[type=text]' ).val()
                        }, function( data ) {
                            if ( data == "OK" )
                                $.reload_content( 'voters;'+ vote_link+ '/partial/voters' );
                            else {
                                $( captcha ).find( '.captcha-reload' ).trigger( 'click' );
                                $( captcha ).find( '.captcha-error' ).show();
                            }
                        } );
                    } );
                    } catch( e ) { alert(e); }
                    return false;
                } );
            
        },
        
        
        /* init_content
            Main init method for anything
        */
        init_content: function() {
            return $( this ).each( function() {
                
                // those inputs .
                $( '#topnav input,.comment textarea' ).focus( function() {
                    if ( $( this ).val() == $( this ).attr( 'rel' ) )
                        $( this ).val( '' );
                } );
                $( '#topnav input,.comment textarea' ).blur( function() {
                    if ( $( this ).val() == '' )
                        $( this ).val( $( this ).attr( 'rel' ) );
                } );
                
                // remove the focus thingy
                $( 'a', this ).focus( function() { $( this ).blur() } );
                
                // set all fancyboxes
                $( '.fancybox', this ).fancybox( $.extend( {}, $FANCYBOX_DEFAULT ) );
                
                // list navigation
                if ( $( this ).hasClass( 'list-container-ajax' ) )
                    $( this ).find( 'a.x-list-load-button, .x-list-load-button a' ).bind_list_load_buttons();
                else
                    $( '.list-container-ajax a.x-list-load-button,.list-container-ajax .x-list-load-button a', this ).bind_list_load_buttons();
                
                
                // startpage
                $( this ).init_random_videos();
                
                // list sorts
                $( this ).init_list_filters();
                
                // init image galleries
                $( this ).init_galleries();
                
                $( this ).init_comment_and_captchas();
                
                
                // tooltips
                $( '.tooltip' ).each( function() {
                    var options = $.extend( {}, $BT_OPTIONS );
                    if ( $( this ).hasClass( 'tooltip-image' ) ) {
                        options.positions = [ 'right' ];
                        options.width  = 80;
                        options.height = 100;
                    }
                    $( this ).bt( $( '#'+ $( this ).attr( 'rel' ) ).html(), options );
                } );
                
                
                // all popup forms
                var groups = {}, single = [];
                $( 'a.popup-form', this ).each( function( idx ) {
                    var height = 300, width = 400, r = $( this ).attr( 'rel' );
                    if ( r.match( /\bheight=(\d+)/ ) ) {
                        height = parseInt( RegExp.$1 );
                        r = r.replace( /[&,;]?height=\d+[&;]?/, '' );
                    }
                    if ( r.match( /\bwidth=(\d+)/ ) ) {
                        width = parseInt( RegExp.$1 );
                        r = r.replace( /[&,;]?width=\d+[&,;]?/, '' );
                    }
                    var list = single;
                    if ( r.match( /\bgroup=([^,;&=]+)/ ) ) {
                        var g = RegExp.$1;
                        r = r.replace( /[&,;]?group=[^,;&=]+[&,;]?/, '' );
                        if ( groups[ g ] === undefined )
                            groups[ g ] = { items: [], width: width, height: height };
                        groups[ g ].items.push( this );
                        $( this ).attr( 'rel', g );
                    }
                    else {
                        single.push( [ this, width, height ] );
                        $( this ).attr( 'rel', '' );
                    }
                } );
                $( single ).each( function() {
                    $( this[0] ).fancybox( $.extend( {
                        frameWidth: this[1],
                        frameHeight: this[2]
                    }, $FANCYBOX_DEFAULT ) );
                } );
                for ( g in groups )
                    $( groups[ g ].items ).fancybox( $.extend( {
                        frameWidth: groups[ g ].width,
                        frameHeight: groups[ g ].height
                    }, $FANCYBOX_DEFAULT ) );
                
            } );
        }
        
    } );
    
    
    
    
    
    
    /*
        SITE INIT
    */
    
    // fade in red bull logo
    setTimeout( function() {
        $( '#home' ).css( { opacity: 0, visibility: 'visible' } ).animate( { opacity: 1 }, 2000 );
    }, 2000 );
    $( function() {
        $( 'body' ).init_content();
    } );
} );
