window.addEvents({

    'domready' : function() {
    
        $$('.fx_header').set('opacity',0);
        
        new SmoothScroll();
        
        base_url = $('body_').getProperty('rel');
        base_style = base_url + 'static/styles/'+$('body_').getProperty('name')+'/';
        
        /* -- promo -- */
        /*
        canvas = [];
        canvas_img = []
        canvas_c = 1;
        
        $$('.promo').each( function( el , i ) {
        
            canvas[i] = el.getContext("2d");
            canvas_img[i] = new Image();
            canvas_img[i].src = el.getChildren()[0].getProperty('src');
            canvas_img[i].onload = function() {
                
                if( canvas_c%2 == 0 ) {
                canvas[i].rotate(-0.4);
                canvas[i].drawImage( canvas_img[i] , 10 , 40 , 100 , 100 );
                } else {
                canvas[i].rotate(0.4);
                canvas[i].drawImage( canvas_img[i] , 80 , -40 , 100 , 100 );
                }
                
                canvas_c++;
            } 
        
        });
        <canvas class='promo' id='promo_{position()}' width="200" height="150">
        */
        
        
        /* -- NAV DROP -- */

        if( $('body_').getProperty('name') == 2 ) {
        
            if( $('ribbon') ) {
            
                $('ribbon').addEvent( 'click' , function() {
             
                    ribbon_ = new Fx.Morph( 'ribbon' );
                    ribbon_.start({'margin-left':[-1024]}).chain( function(){ $('ribbon').destroy(); } );
                })
            
            }
            
            $('member').removeClass('hide');
            fx_member_ = new Fx.Morph('member',{'duration':2000, 'transition':Fx.Transitions.Bounce.easeOut});
            fx_member_.start({ 'top':[-246,-110] });
            
            function flowerdrop(e) {
            
                e.stop();
                
                flowers_seg.addClass( 'hide');
                
                parent = this.getParent();
                margin = parent.getStyle( 'margin-top' ).replace(/px/,'') * 1;
                if( parent.getProperty('id') == "tree_help") margin += 70;
                if( parent.getProperty('id') == "tree_about") margin += 20;
                fx_flower_ = new Fx.Morph(parent,{'duration':2000, 'transition':Fx.Transitions.Bounce.easeOut});
                fx_flower_.start({ 'margin-top':margin+110 });
                
                this.removeEvent('click',flowerdrop);

            }
            
            flowers = $$('#tree span a');
            flowers_bs = $$('#tree span');
            flowers_seg = $$('.tree_sub');
            
            sub_on = 1;
            
            flowers_bs.set( 'opacity' , 0 );
            fx_flower = [];
            flowers_bs.each( function( el , i ) {
                fx_flower[i] = new Fx.Morph( el , {'duration':1000} );
            });

            fx_flower[0].start({'opacity':[0,1]}).chain(function(){
                fx_flower[1].start({'opacity':[0,1]}).chain( function() {
                    fx_flower[2].start({'opacity':[0,1]}).chain( function() {

                    coords = $('tree_about').getCoordinates();
                    
                    ul_ch = $$('ul[rel=tree_about]')[0];
                    ul_ch.setStyles({'top':coords.top + 17, 'left':coords.left + 49 , 'width':0  });
                 
                    ul_ch.removeClass( 'hide' );
                    fx_first_ch = new Fx.Morph( ul_ch , {'link':'ignore'} );
                    fx_first_ch.start({'width':[0,230]});
                        
                    sub_on = 1;
    
                    });
                })
            });

            flowers_seg.addEvent( 'mouseleave' , function() {
                if( sub_on == 1 ) {
                    flowers_seg.addClass('hide');
                    sub_on = 0;
                }
            }); 
            
            flowers.addEvents({ 
                'mouseenter' : function() {

                    flowers_seg.addClass( 'hide');
                    coords = this.getParent().getCoordinates();
                    
                    ul_ch = $$('.tree_sub[rel='+this.getParent().getProperty('id')+']')[0];
                    ul_ch.setStyles({'top':coords.top + 17, 'left':coords.left + 49 , 'width':0  });
                 
                    ul_ch.removeClass( 'hide' );
                    fx_first_ch = new Fx.Morph( ul_ch , {'link':'ignore'} );
                    fx_first_ch.start({'width':[0,230]});
                        
                    sub_on = 1;
                
                },
                'click' : flowerdrop
            });
            

            
        }

        /* -- LOAD EXTERNAL SCRIPTS -- */
                                                                   
        if( $$('.wysiwyg').length > 0 || $$('.wysiwyg_d').length > 0 ) {                       
            new Asset.javascript(base_url+'static/javascript/libs/fckeditor/fckeditor.js' , {id:'wysiwyg', onload:function(){
                if( $$('.wysiwyg').length > 0 ) {
                    oEditor = [];
                    $$('.wysiwyg').each( function( el , i ) {
                        var oEditor = new FCKeditor(el.getProperty('name')) ;
                        oEditor.BasePath = base_url+"static/javascript/libs/fckeditor/" ;
                        oEditor.Config["CustomConfigurationsPath"] = base_url+"static/javascript/libs/fckeditor/config_"+el.getProperty('rel')+".js?" + ( new Date() * 1 ) ;
                        if( el.getProperty('rel') == 'advanced' ) oEditor.Height = '500px';
                        oEditor.ReplaceTextarea() ;
                    });  
                }
            }});
        }
        
        if( $$('.color_picker').length > 0 )    {
            new Asset.css(base_style+'css/colorpicker.css');
            new Asset.javascript(base_url+'static/javascript/libs/rainbow.lib.js' , {onload:function(){
                $$('.color_picker').each( function( el, i ) {
                var r = new MooRainbow( el , {
                    'id':'rainbow_'+el.getProperty('name'),
		            'startColor': el.getProperty('rel').split(','),
		            'onChange': function(color) {
		                el.value = color.hex.toUpperCase();
		                if( el.getProperty('name') == 'ahero_bgcolor' )       $('preview_style').setStyle( 'background-color' , color.hex );
		                if( el.getProperty('name') == 'ahero_fontcolor' )     $('preview_style').setStyle( 'color' , color.hex );
		                if( el.getProperty('name') == 'ahero_headercolor' )   $$('#preview_style h3').setStyle( 'color' , color.hex );
		                if( el.getProperty('name') == 'ahero_linkcolor' )     $$('#preview_style a').setStyle( 'color' , color.hex );
		            }
	            });      
                });
            }});
            
            if( $('preview_style') ) {
            
                $$('.color_picker').each( function( el ) {
                    
                    if( el.getProperty( 'value' ).contains( '#' ) ) {
                        
		                if( el.getProperty('name') == 'ahero_bgcolor' )       $('preview_style').setStyle( 'background-color' , el.getProperty( 'value' ) );
		                if( el.getProperty('name') == 'ahero_fontcolor' )     $('preview_style').setStyle( 'color' , el.getProperty( 'value' ) );
		                if( el.getProperty('name') == 'ahero_headercolor' )   $$('#preview_style h3').setStyle( 'color' , el.getProperty( 'value' ) );
		                if( el.getProperty('name') == 'ahero_linkcolor' )     $$('#preview_style a').setStyle( 'color' , el.getProperty( 'value' ) );
                    
                    }
                    
                });

            }
            
        }
       
        /* -- BLACKOUT -- */
        
        $('blackout').addEvent( 'click' , function() {
            this.addClass('hide');
            if( $('canvas') ) {
                $('canvas').empty();
                $('canvas').addClass('hide');
            }
        });


        $$('a').addEvent( 'focus' , function() {
            this.blur()
        });


        /* -- FORMS -- */

        function add_note( x , y , txt ) {
        
            if( $('note') ) $('note').destroy();
            
            if( x + 300 > window.getWidth() )   x = window.getWidth() - 300;
            if( y < 0 )                         y = 0;

            $('content').adopt( new Element( 'div' , { 'id':'note' } ).setStyles({'top':y , 'left':x } ) );
            $('note').adopt( new Element( 'div' , { 'id':'note_inner' , 'html':txt } ) );
            
        }
        
        forms_ = $$('#content form[name!=go]');
    
        forms_.addEvent( 'submit' , function(e) {
        
            e.stop();

            $$('#current_form').removeProperty( 'id' );

            current_form_ = this;
            current_form_.setProperty( 'id' , 'current_form' );
            
            if( $('openid') ) {
            
                if( $('openid_if') ) $('openid_if').destroy();
                
                $('openid_cont').setStyle( 'background' , 'url('+base_style+'images/ajax-loader.gif) no-repeat bottom right' );
                $('current_form').adopt( new Element( 'iframe' , { 'src':base_url+'openid/'+$('openid').getProperty('value')+'/' , 'id' : 'openid_if' , 'name' : 'openid_if' } ).setStyles({'width':'100%', 'height':400, 'border':0 }) );
                
                ( function() {
                
                    oid_load = 0;
                    txt_on = 0;

                    txt = $('openid_if').contentDocument.defaultView.document.body.innerHTML;
                            
                    if( txt == 'error' ) {
                        $('openid_cont').removeProperty( 'style' );
                        ( function() { $('openid_if').destroy(); } ).delay(50);   
                    }
                            
                    $('openid_if').addEvent( 'load' , function() {
                    
                        if( oid_load == 0 ) $('openid_cont').removeProperty( 'style' );
                            
                        txt = $('openid_if').contentDocument.defaultView.document.body.innerHTML;
                        if( txt == 'error' || txt.contains('ttuname###') ) {
                            $('openid_if').setStyles({'width':0, 'height':0 });
                            if( txt.contains('ttuname###') ) {
                                oid_name = txt.replace(/ttuname###/,'');
                                $('current_form').adopt( new Element( 'input' , { 'name':'cname', 'type':'hidden' , 'value':oid_name } ) );
                                form_submit();
                            }
                            txt_on = 1;
                        }
                            
                        if( oid_load == 1 || txt_on == 1 ) ( function() { $('openid_if').destroy(); } ).delay(50);

                        oid_load++;
                        
                    });
                
                } ).delay(500);
            
            } else form_submit();
            
            function form_submit() {

            if( $$('#current_form .wysiwyg').length > 0 ) {
                oEditor = [];
                $$('#current_form .wysiwyg').each( function( el , i ) {
                    oEditor[i] = FCKeditorAPI.GetInstance(el.getProperty('name'))
                    if( $('wysiwyg_'+i) ) $('wysiwyg_'+i).destroy();
                    current_form_.adopt( new Element( 'input' , { 'id':'wysiwyg_'+i , 'type':'hidden' , 'name':'ow_'+el.getProperty('name') , 'value':oEditor[i].GetXHTML() } ) );
                });
            }

            new Request.JSON({url: base_url+"imps/"+current_form_.getProperty('name'), onComplete: function(response){ if( response ) {



                error_codes = $$('#current_form b');
                error_codes.addClass( 'error' );
                $$('#current_form input').removeClass( 'error_border' );
                
                response.insert ? ri = response.insert : ri = '';
                    
                input_s = $$('#current_form input[type=submit]');
                x = input_s[0].getPosition().x
                y = input_s[0].getPosition().y
                
                if( response.error ) {
                    $$('#current_form b').removeProperty('id');
    
                    response.error.each( function( el, i ) {
                        $$('#current_form *[name='+error_codes[el].getProperty('rel')+']').addClass( 'error_border' );
                        error_codes[el].removeClass('error');
                        if( i == 0 ) error_codes[el].setProperty('id', 'firsterror');
                    });
            
                    error_scroll = new Fx.Scroll(window).toElement('firsterror');
                    
                    if( $('recaptcha_widget_div') ) Recaptcha.reload();
                }
                
                if( response.note ) {
                    add_note(x,y-200,response.note);
                }
                
                if( response.upload ) {
                
                    $('current_form').setProperties({ 'target':'upload_target' , 'enctype':'multipart/form-data' , 'method':'post' , 'action':base_url+'global/upload_file.php'});
                    $('current_form').adopt( new Element( 'input' , { 'name':'file_info', 'id':'file_info', 'type':'hidden' , 'value':response.upload } ) );
                    $('current_form').adopt( new Element( 'iframe' , { 'id':'upload_target', 'name':'upload_target', 'src':base_url+'global/upload_file.php' } ).setStyles({'width':0, 'height':0, 'border':0 }) );
                    $('current_form').submit();
                    
                    new Request.JSON({url: base_url+"global/upload_file.php", onComplete: function(tmp_file){ if( tmp_file ) {
                    
                        if( tmp_file.name ) {

                            $('upload_progress').set( 'html' , 'Upload starting ... ' );
                       
                            check_progress = ( function() {   
                        
                                new Request.JSON({url: base_url+"global/upload_file.php", onComplete: function(tmp_size){ if( tmp_size ) {
                            
                                    upload_bar = '';
                                    size_info = tmp_size.size.split('|');
                                
                                    if( size_info[1] == "MB" )      increment = 5;
                                    else if( size_info[1] == "KB" ) increment = 1024*5;
                                    else                            increment = 1024*1024*5;
                                
                                    for( i = 0 ; i < size_info[0] ; i+=increment ) upload_bar += '<img src="'+base_style+'images/progress.gif" width="25" height="15" style="margin-right:1px" />';
                                    $('upload_progress').set( 'html' ,  upload_bar );
                                
                                }}}).post({'act':'check_size', 'file':tmp_file.name });
                            
                            }).periodical(1000);
                        
                            $('upload_target').addEvent( 'load' , function() {
                            
                                $clear(check_progress);
                                txt = $('upload_target').contentDocument.defaultView.document.body.innerHTML;
                                add_note( x,y-200,txt );
                                txt = (txt + '').replace(/<br>/g, '\n');
                                $('upload_progress').set( 'html' , txt );
                                $('current_form').removeProperties('target', 'enctype', 'action');
                                $('file_info').destroy();
                                ( function() { $('upload_target').destroy(); } ).delay(50);  

                                if( ri != '' ) {
                                    $(ri['into']).set( 'html' , $(ri['into']).get('html') + ri['item'] );
                                }
                
                            }); 

                        } else {
                        
                            $('current_form').removeProperties('target', 'enctype', 'action');
                            $('file_info').destroy();
                            ( function() { $('upload_target').destroy(); } ).delay(50);  
                            $('upload_progress').set( 'html' , tmp_file.error );
                        }
                        
                    }}}).post({'act':'get_file'});

                }
        
                                
                if( response.content ) {
                    $('content').set('html',response.content);
                }
                
                if( response.cookie ) {
                    response.cookie.each( function( el , i ) {
                        Cookie.dispose( el.name );
                        Cookie.write( el.name , el.info , {duration: el.duration , path:'/'});
                    });
                }
                      
                if( response.refresh == 1 ) {
                    location.href = location.href;
                }
                      
                if( response.forward ) {
                    response.forward.contains('#') ? location.href = location.href + response.forward : location.href = response.forward;
                }
                
                if( response.destroy ) {
                    response.destroy.each( function( el , i ) {
                        $$('*[title='+el+']').destroy();
                    });
                }

                
                                
            }}}).post(current_form_);
            
            }
        
        });
        
        
        /* -- PANELS -- */

        if( $$('.panel').length > 0 ) {

            panel_li = [];
            panel_span = [];
            panel_set = [];
            panel_id = 0;
            
            cprog = $('body_').getProperty('class');
            hprog = location.hash.replace(/#/,'');

            function panel_switch( panel, segment ) {
            
 //               flowers_seg.addClass( 'hide');
                
                Cookie.dispose( 'cp'+cprog+panel );
                Cookie.write( 'cp'+cprog+panel , segment );

                panel_li[panel].removeClass('on');
                panel_li[panel][segment].addClass('on');
                               
                panel_span[panel].addClass('hide');
                panel_span[panel][segment].removeClass('hide');    
                
                if( $('panel_title') ) $('panel_title').set('html',panel_li[panel][segment].get('html'));
            }
            
            $$('.panel').each( function( el , i ) {
                
                p = -1;
            
                panel_li[i] = el.getElements('ul li');
                panel_span[i] = el.getElements('span');
    
                panel_li[i].setProperty( 'rel' , i );
                panel_id = i;
    
                panel_li[i].each( function( elb, ib ) {
                    elb.addEvent( 'mouseenter' , function() { panel_switch(elb.getProperty('rel'),ib) } );
                    if( elb.getProperty( 'id' ) == hprog ) p = ib;
                });

                if( p == -1 ) Cookie.read( 'cp'+cprog+i ) && panel_li[i][Cookie.read( 'cp'+cprog+i )] ? p = Cookie.read( 'cp'+cprog+i ) : p = 0;
          
                panel_switch( i , p );
            
            });
            
        }

        /* -- LOG IN REPLACE -- */
    
        if( $('log-in-form') ) {

            member_form_inp = $$("#member input[type='text']");

            function update_login() {
                 member_form_inp.each( function( el , i ) {
                    if( !el.getProperty( 'value' ) ) {
                        el.setProperty( 'type' , 'text' );
                        el.addClass( 'overtext' );
                        el.setProperty( 'value' , li_input[el.getProperty('rel')] );
                    }
                });
            }
            
            fx_login = new Fx.Slide( 'log-in-form' , { mode:'vertical' } ).hide();
            fx_password = new Fx.Slide( 'lost-password-form' , { mode:'vertical' } ).hide();

            $('log-in').addEvent( 'click' , function(e) {
                e.stop();
                update_login();
                fx_password.open ? fx_password.slideOut().chain( function() { fx_login.toggle() } ) : fx_login.toggle();
                
            });
            
            $('lost-password').addEvent( 'click' , function(e) {
                e.stop();
                update_login();
                fx_login.open ? fx_login.slideOut().chain( function() { fx_password.toggle() } ) : fx_password.toggle();
            });
            
            li_input = [];
            member_form_inp.each( function( el , i ) {li_input[i] = el.getProperty( 'value' );});

            member_form_inp.addEvents({
                'focus' : function() {
                    update_login();
                    this.setProperty( 'value' , '' );
                    this.removeClass( 'overtext' );
                    if( this.getProperty( 'name' ) == 'mpassword' && this.getProperty( 'type' ) == 'text' ) this.setProperty( 'type' , 'password' );
                }
            });
            
        }
         

        /* -- PROMO -- */
        
            $$('#promo a').addEvent( 'focus' , function() { this.blur() } );
            
            
        /* -- SLIDESHOW -- */
        
            if( $('slideshow') ) {
            
            
                slideshow_images_ = $$('#slideshow_images li');
                slideshow_curr = 1;
                
                slideshow_img_array = [];
            
                slideshow_images_.each( function(el,i) { slideshow_img_array[i] = "'" + slideshow_images_[i].get('text') + "'" });

                function ss_flip() {

                    imgFX.start({ 'width': [244, 1] , 'height' : [365]  }).chain( function() {

                        (slideshow_curr+1) > slideshow_images_.length ? slideshow_curr = 1 : slideshow_curr++;
                        $('slideshow_img').setProperty( 'src' , slideshow_images_[(slideshow_curr-1)].get('text') );
                    
                        ( function() { imgFX.start({ 'width': [1,244] , 'height' : [365] }); } ).delay(50);

                    })
                }
                        
                var myImages = new Asset.images([slideshow_img_array.join(',')], { onComplete: function(){
                
                    $('slideshow').adopt( 
                        new Element( 'img' , { 'id' : 'slideshow_img' , 'src' : slideshow_images_[0].get('text') , 'width' : '244px' , 'height' : '365px' } )
                    );
                    
                    ss_auto = ss_flip.periodical(3000);

                    imgFX = new Fx.Morph('slideshow_img', {duration: 'short', transition: Fx.Transitions.Sine.easeOut});
                    
                    $('slideshow_img').addEvents({
                    
                        'click' : function() {
                        
                            $clear(ss_auto);
                            ss_flip();
                        }
                                        
                    });
 
                }});
    
                
            }


        /* -- SEARCH -- */
            
            s = 0;
        
            $$('.search').addEvents({

                'keyup': function() {
                
                    this_search = this;
                    
                    if( this_search.getProperty('value') != '' && s == 0 ) {
                
                        search_delay = ( function() {
                    
                            new Request.JSON({url: base_url+"imps/"+this_search.getProperty('name'), onComplete: function(response){ if( response ) {

                                if( response.display ) {
                                    $('search_display').set( 'html' , response.display ) ; 
                                    tbl_alternate();
                                } else $('search_display').set( 'html' , 'No results found!' );
                                
                                s = 0;
                                
                            }}}).post({ 'act' : 'search' , 'value' : this_search.getProperty('value') });
                        
                        }).delay( 2000 );
                        
                        s = 1;
                    
                    }

                },
                
                'keydown': function() {
                
                    if( s == 1 ) {
                        $clear( search_delay );
                        s = 0;
                    }
                }
            
            });
            
            
        /* -- delete -- */
        
        $$('.delete').addEvent( 'click' , function(e) {
        
            e.stop();
            x = e.client.x - 90;
            y = e.client.y - 193 + getScroll().y;
            
            add_note( x , y , "<p><a href='#' id='delete_confirm'><b>Yes, I definitely want to delete this</b></a></p><p><a href='#' id='delete_remove'>I've changed my mind!</a></p>" );

            cell_tag = ''
            cell_curr = this;
                
            $('delete_confirm').addEvent( 'click' , function(e) {
            
                e.stop();

                new Request.JSON({url: cell_curr.getProperty('href') , onComplete: function(response){ if( response ) {
                
                    $('note').destroy();
                    
                    if( response.forward ) {
                
                        location.href = response.forward;
                        
                    } else if( response.success == 1 ) {
                    
                        while( cell_tag != 'tr' && cell_tag != 'div' ) {
                            cell_curr = cell_curr.getParent();
                            cell_tag = cell_curr.get('tag');
                        }
                        
                        if( cell_curr.hasClass( 'show_parent' ) ) $$('rel=['+cell_curr.getProperty('name')+']').destroy();
                        
                        cell_height = cell_curr.getSize().y;
                        cell_curr.setStyle( 'height' , cell_height );

                        fade = new Fx.Morph( cell_curr , {duration: 'short', transition: Fx.Transitions.Sine.easeOut} );
                        fade.start({ opacity:[1,0] }).chain( function() {
                            cell_curr.empty();
                            fade.start({height:[cell_height,0]}).chain(function() {
                                cell_curr.destroy()
                            }); 
                        });
                        
                    } else add_note( x , y , response.error );
                                
                }}}).post({ 'act' : cell_curr.getProperty( 'name' ) , 'id' : cell_curr.getProperty( 'rel' ) });

            });
            
            $('delete_remove').addEvent( 'click' , function(e) {
                e.stop();
                $('note').destroy();
            });
            
        });
             
            
        /* -- parent child -- */
        
        wysiwyg_arr = [];
        
        $$('.show_child').addClass( 'hide' );
        $$('.show_parent').addEvent( 'click' , function(e) {
            e.stop();
            $$('*[rel='+this.getProperty('name')+']').toggleClass('hide');
            
            if( this.getProperty( 'rel' ) && this.getProperty( 'rel' ) == "wysiwyg_d" ) {
            
                check = $$('*[rel='+this.getProperty('name')+']');
                
                if( !check[0].hasClass( 'hide' ) && !wysiwyg_arr.contains(this.getProperty('name')) )  {
                
                    ta = $$('textarea[name='+this.getProperty('name')+']');
                    var oEditor = new FCKeditor(ta[0].getProperty('name')) ;
                    oEditor.BasePath = base_url+"static/javascript/libs/fckeditor/" ;
                    oEditor.Config["CustomConfigurationsPath"] = base_url+"static/javascript/libs/fckeditor/config_"+ta[0].getProperty('rel')+".js?" + ( new Date() * 1 ) ;
                    if( ta[0].getProperty('rel') == 'advanced' ) oEditor.Height = '500px';
                    oEditor.ReplaceTextarea();
                    
                    wysiwyg_arr.extend([this.getProperty('name')])

                }
            }
        });
        
        /* -- selectngo -- */

        $$('.selectngo').addEvent( 'change' , function() {
        
            location.href = this.getProperty('rel') + this.getProperty('value');
            return;           
        
        });
        
        /* -- a rel -- */
        
        $$('a[rel=external]').setProperty( 'target' , '_blank' );
        
        
        /* -- img thumbs -- */
        
        $$('.img_thumb p').addEvent( 'click' , function() {
        
            this.toggleClass('on');
            
            if( $('img_delete') ) {
            
                delete_img = [];
                $$('.img_thumb p.on').each( function( el , i ) { delete_img[i] = el.getProperty( 'alt' ) });
                
                $('img_delete').setProperty( 'value' , delete_img.join('|') );
            
            }
            
        });
        
            
        /* -- toggle create account -- */
        
        $$('input[name="mtype"]').addEvent( 'click' , function() {
            this.getProperty( 'value' ) == 3 ? $('view').removeClass('hide') : $('view').addClass('hide');
        });
        
        
        /* -- catch tab -- */
        
        $$('.code').addEvent( 'keydown' , function(e) {
            if( e.key == 'tab' ) {
                e.stop();
                this.insertAtCursor("    ");
                this.setCaretPosition(this.getCaretPosition()+4);
            }
        });
        
        /* -- swiff -- */
        
        
        if( $('swf_inject' ) ) {
        
            if( !$('swf_inject' ).getProperty('name') ) {
                w = 800;
                h = 400;
            } else {
                wh = $('swf_inject' ).getProperty('name').split( 'x' );
                w = wh[0];
                h = wh[1];
            }
        
        var obj = new Swiff(base_url+$('swf_inject' ).getProperty('rel'), {
            id: 'swf',
            container: $('swf_inject' ),
            width: w,
            height: h,
            params: {
                wmode: 'opaque',
                bgcolor: '#141414'
            },
            vars: {
                'data-file':$('swf_inject' ).getProperty('class')
            }
        });
        }

        /* -- send post -- */
        
        $$('.postto').addEvent( 'click' , function(e) {
        
            e.stop();

            x = e.client.x - 90;
            y = e.client.y - 193 + getScroll().y;
            
            postto_ = this.getProperty('name').split('?');

            new Request.JSON({url: base_url+"imps/"+postto_[0], onComplete: function(response){ if( response ) {
                    
                    add_note( x , y , "<p>"+response.note+"</p>" );
          
            }}}).post({ 'act' : postto_[1] , 'id' : this.getProperty( 'id' ) });

        });
        
        /* -- send email -- */
        
        $$('.send_email').addEvent( 'click' , function(e) {

            x = e.client.x - 90;
            y = e.client.y - 193 + getScroll().y;

            if( typeof FCKeditorAPI != "undefined" ) {
            
                eEditor = FCKeditorAPI.GetInstance(this.getProperty('id'))
                img_ = this;
                
                new Request.JSON({url: base_url+"imps/admin", onComplete: function(response){ if( response ) {
                    
                    if( response == 1 ) add_note( x , y , "<p><b>The email has been sent!</b></p><p>You will receive a copy to your registered email</p>" );
          
                }}}).post({ 'act' : 'progress_email' , 'email_txt' : eEditor.GetXHTML() , 'email_info' : this.getProperty('rel').split('#') });
            
            } else  alert("Please open the email first!");

        });
        
        /* -- accordian -- */
        
        if( $('accordian') ) {
            var accordion_ = new Fx.Accordion($$('#accordian .togglers'), $$('#accordian .togglees'), { display: 0, alwaysHide: true, initialDisplayFx: false });
        }
          
        
        function tbl_alternate() {

   		    if( $$('table.alternate' ).length > 0 ) {
        	    $$('table.alternate tr:even').addClass( 'light' );
         	    $$('table.alternate tr:odd').addClass( 'dark' );
			    $$('table.alternate tr.tblheader').removeClass('light');
          	    $$('table.alternate tr.tblheader').removeClass('dark');
   		    }
        }
        
        tbl_alternate();
        
        

    },
    
    'load': function() {

        if( Browser.Engine.trident && Browser.Engine.version == 4 ) {
            $$('img[class=reflected]').setStyle( 'behavior' , 'url(/static/javascript/libs/iepngfix.htc)' );
            $$('div[id=beta]').setStyle( 'behavior' , 'url(/static/javascript/libs/iepngfix.htc)' );
        }
        
        $('body_').addEvent( 'click' , function() {
            if( $('note') )  $('note').destroy();
        });
        
        if( $$('.fx_header').length > 0 ) {
        
            fx_header_ = $$('.fx_header');
          //  fx_colors_ = ['#B47C0D','#BD00FD','#049BAC'];
            fx_colors_ = ['#0D5F64','#0D5F64','#0D5F64'];
            
            fx_header_[0] = new Fx.Morph(fx_header_[0], {duration:1000});
            fx_header_[1] = new Fx.Morph(fx_header_[1], {duration:1000});
            fx_header_[2] = new Fx.Morph(fx_header_[2], {duration:1000});
            fx_header_[0].start({'opacity':[0,1], 'letter-spacing':[-40,10], 'color':['#000000',fx_colors_[0]]}).chain( function() {
                fx_header_[1].start({'opacity':[0,1], 'letter-spacing':[-40,10], 'color':['#000000',fx_colors_[1]]}).chain( function() {
                    fx_header_[2].start({'opacity':[0,1], 'letter-spacing':[-40,10], 'color':['#000000',fx_colors_[2]]}).chain( function() {
                        fx_header_[0].start({'color':[fx_colors_[0],'#FFFFFF']});
                        fx_header_[1].start({ 'color':[fx_colors_[1],'#FFFFFF']});
                        fx_header_[2].start({ 'color':[fx_colors_[2],'#FFFFFF']});
                    });
                });
            });
 
        }

    }, 
    
    'unload': function() {
    },
    
    'resize': function() {

        $$('.tree_sub').addClass('hide');
    }
    
});

