function cmp_naslovnica_glavni_sadrzaj( p_max_items, p_instance_name, p_thumb_switching )
{

    this.current_index = 0,
    this.current_thumb_index = 1;
    this.timer_id = null,
    this.max_items = p_max_items,
    this._instance_name = p_instance_name,
    this._thumb_switching = p_thumb_switching;
    this.paused = false;

    this.show_content = function( p_index, p_reset_timer )
    {
        var _index = p_index;

        var _thumb_index = p_index + 1;
        if( p_index + 1 >= this.max_items ){
            _thumb_index = 0;
        }
        
        // sakrij trenutnu
        $( '#div_nasl_glavni_sadrzaj_main_' + this.current_index ).fadeOut( 50, function()
        {
            $( '#div_nasl_glavni_sadrzaj_main_' + _index ).fadeIn( 'fast' );
        }
        );

        var _old_index = this.current_index;
        var _old_thumb_index = this.current_thumb_index;
        
        if( this._thumb_switching ){
            $( '#div_nasl_glavni_sadrzaj_side_' + _old_thumb_index ).hide();
            $( '#div_nasl_glavni_sadrzaj_side_' + _thumb_index ).show();
            
            $( '#div_nasl_glavni_sadrzaj_position_' + _index ).addClass( 'active' );
            $( '#div_nasl_glavni_sadrzaj_position_' + _old_index ).removeClass( 'active' );
            
        } else {
            $( '#div_nasl_glavni_sadrzaj_side_' + _index ).addClass( 'active' );
            $( '#div_nasl_glavni_sadrzaj_side_' + _old_index ).removeClass( 'active' );
        }

        this.current_index = p_index;
        this.current_thumb_index = _thumb_index;

        if( typeof( p_reset_timer != 'undefined' ) && p_reset_timer ){
            if (!this.paused) {
                this.start_timer();
            }
        }
        //this.start_timer();
    },

    this.show_next_content = function()
    {
        var next_index = this.current_index + 1;
        if( ( next_index + 1 ) > this.max_items ){
            next_index = 0;
        }

        this.show_content( next_index );
    },

    this.start_timer = function()
    {
        if( this.timer_id != null ){
            clearTimeout( this.timer_id );
        }
        if( this._instance_name != null ){
            this.timer_id = setInterval( this._instance_name + '.show_next_content()' , 5000 );
        }

    },
    
    this.stop_timer = function() {
        if( this.timer_id != null ){
            clearTimeout( this.timer_id );
        }
    }

    this.start_slideshow = function()
    {
        this.start_timer();
        $('#gs_play').css({'display':'none'});
        $('#gs_pause').css({'display':'block'});
        this.paused = false;
    }
    
    this.stop_slideshow = function() {
        this.stop_timer();
        $('#gs_play').css({'display':'block'});
        $('#gs_pause').css({'display':'none'});
        this.paused = true;
    }

    if( this.max_items == null ){
        this.max_items = 4;
    }

    if( this._thumb_switching == null ){
        this._thumb_switching = true;
    }
}


function cmp_sportal_overview( p_app_rewrite_base )
{
    this._url = p_app_rewrite_base + 'index.php?cmd=ajax_cmp_sportal_overview';

    this._current_tag = 4; // default

    this.set_tag = function( p_tag )
    {
        $( '#div_sportal_overview').hide();
        $( '#div_sportal_overview_spinner').show();

        $( '#id_sportal_overview_menu_' + this._current_tag ).removeClass( 'active' );
        
        var _new_tag = p_tag;
        this._current_tag = _new_tag;
        
        $( '#div_sportal_overview').load( this._url + '&tag_id=' + p_tag, {}, function()
        {
            $( '#id_sportal_overview_menu_' + _new_tag ).addClass( 'active' );
            
            $( '#div_sportal_overview_spinner').hide();
            $( '#div_sportal_overview').show();
        }
        );
    }
}



