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();
        }
        );
    }
}


function cmp_naslovnica_clanak_auto_sadrzaj( p_app_rewrite_base, p_arr_component_params )
{
    this._url = p_app_rewrite_base  + 'index.php?cmd=ajax_cmp_naslovnica_clanak_auto_sadrzaj',
    this._arr_component_params = p_arr_component_params,
    this.current_index = 0,
    
    this.show_image = function( p_index )
    {
        // sakrij trenutnu
        $( '#' + this._arr_component_params[ 'component_id_prefix' ]  + '_div_auto_clanak_image_' + this.current_index ).hide();
        $( '#' + this._arr_component_params[ 'component_id_prefix' ]  + '_div_auto_clanak_image_' + p_index ).show();

        this.current_index = p_index;
    },

    this.show_preset = function( p_preset_suffix )
    {
        $( '#' + this._arr_component_params[ 'component_id_prefix' ]  + '_div_auto_clanak_content' ).hide();
        $( '#' + this._arr_component_params[ 'component_id_prefix' ]  + '_div_auto_clanak_spinner' ).show();

        var _new_preset = this._arr_component_params[ 'preset_base' ] + '_' + p_preset_suffix;
        this._current_preset = _new_preset;

        var div_prefix = this._arr_component_params[ 'component_id_prefix' ];

        //alert( '#' + div_prefix  + '_div_auto_clanak_content' );
        
        $( '#' + div_prefix  + '_div_auto_clanak_content' ).load( this._url , {
            preset_suffix: p_preset_suffix, 
            preset_base: this._arr_component_params[ 'preset_base' ], 
            limit: this._arr_component_params[ 'limit' ], 
            component_id_prefix: this._arr_component_params[ 'component_id_prefix' ], 
            wrapper_div_class: this._arr_component_params[ 'wrapper_div_class' ],
            fix_content_type: this._arr_component_params[ 'fix_content_type' ],
            alter_template: this._arr_component_params[ 'alter_template' ],
            tag_id: this._arr_component_params[ 'tag_id' ],
            title: this._arr_component_params[ 'title' ],
            header_url: this._arr_component_params[ 'header_url' ]
        }, function()
        {

            //alert( 'tu sam' );
            $( '#' + div_prefix  + '_div_auto_clanak_spinner' ).hide();
            $( '#' + div_prefix  + '_div_auto_clanak_content' ).show();
        }
        );
    }
}


