$(document).ready(function() {

    topMenu = {
        orange_bar: $('.pointer .orange'),
        links: $('.menu ul a'),
        menu: $('.header .menu'),
        header: $('.header'),
        default_visibility: null,

        move_bar: function(link) {
            var link_offset = 20;
            var link_position = link.position().left + link_offset;
            var link_middle = ((link.width() + 36) / 2);
            this.orange_bar.animate({ width: (link_position + link_middle) + 'px', 'padding-right': (link_middle - 45) + 'px' }, 200, 'linear');
        },
        set_default_visibility: function() {
            this.orange_bar.css('visibility', this.default_visibility);
        },
        activate_link: function() {
            this.links.each(function() { $(this).hasClass('active') ? topMenu.move_bar($(this)) : null; })
        },
        setup_menu: function() {
            this.activate_link();
            this.menu.hoverIntent({ interval: 100, timeout: 0,
                over: function() { topMenu.orange_bar.css('visibility', "visible"); },
                out: function() { topMenu.set_default_visibility(); topMenu.activate_link(); }
            });
        },
        setup_links: function() {
            this.links.hoverIntent({ sensitivity: 2, interval: 50, timeout: 0,
                over: function(el) { topMenu.move_bar($(el.target)) },
                out: function() { }
            });
            this.links.click(function() {
                topMenu.links.removeClass('active');
                $(this).addClass('active');
            });
        },
        init: function() {
            this.default_visibility = this.orange_bar.css('visibility');
            this.setup_menu();
            this.setup_links();
        }
    };
    topMenu.init();

    actionBox = {
        init: function() {
            $('.box .buttons a').click(function() {
                $('.box .column').each(function() {
                    $(this).toggleClass('active');
                });
                $('.column.menu').toggleClass('right');
                return false;
            })
        }
    };
    //actionBox.init();

    $('.column.narrow a.show-next').click(function() {
        $('#top-app-info div').toggle();
        return false;
    })

        var adReportForm = {
        textarea_value: 'Reason of reporting the add ...',
        button_show_form: $('.ad-report a.report'),
        textarea_input: $('.ad-report textarea'),

        button_init: function(){
            this.button_show_form.click(function(){
                var form = $(this).parent().siblings('form');
                $(this).children().children().text(form.css('display') == 'none' ? 'Close' : 'Report Ad');
                form.slideToggle('fast');
                return false;
            })
        },
        textarea_init: function() {
            var _textarea_value = this.textarea_value;
            this.textarea_input.attr('value', this.textarea_value);
            this.textarea_input.focus(function(){
                if($(this).attr('value') == _textarea_value ) {$(this).attr('value', '')}
                $(this).css('color', '#333333')
            })
        },
        init: function(){
            this.button_init();
            this.textarea_init();
        }
    };

    adReportForm.init();
    
});

