/*
 * MENU
 */
var ni_menu = new function()
{
    this.in_timeout;
    this.out_timeout;
    this.active;
    this.tmpactive;
    this.selected;

    this.init = function()
    {
        this.selected = $('.box-node-tree-default ul.main li a.active');
        
        $('.box-node-tree-default .main').removeClass('drop-on');
        $('.box-node-tree-default .dropdown').hide();

        $('.box-node-tree-default ul.main li a')
            .mouseover(function(){
                ni_menu.tmpactive = this;
                ni_menu.over('main');
            })
            .mouseout(function(){
                ni_menu.out()
            });
        $('.box-node-tree-default .dropdown')
            .mouseover(function(){
                ni_menu.over('dropdown');
            })
            .mouseout(function(){
                ni_menu.out()
            });
    }

    this.over = function(type)
    {
        clearTimeout(this.in_timeout);
        clearTimeout(this.out_timeout);
        this.in_timeout = setTimeout(function(){
            if(ni_menu.tmpactive && type == 'main'){
                ni_menu.active = ni_menu.tmpactive;
                $('.box-node-tree-default ul.main li a').removeClass('selected').removeClass('active');
                $(ni_menu.active).addClass('selected');

                var dest = $(ni_menu.active).attr('rel');
                if(!dest){
                    ni_menu.drophide();
                    return;
                }

                $('.box-node-tree-default .dropbox').hide();
                $('.box-node-tree-default .'+dest).show();
            }
            else {
                ni_menu.tmpactive = null;
            }

            $('.box-node-tree-default .main').addClass('drop-on');
            $('.box-node-tree-default .dropdown').show();
        }, 175);
    }

    this.out = function()
    {
        clearTimeout(this.in_timeout);
        clearTimeout(this.out_timeout);
        this.out_timeout = setTimeout(function(){
            if(ni_menu.selected){
                $(ni_menu.selected).addClass('active');
            }
            $('.box-node-tree-default ul.main li a').removeClass('selected');
            ni_menu.drophide();
        }, 500);
    }

    this.drophide = function()
    {
        $('.box-node-tree-default .main').removeClass('drop-on');
        $('.box-node-tree-default .dropdown').hide();
    }
}

/*
 * FORM
 */
$.fn.form = function(options){
    var options = $.extend({
        enableClass: null,
        disableEmpty: false
    }, options);

    return this.each(function(){
        //form
        $(this)
            .submit(function(){
                if(options.disableEmpty){
                    $(this).find('input[type="text"]').each(function(){
                        if($(this).val() == $(this).attr('data-default') ){
                            $(this).attr('disabled', 'disabled');
                        }
                    });
                }
            })
            .find('input[type="text"]').each(function(){
                if($(this).val() != $(this).attr('data-default') ){
                    if(options.enableClass){
                        $(this).addClass(options.enableClass);
                    }
                }
                //input
                $(this)
                    .focus(function(){
                        if($(this).val() == $(this).attr('data-default') ){
                            $(this).val(''); // TUTAJ BRAKOWALO SREDNIKA :)
                            if(options.enableClass){
                                $(this).addClass(options.enableClass);
                            }
                        }
                    })
                    .blur(function(){
                        if(!$(this).val()){
                            $(this).val($(this).attr('data-default')); // TUTAJ BRAKOWALO SREDNIKA :)
                            if(options.enableClass){
                                $(this).removeClass(options.enableClass);
                            }
                        }
                        else {
                            if(options.enableClass){
                                $(this).addClass(options.enableClass);
                            }
                        }
                    });
        });
    });
};

/*
 * FONT SIZE
 */
var ni_fontresizer = new function()
{
    this.active = 1;
    this.def    = false;
    this.config = {'size2':1.2, 'size3':1.4 };

    this.init = function()
    {
        $(".size-change a").click(function(){
            if(!ni_fontresizer.def){
                ni_fontresizer.def_size();
            }

            type = $(this).attr('rel');
            if(ni_fontresizer.active == type){
                return;
            }

            ni_fontresizer.active = type;

            if(type == 1){
                ni_fontresizer.reset();
            }
            else if (type == 2 || type == 3){
                ni_fontresizer.resize(type);
            }

            return false;
        });
    }

    this.reset = function()
    {
        $('.template-bodyer-bg *').filter('div,a,p,b,strong,span,h1,h2,h3,h4,h5,h6,u,i,li,td').each(function(){
            var size = $(this).data('default-size');
            $(this).css('font-size', size);
        });
    }

    this.resize = function(type)
    {
        $('.template-bodyer-bg *').filter('div,a,p,b,strong,span,h1,h2,h3,h4,h5,h6,u,i,li,td').each(function(){
            var size = $(this).data('default-size');
            size = size * ni_fontresizer.config['size'+type];
            $(this).css('font-size', size);
        });
    }

    this.def_size = function(){
        this.def = true;
        $('.template-bodyer-bg *').filter('div,a,p,b,strong,span,h1,h2,h3,h4,h5,h6,u,i,li,td').each(function(){
            var size = $(this).css('font-size');
            size = parseFloat(size, 10);
            $(this).data('default-size', size);
        });
    }
}

$(function(){
    ni_fontresizer.init();
});

