function doButtons(bid){
    if($("#"+bid).attr("id")=='b1'){var le=0;}
    if($("#"+bid).attr("id")=='b2'){var le=-142;}
    if($("#"+bid).attr("id")=='b3'){var le=-282;}
    var tid=$("#"+bid).attr("id");
    $("#"+bid).animate({
        backgroundPosition: le+"px -40px"
    },300);
    $(".slide-b").each(function(){
        if($(this).attr("id")=='b1'){var le=0;}
        if($(this).attr("id")=='b2'){var le=-142;}
        if($(this).attr("id")=='b3'){var le=-282;}
        if($(this).attr("id")==tid){var to=-40;}else{var to=0;}
        $(this).animate({
            backgroundPosition: le+"px "+to+"px"
        },300);
    })
}
function doBanners(bid){
    if($("#ban-b1").css("opacity")>0){$("#ban-b1").fadeOut("300")}
    if($("#ban-b2").css("opacity")>0){$("#ban-b2").fadeOut("300")}
    if($("#ban-b3").css("opacity")>0){$("#ban-b3").fadeOut("300")}
    $("#"+bid).fadeIn("300");
}
var dos=true;
function doSlide(kery){
    if(dos===true){
        if(kery==4){kery=1;}
        setTimeout(function(){
            doBanners("ban-b"+kery);
            doButtons("b"+kery);
            setTimeout(function(){
                doSlide(kery+1);
            },3000);
        },3000);
    }
}
$(document).ready(function(){
    $(".mail").each(function(){
        $(this).html($(this).html().replace(/.%małpka%./g,"@"));
    })
    setTimeout(function(){
        doSlide(2);
    },3000);
    var wartosci_form=new Array();
    $(":input").each(function(){
        var wartosc=$(this).val();
        wartosci_form[$(this).attr('name')]=wartosc;
        $(this).focus(function(){
            if($(this).val()==wartosc){
                $(this).val('');
            }
        });
        $(this).blur(function(){
            if($(this).val()==''){
                $(this).val(wartosc);
            }
        });
    });
    $("#send_form").click(function(){
        var p=0;
        $(":input").each(function(){
            if($(this).attr('type')!='hidden' && $(this).attr('type')!='submit'){
                if($(this).val()==wartosci_form[$(this).attr('name')]){       
                    if($(this).attr('type')=='checkbox' && $(this).is(':checked')==1) {
                        $(this).val('1');
                    }else{
                        $(this).val('');
                    }
                }
                if($(this).attr('name')=='email'){
                    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
                    if(reg.test($(this).val()) == false){$(this).val('');}
                }
                if($(this).val()==''){
                    var nazw=wartosci_form[$(this).attr('name')].replace(":","").replace("...","");
                    $(this).focus();
                    alert("Proszę wypełnić wymagane pole - '"+nazw+"'!");
                    p++;
                    return false;
                }
            }
        });
        if(p>0) {
            return false;
        }
    });

    //taby
    $(".tabs").click(function(){
        $(".tabs").each(function(){
            if(typeof($(this).css('background-position'))==='undefined'){
                $(this).css('background-position-y','bottom');
            }else{
                $(this).css("background-position",$(this).css("background-position").replace(" 0%"," bottom").replace(" 0px"," bottom"));
            }
        })
        if(typeof($(this).css('background-position'))==='undefined'){
             $(this).css('background-position-y','top');
        }else{
            $(this).css("background-position",$(this).css("background-position").replace(" bottom"," 0px").replace(" 100%"," 0px"));
        }
        $(".teksty").hide();
        $('#'+$(this).attr('id')+'-text').show();
    })

    $(".slide-b").click(function(){
        doBanners("ban-"+$(this).attr("id"));
        doButtons($(this).attr("id"));
        dos=false;
    })
    $("#click_cs").click(function(){
        window.open("http://www.cstore.pl");
    })

    $("#click_sms").click(function(){
        window.open("http://www.smsapi.pl");
    })
});
