﻿//dla orginalnego meeting pointu odznaczyc linie:
//76-77
//102-104








(function($) {
    $.fn.extend({
        createSlider: function(type, Classname) {
            var type = type;
            var obj = this;
            var objClass = obj.attr('class');
            
            if (obj.parent().attr('class') == undefined) {
                        
                obj.removeClass();
                obj.css({
                    position: 'absolute'
                })            
                var tmp = $('<div class="' + objClass + '">').addClass(type).addClass(Classname);
                obj.wrap(tmp);
                obj.after('<div class="slider"><div class="handle"></div></div>');
            
            }
            
            $(obj).parent().each(function() {
                var slider = $('.slider', this);
                var productHeight = obj.innerHeight() - $(this).outerHeight();
                if (type == 'vertical') {
                    if (productHeight > 0) {
                        slider.slider({
                            handle: '.handle',
                            minValue: 0,
                            maxValue: productHeight,
                            startValue: 0,
                            slide: function (ev, ui) {
                                obj.css('top', '-' + ui.value + 'px');
                            },
                            stop: function (ev, ui) {
                                obj.animate({'top' : '-' + ui.value + 'px' }, 500, 'linear');
                            }
                        })    
                    } else {
                        slider.css('display', 'none');
                    }
                }
            })
        }
    })
})(jQuery);

var $j = jQuery.noConflict();

var mp = {
    count: 0,
    pos: 0,
    divHeight: 0,
    divOffset: 0,
    trOffset: 0,
    trScroll: 0,
    
    initScroller: function() {
        $j('#aktualnie tr').each(function(i) {
            if ($j(this).hasClass('srodek')) {
                mp.pos = i;
            }
            mp.count = i;        
        })
        
        mp.divHeight = $j('#aktualnie').height();
//        mp.divOffset = $j('#aktualnie').offset().top;
//        mp.trOffset = mp.getTrOffset(mp.pos);
        mp.trScroll = mp.setTrScroll();
        
        mp.addClasses(mp.pos);
        
        $j('#aktualnie .scrollTable').animate({'top': '-=' + mp.trScroll + 'px'}, 'slow');
        
        $j('#top').mousedown(function() {
            if (mp.pos > 0) {
                mp.pos--;
                mp.trOffset = mp.getTrOffset(mp.pos);
                mp.trScroll = mp.setTrScroll();            
                $j('#aktualnie .scrollTable').animate({'top': '-=' + mp.trScroll + 'px'}, 'slow', function(){mp.addClasses(mp.pos);})
            }
        })
        $j('#down').mousedown(function() {
            if (mp.pos < mp.count) {
                mp.pos++;
                mp.trOffset = mp.getTrOffset(mp.pos);
                mp.trScroll = mp.setTrScroll();            
                $j('#aktualnie .scrollTable').animate({'top': '-=' + mp.trScroll + 'px'}, 'slow', function(){mp.addClasses(mp.pos);})
            }
        })
        
    },
//    getTrOffset: function(i) {
//        return $j('#aktualnie .scrollTable tr:eq('+ i +')').offset().top;    
//    },
    setTrScroll: function() {
        var x = mp.trOffset - mp.divOffset - mp.divHeight/2;
        if ($j.browser.msie) x += 10;
        return x;
    },
    
    addClasses: function(i) {
        mp.removeClasses();
        $j('#aktualnie .scrollTable tr:eq('+ i +')').each(function() {
            $j(this).addClass('srodek');
            $j(this).prev().prev().addClass('gora');
			$j(this).prev().addClass('przysrodek');
			/*$j(this).next().addClass('przysrodek');*/
			$j(this).next().addClass('posrodek');
			$j(this).next().next().addClass('dol');
        })    
    },
    removeClasses: function() {
        $j('.scrollTable tr').removeClass();
    },
    
    addSlider: function() {
        $j('#zakladki #tab1').each(function() {
            if ($j(this).parents('div:eq(1)').is(':visible')) {
                $j(this).createSlider('vertical');
            }
        })
        $j('#zakladki #tab2').each(function() {
            if ($j(this).parents('div:eq(1)').is(':visible')) {
                $j(this).createSlider('vertical');
            }
        })
        $j('#zalacznik #tab1').each(function() {
            if ($j(this).parents('div:eq(1)').is(':visible')) {
                $j(this).createSlider('vertical');
            }
        })
        $j('#zalacznik #tab2').each(function() {
            if ($j(this).parents('div:eq(1)').is(':visible')) {
                $j(this).createSlider('vertical');
            }
        })
        $j('#zalacznik #tab3').each(function() {
            if ($j(this).parents('div:eq(1)').is(':visible')) {
                $j(this).createSlider('vertical');
            }
        })
        $j('#zalacznik #tab4').each(function() {
            if ($j(this).parents('div:eq(1)').is(':visible')) {
                $j(this).createSlider('vertical');
            }
        })        
    },
    
    topBookmark: function() {
        var delay = 10;
        $j('#zakladki span[id$="_boczna_tresc_Tekst"]').each(function() {
            $j(this).addClass('zakladka_prawo_lewa');
            $j(this).click(function() {
                setTimeout("$j('#zakladki #tab1').createSlider('vertical');", delay);    
            })
            /*
            $j(this).one('click', function() {
                setTimeout("$j('#zakladki #tab1').createSlider('vertical');", delay);
            })
            */
        })
        $j('#zakladki span[id$="_boczna_tresc_Audio"]').each(function() {
            $j(this).addClass('zakladka_prawo');
            $j(this).click(function() {
                setTimeout("$j('#zakladki #tab2').createSlider('vertical');", delay);    
            })
            /*
            $j(this).one('click', function() {
                setTimeout("$j('#zakladki #tab2').createSlider('vertical');", delay);
            })
            */
        })
    },
    
    attachmentBookmark: function() {
        var delay = 10;
        $j('#zalacznik span[id$="_boczna_tresc_Tekst"]').each(function() {
            $j(this).addClass('zakladka_prawo_lewa');
            $j(this).click(function() {
                setTimeout("$j('#zalacznik #tab1').createSlider('vertical');", delay);    
            })
            /*
            $j(this).one('click', function() {
                setTimeout("$j('#zalacznik #tab1').createSlider('vertical');", delay);
            })
            */
        })
        $j('#zalacznik span[id$="_boczna_tresc_Audio"]').each(function() {
            $j(this).addClass('zakladka_prawo');
            $j(this).click(function() {
                setTimeout("$j('#zalacznik #tab2').createSlider('vertical');", delay);   
            })
            /*
            $j(this).one('click', function() {
                setTimeout("$j('#zalacznik #tab2').createSlider('vertical');", delay);
            })
            */
        })
        $j('#zalacznik span[id$="_boczna_tresc_Video"]').each(function() {
            $j(this).addClass('zakladka_prawo');
            $j(this).click(function() {
                setTimeout("$j('#zalacznik #tab3').createSlider('vertical');", delay);    
            })
            /*
            $j(this).one('click', function() {
                setTimeout("$j('#zalacznik #tab3').createSlider('vertical');", delay);
            })
            */
        })
        $j('#zalacznik span[id$="_boczna_tresc_Foto"]').each(function() {
            $j(this).addClass('zakladka_prawo_prawa');
            $j(this).click(function() {
                setTimeout("$j('#zalacznik #tab4').createSlider('vertical');", delay);    
            })
            /*
            $j(this).one('click', function() {
                setTimeout("$j('#zalacznik #tab4').createSlider('vertical');", delay);
            })
            */
        })
    },
    
    parseHtmlToTextArticle: function() {
        $j('#audycja_tresc .zobacz').each(function() {
            var str = '';
            var moreLink = $j(this).find('.wiecej');
            $j(moreLink).appendTo($j(this).parent());
        })
    },
    
    init: function() {
        this.initScroller();
        this.attachmentBookmark();
        this.topBookmark();
        this.parseHtmlToTextArticle();
        //this.addSlider();
    }
}

$j(function() {
    mp.init();
})

$j(window).load(function () {
    $j('#zakladki #tab1').createSlider('vertical');
    $j('#zalacznik #tab3').createSlider('vertical'); 
    /***************************************************/
    /*_________SCROLLE NA STRONACH RADIA EURO__________*/
    //    jQuery(".BottomScroller ul").cycle({fx: 'cover', speed: 4000, timeout: 10000});
    jQuery('.BottomScroller a').attr({target: "blank"});
    if(jQuery.browser.msie && (jQuery.browser.version.substring(0,1)==6))
    {
        jQuery('.BottomScroller').css('width', '100%');
    }
    if(jQuery.browser.opera)
    {
        jQuery('.BottomScroller ul').css('display', 'inline');
        jQuery('.BottomScroller').css('padding-top', '2px');
        jQuery('.BottomScroller').css('height', '20px');
    }
    jQuery('.BottomScroller ul li').each(function(e) {
        jQuery(this).prepend('<span class="category">&nbsp;' + jQuery(this).attr('class') + '&nbsp;</span> ');
    });
//    alert(jQuery.cookie('BottomScroller'));
        jQuery('.BottomScroller .zwin').toggle(
        function(){
            jQuery('.BottomScroller').animate( { width:"50px"}, 2000);
            jQuery(this).html('').html('<img src="../Images/Layout/rozwin4.GIF" alt="rozwiń" />');
            jQuery.cookie('BottomScroller', 'short', { expires: 1 });
//            alert(jQuery.cookie('BottomScroller'));
        }, 
        function(){
            jQuery('.BottomScroller').animate( { width:"100%"}, 2000);
            jQuery(this).html('').html('<img src="../Images/Layout/zwin4.GIF" alt="zwiń" />');
            jQuery.cookie('BottomScroller', 'long', { expires: 1 });
//            alert(jQuery.cookie('BottomScroller'));
           
//            jQuery(this).text('').text('zwin');
    });
    var marginElemScroll = 75;  //lewy margines scrollowanego elementu
    var screenL = jQuery('.BottomScroller').parent().width(); //szerokosc ekranu
    var elemWdth = jQuery('.BottomScroller ul').width();      //szerokosc listy scrolli
    jQuery('.BottomScroller').css('width', screenL);          //szerokosc przewijanego elementu ustawiamy = szerokosc ekranu
    polKoncowe = "-" + (elemWdth - marginElemScroll) + 'px';    //wartosc do jakiej ma sie przewijac scroller
//    polPoczatkowe = 50 + 'px';
    polPoczatkowe = screenL + 'px';    //polozenie do ktorego ma bys zresetowny margines po wykonaniu scrolla
    function scrollBar() {
        var period = parseInt(elemWdth * 20);
        jQuery('.BottomScroller ul').animate({marginLeft: polKoncowe}, period, setMargin);
    }
    function setMargin() {
        jQuery('.BottomScroller ul').css('margin-left', polPoczatkowe);
        scrollBar();
    }
    scrollBar();
    jQuery('.BottomScroller').hover(function(){jQuery('.BottomScroller ul').stop()}, scrollBar);
    if((jQuery.cookie('BottomScroller')=='long'))
        {
            jQuery('.BottomScroller').css('width', '100%');
            jQuery('.BottomScroller .zwin').html('').html('<img src="../Images/Layout/zwin4.GIF" alt="zwiń" />');
        }
        else if(jQuery.cookie('BottomScroller')=='short')
        {
            jQuery('.BottomScroller').css('width', '50px');
            jQuery('.BottomScroller .zwin').html('').html('<img src="../Images/Layout/rozwin4.GIF" alt="rozwiń" />');
        }
        else
        {
            jQuery('.BottomScroller').css('width', '100%');
            jQuery.cookie('BottomScroller', 'long', { expires: 1 });
//            jQuery('.BottomScroller .zwin').html('').html('<img src="../Images/Layout/zwin4.GIF" alt="zwiń" />');
        }
    /*____________________ KONIEC SCROLLERA ___________________*/
})