function IEHoverPseudo() {
    var navItems = document.getElementById("primary-nav").getElementsByTagName("li");
    for (var i=0; i < navItems.length; i++) {
        if(navItems[i].className == "menuparent") {
            navItems[i].onmouseover=function() {this.className += " over";}
            navItems[i].onmouseout=function() {this.className = "menuparent";}
        }
    }
}
window.onload = IEHoverPseudo;


jQuery.noConflict();

jQuery(document).ready(function($){
    var root = $('a#url').text();
    var fontsize = $('a#fontsize').text();

    $('div#left_advert div').css('width', '100%');
    $('div#left_advert').cycle({
        timeout: 5000,
        speed: 1000,
        cssBefore: {
            width: '100%'/*,
            opacity: 0,
            display: 'block'*/
        },
        cssAfter: {
            width: '100%'/*,
            opacity: 0,
            display: 'none'*/
        }
    });

    var $elements = 'div#right, div#right div.tekst, div#right p, div#right span';
    var $lelements = '#right div';
    if(fontsize != '') {
        $($elements).css('font-size', fontsize+'px');
    }
    // --------- zwiększ czcionkę ----------------------------------------------
    $('a#font_plus').click(function(){
        var currentFontSize = $($elements).css('font-size');
        var divCurrentLineHeight = $('#right div.txt').css('line-height');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var divCurrentLineHeightNum =parseFloat(divCurrentLineHeight, 10);
        var newFontSize = parseInt(currentFontSizeNum+1);
        var newDivLineHeight = divCurrentLineHeightNum +(newFontSize - currentFontSizeNum);
        $($elements).css('font-size', newFontSize);
        $($lelements).css('line-height',newDivLineHeight +'px');
        $.get(root+'index.php', {model: "index", action: "font", size: newFontSize} );
        return false;
    });
    // --------- zmniejsz czcionkę ---------------------------------------------
    $('a#font_minus').click(function(){
        var currentFontSize = $($elements).css('font-size');
        var divCurrentLineHeight = $('#right div.txt').css('line-height');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var divCurrentLineHeightNum =parseFloat(divCurrentLineHeight, 10);
        if(currentFontSizeNum > 1)
            var newFontSize = parseInt(currentFontSizeNum-1);
        else
            var newFontSize = currentFontSizeNum;
        var newDivLineHeight = divCurrentLineHeightNum +(newFontSize - currentFontSizeNum);
        $($elements).css('font-size', newFontSize);
        $($lelements).css('line-height',newDivLineHeight +'px');
        $.get(root+'index.php', {model: "index", action: "font", size: newFontSize} );
        return false;
    });
    // -------------------------------------------------------------------------

    // --------- galeria - miniaturki ------------------------------------------
    $('a.gallery_min').click(function(){
        var url = $(this).attr('href');
        var title = $(this).attr('title');
        $('div#gallery_big').html('<img src="'+url+'" alt="'+title+'"/><div style="padding: 5px; text-align: center; font-weight: bold">'+title+'</div>');
        return false;
    });
    $('div.gallery_next a').click(function(){
        $(this).parent().parent('div.gallery_slider').hide();
        var iter = $(this).parent().parent('div.gallery_slider').attr('id').replace('gal_','');
        $('div#gal_'+parseInt(parseInt(iter)+1)).show();
        return false;
    });
    $('div.gallery_prev a').click(function(){
        $(this).parent().parent('div.gallery_slider').hide();
        var iter = $(this).parent().parent('div.gallery_slider').attr('id').replace('gal_','');
        $('div#gal_'+parseInt(parseInt(iter)-1)).show();
        return false;
    });

    // --------- strona główna - zakładki --------------------------------------
    $('a.tab').live('click', function(){
        var id = $(this).attr('id').replace('tab','');
        $('a.tab').removeClass('sel');
        $(this).addClass('sel');
        $('div.main_box_content').hide();   
        $('a.show_all').hide();
        $('div#content'+id).show();
        $('a#show_all'+id).show();
        return false;
    });

    // --------- strona główna - aktualności -----------------------------------
    $('a.lista_a').live('hover', function(){
        var id = $(this).attr('id').replace('news_','');
        $('div.news_foto').hide();
        $('div.news_tekst').hide();
        $('div#news_foto_'+id).show();
        $('div#news_tekst_'+id).show();
        $('a.lista_a_sel').removeClass('lista_a_sel').addClass('lista_a');
        $(this).removeClass('lista_a').addClass('lista_a_sel');
    });
    // --------- strona główna - galerie ---------------------------------------
    $('a.glista_a').live('hover', function(){
        var id = $(this).attr('id').replace('gal_','');
        $('div.gal_foto').hide();
        $('div.gal_tekst').hide();
        $('div#gal_foto_'+id).show();
        $('div#gal_tekst_'+id).show();
        $('a.glista_a_sel').removeClass('glista_a_sel').addClass('glista_a');
        $(this).removeClass('glista_a').addClass('glista_a_sel');
    });
    // --------- strona główna - o nas -----------------------------------------
    $('a.slista_a').live('hover', function(){
        var id = $(this).attr('id').replace('site_','');
        $('div.site_foto').hide();
        $('div.site_tekst').hide();
        $('div#site_foto_'+id).show();
        $('div#site_tekst_'+id).show();
        $('a.slista_a_sel').removeClass('slista_a_sel').addClass('slista_a');
        $(this).removeClass('slista_a').addClass('slista_a_sel');
    });

    // --------- 1 % - film ----------------------------------------------------
    $('div#procent_overlay').bgiframe();

    function procentPosition(){
        var offs = ( $(window).scrollTop() );
        var heig = ( $('body').innerHeight() );
        $('div#procent_content').css( 'top', parseInt(offs+parseInt(heig/2-200))+'px' );
        $('div#procent_content').css( 'left', parseInt( $('div#procent').innerWidth()/2-250)+'px' );
    }
    procentPosition();
    $('a#zobacz_ulotke').click(function(){
        $('div#procent').show();
        procentPosition();
        return false;
    })
    $('a#schowaj_ulotke').click(function(){
        $('div#procent').hide();
        $.get(root+'index.php', {model: "index", action: "jedenprocent"} );
        return false;
    })

   // ------------ FACEBOOK -------------------------------
    $("#wysuwany_div").mouseover(function() {
        $("#wysuwany_div").stop();
        $("#wysuwany_div").animate({
            top: "0",
        },260
        );
    });
    $("#wysuwany_div").mouseout(
        function() {
            $("#wysuwany_div").stop();
            $("#wysuwany_div").animate({
                top: "-260",
            }, 260
            );
        });

});
