window.onload = function(){
    $('#top-banner ul').cycle({
        fx:     'fade',
        speed:  '400',
        timeout: 0,
        pager: '.pager'
    });
    $('#tbanner ul').cycle({
        fx:     'scrollRight',
        speed:  '700',
        timeout: 0,
        pager: '.tpager'
    });
    $('#bbanerl ul').cycle({
        fx:     'scrollLeft',
        speed:  '400',
        timeout: 0,
        pager: '.pagerl'
    });
    $('#bbanerr ul').cycle({
        fx:     'scrollRight',
        speed:  '400',
        timeout: 0,
        pager: '.pagerr'
    });
}
$(document).ready(function () {
    $("input.autocomplete").each( function () {
        $(this).autocomplete('smartsearch.php', {
            minChars: 2,
            max: 50,
            width: $(this).width(),
            selectFirst: false
        } );
    });
    $('#search input.input-text').focus();
    if($.browser.msie){
        $('#top ul li:last-child a').hover(
            function(){
                $(this).css('padding','4px 20px 5px 21px');
            },
            function(){
                $(this).css('padding','4px 20px 5px 22px');
            }
            );
    }
    
    $("#top ul li:first-child").addClass("i1");
    $("#cats .mlist .pos:nth-child(4n)").addClass("remove");
    $(".prods ul li:nth-child(4n)").addClass("remove");
    $("#data-rotate .prods ul li:nth-child(4n)").addClass("remove");
    $("#data-nav li a").click(function() {
        var curList = $("#data-nav li a.current").attr("rel");
        var curListHeight = $("#data-rotate").height();
        $("#data-nav li a").removeClass("current");
        $(this).addClass("current");
        var listID = $(this).attr("rel");
        if (listID != curList) {
            $("#"+curList).fadeOut(0, function() {
                $("#"+listID).fadeIn();
                var newHeight = $("#"+listID).height();
            });
        }        
        return false;
    });		

    $("#reg-nav li a").click(function() {
        var curList = $("#reg-nav li a.current").attr("rel");
        var curListHeight = $("#reg-rotate").height();
        $("#reg-nav li a").removeClass("current");

        $(this).addClass("current");
		
        var listID = $(this).attr("rel");
        if (listID != curList) {
            $("#"+curList).fadeOut(0, function() {
                $("#"+listID).fadeIn();
                var newHeight = $("#"+listID).height();
            });
        }        
        return false;
    });
    if($('#main span.pagination_buttons').html() != undefined){
        var $pagination_buttons = $('#main span.pagination_buttons');
        $pagination_buttons.find('b').addClass('current');
        $pagination_buttons.html(
            $pagination_buttons.html()
            .replace(/\[\s|\s\]/g,'')
            .replace(/\<b/gi,'<a')
            .replace(/\<\/b\>/gi,'</a>')
            .replace(/\<\u\>|\<\/\u\>/gi,'')
            .replace(/\|/gi,'<span class="separator">|</span>')
            );
        $pagination_buttons.find('.current').attr('href','#');
    }
    $topText = $('#main .top_text');
    if($('#main div.mcnt ul').html() != undefined){
        $('#main div.mcnt ul:first-child').before($topText.css({'position':'static','padding':'0'}));
    }
    
    if($('#main div.no_products').html() != undefined){
        $topText.css('position', 'static');
        $('#lista_produktow').css('background-color','#fff');
    }
    //ukrywanie/pokazywanie kategorii w menubx
    if($('#sub').html() != undefined){
        i = 0;
        $('#sub .ctable_menubox_category div,#sub .ctable_menubox_category li').each(function(){
            if(i > 25){
                $(this).addClass('hidden');
            }
            i++;
        });
    }
    $('#cat-more').click(function() {
        $('#sub .ctable_menubox_category div.hidden,#sub .ctable_menubox_category li.hidden').animate({
            opacity: 'toggle'
        }, 1000, function() {
            });
    });
    if($('#total_price_brutto').html() != undefined){
        $('#total_price_brutto_copy strong').text($('#total_price_brutto strong').text());
        $('#total_price_netto_copy').css('display','block').find('span').text($('#total_price_netto span').text());
    }
    if(document.getElementById('ship_post')!=undefined) {
	    if(document.getElementById('ship_post').style.display == 'none') {document.getElementById('total_price_brutto_copy').innerHTML = '<strong>' + (parseFloat(document.getElementById('total_price_brutto_dynsrc').innerHTML.replace(',','.').replace(new RegExp('&nbsp;','g'),'')) + parseFloat(document.getElementById('hlpg_wys_koszt_' + getCheckedValue(document.getElementsByName('wysylka[0]')).toString()).value)).number_format() + '</strong>';
			document.getElementById('total_price_netto_dyn').innerHTML = (roundNumber(parseFloat(document.getElementById('total_price_netto_dynsrc').innerHTML.replace(',','.').replace(new RegExp('&nbsp;','g'),'')) + parseFloat(document.getElementById('hlpg_wys_koszt_n_' + getCheckedValue(document.getElementsByName('wysylka[0]')).toString()).value),2)).number_format();
			}else{document.getElementById('total_price_brutto_copy').innerHTML = '<strong>' + (parseFloat(document.getElementById('total_price_brutto_dynsrc').innerHTML.replace(',','.').replace(new RegExp('&nbsp;','g'),'')) + parseFloat(document.getElementById('hlp_wys_koszt_' + getCheckedValue(document.getElementsByName('wysylka[1]')).toString()).value)).number_format() + ' </strong>';
			document.getElementById('total_price_netto_dyn').innerHTML = (roundNumber(parseFloat(document.getElementById('total_price_netto_dynsrc').innerHTML.replace(',','.').replace(new RegExp('&nbsp;','g'),'')) + parseFloat(document.getElementById('hlp_wys_koszt_n_' + getCheckedValue(document.getElementsByName('wysylka[1]')).toString()).value),2)).number_format();}
		}
    
});
