// wymaga prototype.js
// wymaga common.js

/*  
 uzywanie

 na poczatku strony:
    <script type="text/javascript" src="js/tabs.js"></script> 
 
 w funkcji begin() nalezy dodac: 
    tabs.init();
    
 <div id="tabs">
    <div title="tytul_zakladki" class="tab"> tresc zakladki </div>
 </div>     
*/ 

var tabs = {
    divs : null,
    container : null,
    count : null,
    
    init : function() 
    {
        this.container = $('tabs');
        this.divs = getElementsByClass( 'tab', this.container, 'div' );
        
        this.count = this.divs.length;
        if ( this.count < 1 )
            return;
        var headers = '';
        
        for (var i=0; i < this.count; i++)
        { 
                headers += '<a href="#dd" id="header_' +i+ '" class="tabHeader" onclick="tabs.toggle('+i+');">' + this.divs[i].title + '</span>';                                 
        }
        
        new Insertion.Top( this.container, headers);
        this.toggle(0);    
    },
    
    toggle : function(n) 
    {
        for (var i=0; i < this.count; i++)
        {
            tabs.divs[i].style.display = 'none'; 
            $('header_'+i).className = 'tabHeader';                                   
        }  
         $('header_'+n).className = 'tabActive';
        tabs.divs[n].style.display = ''; 
        tabs.divs[n].blur(); 
    }
};

var tabs2 = {
    divs2 : null,
    container2 : null,
    count2 : null,
    
    init : function() 
    {
        this.container2 = $('tabs2');
        this.divs2 = getElementsByClass( 'tab2', this.container2, 'div' );
        
        this.count2 = this.divs2.length;
        if ( this.count2 < 1 )
            return;
        var headers2 = '';
        
        for (var k=0; k<this.count2; k++)
        { 
                headers2 += '<a href="#zak" id="header_' +k+ '" class="tabHeader" onclick="tabs2.toggle('+k+');">' + this.divs2[k].title + '</span>';                                 
        }
        
        new Insertion.Top( this.container2, headers2);
        this.toggle(0);    
    },
    
    toggle : function(m) 
    {
        for (var k=0; k<this.count2; k++)
        {
            tabs2.divs2[k].style.display = 'none'; 
            $('header_'+k).className = 'tabHeader';                                   
        }  
        $('header_'+m).className = 'tabActive';
        tabs2.divs2[m].style.display = ''; 
        tabs2.divs2[m].blur(); 
    }
};

