
// news image slider
var newsSpeed = 4000;
var newsAnimationSpeed = 300;
/*
$(function(){
    var bannerCookie = $.cookie('bannerCookie'); 
    if(bannerCookie == null){
        $.fancybox(
                $(".reklamaDiv").html(),
                {
                        'autoDimensions'	: false,
                        'width'         		: "auto",
                        'height'        		: 'auto',
                        'transitionIn'		: 'none',
                        'transitionOut'		: 'none',
                        onComplete:function(){
                            $.fancybox.resize;
                        }
                }
        );
        $.cookie('bannerCookie', "shown", { expires: 1 });
    }
});
*/
$(function(){
    
    $("#h-news .imgs .img:first").wrap('<span class="first" />');
    
    Cufon.replace('#h-top', {
        textShadow: '1px 1px #000'
    });
    Cufon.replace('#menu>ul>li>a, #search .submit span, #footer p,#h-news .news-more, a.butt1, .butt1 span, .news-single-backlink, .wtgallery_category_seemore a', {
        textShadow: '1px 1px #000'
    });
    Cufon.replace('#topmenu a,#h-news h2 a', {
        hover: true
    });
    Cufon.replace('.box h1');

    if($(".mainpage").length){
        var intervalId = window.setInterval(newsScroll, newsSpeed);
    }
    $("#lang .active").bind("click", function(){
        if($.browser.msie) $(this).siblings(".more").toggle();
        else $(this).siblings(".more").slideToggle(100);
    });
    $('body').bind("click",function (){
        if($.browser.msie) $("#lang .more").hide();
        else $("#lang .more").slideUp(100);
    });
    $('#lang .active').bind("click",function(event){
        event.stopPropagation();
    });


    $("#searchinput").bind({
        focus: function (){
            if(!$_GET('L') || $_GET('L')==0){
                if(this.val()=="Wpisz wyszukiwana fraze...")
                    this.val("");
                alert("hura");
            } else {
                if(this.val()=="Enter search phrase...")
                    this.val("");                
            }
        },
        blur: function (){
        ;
        }
    });

    $("a[rel=gallery]").fancybox({
        'transitionIn' : 'none',
        'transitionOut' : 'none',
        'titlePosition' : 'over',
        'titleFormat'       : function(title) {
            return '<span id="fancybox-title-over">' + title + '</span>';
        }
    });
});

function newsScroll(){
    var imgs = $("#h-news .imgs");
    var attr0 = imgs.find(".img:eq(0) img").attr("src");
    var n =  imgs.find(".img").length;
    imgs.find(".img img").hide();
    for(var i=0;i<n;i++){
        imgs.find(".img:eq("+i+") img").attr("src" , imgs.find(".img:eq("+(i+1)+") img").attr("src"));
    }
    imgs.find(".img:eq("+(n-1)+") img").attr("src",attr0);
    imgs.find(".img img").fadeIn(newsAnimationSpeed);
}

function dbug(msg){
    //
    // Debug window wrote by Wojciech Gorecki (wojciech.gorecki@gmail.com)
    //

    ////////// Edit variables below only:

    // show time when message is sent
    var showTime = 1;

    // width
    var w1 = 300;
    var w2 = 500;

    // height
    var h1 = 150;
    var h2 = 450;

    // horizontal position. Only 'left' and 'right' allowed
    var posX = 'right';

    // vertical position (percent)
    var posY = "0%";
    
    /////////////////////////////////////

    if(!$("#lst-dbg").length){
        var w = new Array(w1, w2);
        var h = new Array(h1, h2);
    }

    var time='';
    if(showTime){
        var curDate = new Date();
        time = curDate.getHours() +':'+ curDate.getMinutes() +':'+ curDate.getSeconds();
    }
    if(!$("#lst-dbg").length){
        $("body").prepend('\n\
            <div id="lst-dbg" style="position: fixed; top: '+posY+'; '+posX+': 0; display:none; z-index:9999; font-size: 11px;">\n\
                <div id="lst-dbg-nav" style="float:'+posX+';">\n\
                    <a onclick="$(this).parent().next().width(-$(this).parent().next().width()+'+parseInt(w[0]+w[1])+'); return false;">[&lt;]</a>\n\
                    <a onclick="$(this).parent().next().height(-$(this).parent().next().height()+'+parseInt(h[0]+h[1])+'); return false;">[v]</a>\n\
                    <a onclick="$(this).siblings(\'#lst-dbg-switch\').children(\'b\').html(\'0\').parent().parent().next().html(\'\'); return false;">[clear]</a>\n\
                    <a onclick="$(this).parent().next().toggle(); return false;" id="lst-dbg-switch">[toggle] (<b></b>)</a>\n\
                </div>\n\
                <div id="lst-dbg-inner" style="overflow: auto; border: 1px solid; background: #fff; height:'+h[0]+'px; clear:both; float:'+posX+'; width: '+w[0]+'px; padding: 10px;"></div>\n\
            </div>\
        ');
    }
    $("#lst-dbg").show();
    $("#lst-dbg-inner").prepend(time+'<div style="padding:0 10px 3px;margin:0;font-weight: bold;">'+msg+"</div>").scrollTop(0);
    $("#lst-dbg-switch b").html($("#lst-dbg-inner").children().length);
}
