//
////// funkcja przełączająca newsa na wartośc w parametrze
var show_nr = 1;
function show_news( nr, start_timeout )
{
    if( nr == -1)
        nr = show_nr;
    else
        show_nr = nr;

    $('#news1 .tab-content').hide();
    $('#news-'+nr+'-desc').show();

    var i =0;

    $(".news-tabs li").removeClass('active');
    $(".news-tabs li").eq(nr-1).addClass('active');

    $('#button-'+nr+' img').attr("src", '/images/design/'+nr+'-a.png');

    var next = nr%$(".news-tabs li").size() + 1;

    show_nr = next;

    if( start_timeout )
        setTimeout('show_news(-1, true)', 6000);
}

$(document).ready(function() {

    //ukryj/pokaż blok logowania w nagłówku strony
    $('#login-button').click(function(){
        $('#login-box').slideToggle('1500');
    });


    // wyswietlanie okna z dokumentami dla konkretnej firmy
    jQuery(".company_doc").live('click', function() {

        var t = this.id.split('_');
		
        jQuery('#dialog').dialog('option', 'title', 'Dokumenty dla '+ $(this).attr('alt') );
        $('.dokumenty.ui-dialog').css({
            position:"fixed",
            top: "0px"
        });

        jQuery('#dialog').html('<img src="/images/jquery-ui/ajax-loader.gif" class="ajax-loader"/>&nbsp;Wczytywanie...');
		
        $('#dialog').dialog('open');
		
        $('.dokumenty.ui-dialog').css({
            top: "20px"
        });
		
        jQuery.ajax({
            type: "POST",
            url: "fp/docs",
            data: "fcompany_id="+t[1],
            success: function(list){
                jQuery('#dialog').html( list );
            }
        });
		
        return false;
    });
	
    jQuery(".bcstat").live('click', function() {

        var t = this.id.split('_');

        jQuery('#statdialog').dialog('option', 'title', 'Statystyki' );

        jQuery('#statdialog').html('<img src="/images/jquery-ui/ajax-loader.gif" class="ajax-loader"/>&nbsp;Wczytywanie...');
		
        $('#statdialog').dialog('open');

        jQuery.ajax({
            type: "POST",
            url: "bcompanystat/index",
            data: "id="+t[1],
            success: function(list){
                jQuery('#statdialog').html( list );
            }
        });
		
        return false;
    });

    // wyswietlanie okna z opisem konkretnej firmy
    jQuery(".companydb-details-link a").live('click', function() {

        jQuery('#dialog').dialog('option', 'title', $(this).attr('title') );

        jQuery('#dialog').html('Wczytywanie...');
        $('#dialog').dialog('open');

        jQuery.ajax({
            type: "POST",
            url: $(this).attr('href'),
            success: function(list){
                jQuery('#dialog').html( list );
            }
        });
        return false;
    });

    $('a[name^=details]').click(function(){
        $('#hidden'+this.name).toggle();
    });

    //klikniecie w zakładke newsa
    $('a.news-button').click(function(){
        var t = this.id.split('-');
        show_news(t[1], false);
        return false;
    });

    $('a.stock-link').click(function(){
        var t = this.id.split('-');
        $('div.stock-content').hide();
        $('#stock-'+t[1]+'-content').show();

        $(".stock-link").removeClass('active');
        $(".stock-link").eq(t[1]-1).addClass('active');
		
        return false;
    });

    //czasowe przelaczanie newsow
    if($('#news1').length)
        show_news(-1, true);

    //scroll po wyszukaniu wyników
    if($("#formularz").length){
        $("#formularz").submit(function() {
            $(document).scrollTop(890);

            });
    }

    if($('#pf-loader').length){
         $('#pf-bt-search').click(function(){
            $("#pf-loader").show();
            $(".search-reasults-box").html('');
        });

        $("#pf-loader").ajaxSuccess(function(event,request, settings){
            $(this).hide();
        });
    }

}); 
