
    var Portal = {
        
        /* SuperMastahBrowser fixes */
        ie6fix: function ( png ) {
            /* inputs */
            $('input[type=text]').addClass('text');
            $('input[type=password]').addClass('text');
            $('input[type=checkbox]').addClass('check');
            
            /* transparency */
            png.fix('.download-box h3, .download-box p, .download-options li h2, .download-options li img, .png, .gg-logo, blockquote, .weather-image, .first-child, .description, .fade, .user, .activity, .temp');
        },
        
        
        /*
         * GG BLOG RSS FETCHER
         *********************/
        ggBlogRSS: {
            init: function() {
                $.ajax({
                    url: 'http://s.gadu-gadu.pl/_rssproxy/jsonp/jsoncallback=Portal.ggBlogRSS.process/blog.gadu-gadu.pl/feed',
                    dataType: 'jsonp',
                    jsonp: 'jsonp',
                    cache: true,
                    success: function( feed ) {}
                });
            },
            process: function( feed ) {
                var itemCount = 4;
                
                var processedData = '';
                for( var i = 0; i < itemCount; i++ ) {
                    processedData += '<li><h3><a href="'+ feed.rss.channel.item[i].link +'">'+ feed.rss.channel.item[i].title +'</a></h3></li>';
                }
                
                $('#bottom-promo #blog').html( processedData );
            }
        },
        
        /*
         * HELP PAGE CONTENT FOLDER
         **************************/
        helpFolder: function() {
            $('#komunikator #main-content .inner').find('dd').each( function() {
                $(this).hide();
            });
            $('#komunikator #main-content .inner').find('dt').bind('click', function() {
                var $definition = $(this).next();
                ( $definition.css('display') == 'none' ) ? $definition.fadeIn('fast') : $definition.fadeOut('fast');
            });
        },
        
        /*
         * MOBILE GG TAB SWITCHER
         *********************/
        mobileTabs: {
            clicked: false,
            init: function() {
                var selectedTab = document.location.toString().split('?')[1];
                if( typeof selectedTab != 'undefined' && this.clicked === false ) {
                    this.switchTab( selectedTab );
                }
                $('.mobile-tabs li a').each( function() {
                    $(this).unbind('click');
                    $(this).bind('click', function(e) {
                        e.preventDefault();
                        Portal.mobileTabs.clicked = true;
                        Portal.mobileTabs.switchTab( $(this).attr('class') );
                        Portal.mobileTabs.init();
                    });
                });
                $('.showable a').each( function() {
                    $(this).unbind('click');
                    $(this).bind('click', function(e) {
                        e.preventDefault();
                        Portal.mobileTabs.clicked = true;
                        Portal.mobileTabs.switchTab( $(this).attr('class') );
                        Portal.mobileTabs.init();
                    });
                });
            
            },
            
            switchTab: function( tabName ) {
                // Get tab selected by user
                var $thisTab = $('ul.mobile-tabs').find('a.' + tabName );
                // Get currently active tab (about to change)
                var $currentTab = $('ul.mobile-tabs').find('span');
                // Replace all <span> with links (reset)
                $('.mobile-tabs li span').replaceWith('<a href="#'+ $currentTab.attr('class') +'" class="'+ $currentTab.attr('class') +'">'+ $currentTab.html() +'</a>');
                // Switch current tab to span
                $thisTab.replaceWith('<span class="'+ tabName +'">'+ $thisTab.html() +'</span>');
                // Hide every content
                $('.tabContent').hide();
                // Show current tab content
                $('#' + tabName ).show();
                // GaduAIR is speshul
                ( tabName == 'gaduair' ) ? $('.mobile-tabs').attr('id', 'ga-tabs') : $('.mobile-tabs').attr('id', '');
            }
        },
        
        /*
         * NAGLOS TABS SWITCHER
         **********************/
        naglosTabs: {
            clicked: false,
            init: function() {
                var selectedTab = document.location.toString().split('?')[1];
                if( typeof selectedTab != 'undefined' && this.clicked === false ) {
                    this.switchTab( selectedTab );
                }
                $('.naglos-tabs li a').each( function() {
                    $(this).unbind('click');
                    $(this).bind('click', function(e) {
                        e.preventDefault();
                        Portal.naglosTabs.clicked = true;
                        Portal.naglosTabs.switchTab( $(this).attr('class'), false );
                        Portal.naglosTabs.init();
                    });
                });
                
                $('.big-promo li a').each( function() {
                    $(this).unbind('click');
                    $(this).bind('click', function(e) {
                        e.preventDefault();
                        Portal.naglosTabs.clicked = true;
                        Portal.naglosTabs.switchTab( $(this).attr('class'),$(this).attr('rel') );
                        Portal.naglosTabs.init();
                    });
                });
                /*
                $('.promo .happy-hours a').each( function() {
                    $(this).unbind('click');
                    $(this).bind('click', function(e) {
                        e.preventDefault();
                        Portal.naglosTabs.clicked = true;
                        Portal.naglosTabs.switchTab( $(this).attr('class'),$(this).attr('rel') );
                        Portal.naglosTabs.init();
                    });
                });
                */
                $('#features li a').not('.nojs').each( function() {
                    $(this).unbind('click');
                    $(this).bind('click', function(e) {
                        e.preventDefault();
                        Portal.naglosTabs.clicked = true;
                        Portal.naglosTabs.switchTab( $(this).attr('class'),$(this).attr('rel') );
                        Portal.naglosTabs.init();
                    });
                });
            },
            
            switchTab: function( tabName, column ) {
                // Get tab selected by user
                var $thisTab = $('ul.naglos-tabs').find('a.' + tabName );
                // Get currently active tab (about to change)
                var $currentTab = $('ul.naglos-tabs').find('span');
                // Replace all <span> with links (reset)
                $('.naglos-tabs li span').replaceWith('<a href="#'+ $currentTab.attr('class') +'" class="'+ $currentTab.attr('class') +'">'+ $currentTab.html() +'</a>');
                // Switch current tab to span
                $thisTab.replaceWith('<span class="'+ tabName +'">'+ $thisTab.html() +'</span>');
                // Hide every content
                $('.tabContent').hide();
                if( column != false ) {
                    var $zadarmo = $('#za-darmo');
                    var $zagrosze = $('#za-grosze');
                    
                    if( column == 'za-grosze' ) {
                        $zadarmo
                            .css('padding-right', 0)
                            .css('width', '326px')
                            .css('float','right');
                            
                        $zagrosze
                            .css('width', '295px' )
                            .css('float', 'left' )
                            .css('padding-right', '70px' );
                            
                    } else {
                        $zadarmo.removeAttr('style');
                        $zagrosze.removeAttr('style');
                    }
                }
                // Show current tab content
                $('#' + tabName ).show();
            }
        },

        init: function() {
            
            // Help page content folder
            if( $('body').attr('class') == 'pomoc' ) { this.helpFolder(); }
            
            // Mobile IM tabs switcher
            this.mobileTabs.init();
            
            // Naglos tabs switcher
            this.naglosTabs.init();
            
            // Fetch ggBlog RSS Feed
            if( $('body').attr('class') == 'desktop' || 
            	$('body').attr('class') == 'mobile' ||
            	$('body').attr('class') == 'web'
            ) { 
            	this.ggBlogRSS.init(); 
            }
        }
            
    };
    
    $( function() {
        /* Because some things don't have to be done. */
        var theBrowser = jQuery.browser;
        if (theBrowser.msie == true && theBrowser.version == '6.0') {
            Portal.ie6fix( DD_belatedPNG );
        }
        
        /* Main init */
        Portal.init();
        
        /* Main page SWF animation */
        if( typeof swfobject != 'undefined' && $('#main-gaduair-flash').length > 0 ) {
            swfobject.embedSWF(
                '/swf/animacja_ga_v1.swf', // movie file
                'main-gaduair-flash', // movie id
                '566', // width
                '242', // height
                '9.0', // flash version
                false, // installer
                false, // params
                { name: 'main-gaduair-flash', id: 'main-gaduair-flash', swLiveConnect: 'true', allowScriptAccess: 'always' } // attributes
            );
        }
    });
    
    $(document).ready(function(){
        $("#ahelp1").bind("click", function(e){ $("#help1").toggle("slow");})
        $("#ahelp2").bind("click", function(e){ $("#help2").toggle("slow");})
        $("#helpzadarmo").bind("click", function(e){ $("#za-darmo").toggle("slow");})
        $("#show-tooltip").bind("click", function(e){ $("#cost-tooltip").toggle();})
        if($("a#gg_105_okno_rozmowy").size()){
        	$('#gg_105_wstep_more').bind("click", function(e){
            	e.preventDefault();
            	$("#gg_105_wstep").hide();
            	$("#gg_105_opis").show();
            	$('.scroll-pane').jScrollPane();
            })
            $('#gg_105_opis_close').bind("click", function(e){
            	e.preventDefault();
            	$("#gg_105_opis").hide();
            	$("#gg_105_wstep").show();
            })
            $("a#gg_105_okno_rozmowy").fancybox({
            	'padding'	: 0,
            	'transitionIn' : 'none',
            	'transitionOut' : 'none'
            });
            $("a#gg_105_portal").fancybox({
            	'padding'	: 0,
            	'transitionIn' : 'none',
            	'transitionOut' : 'none'
            });
        }        
    })
