(function($) {
    jQuery.fn.pngFix = function(settings) {

        // Settings
        settings = jQuery.extend({
            blankgif: 'blank.gif'
        }, settings);

        var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
        var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);

        if (jQuery.browser.msie && (ie55 || ie6)) {

            //fix images with png-source
            jQuery(this).find("img[src$=.png]").each(function() {

                jQuery(this).attr('width',jQuery(this).width());
                jQuery(this).attr('height',jQuery(this).height());

                var prevStyle = '';
                var strNewHTML = '';
                var imgId = (jQuery(this).attr('id')) ? 'id="' + jQuery(this).attr('id') + '" ' : '';
                var imgClass = (jQuery(this).attr('class')) ? 'class="' + jQuery(this).attr('class') + '" ' : '';
                var imgTitle = (jQuery(this).attr('title')) ? 'title="' + jQuery(this).attr('title') + '" ' : '';
                var imgAlt = (jQuery(this).attr('alt')) ? 'alt="' + jQuery(this).attr('alt') + '" ' : '';
                var imgAlign = (jQuery(this).attr('align')) ? 'float:' + jQuery(this).attr('align') + ';' : '';
                var imgHand = (jQuery(this).parent().attr('href')) ? 'cursor:hand;' : '';
                if (this.style.border) {
                    prevStyle += 'border:'+this.style.border+';';
                    this.style.border = '';
                }
                if (this.style.padding) {
                    prevStyle += 'padding:'+this.style.padding+';';
                    this.style.padding = '';
                }
                if (this.style.margin) {
                    prevStyle += 'margin:'+this.style.margin+';';
                    this.style.margin = '';
                }
                var imgStyle = (this.style.cssText);

                strNewHTML += '<span '+imgId+imgClass+imgTitle+imgAlt;
                strNewHTML += 'style="position:relative;white-space:pre-line;display:inline-block;background:transparent;'+imgAlign+imgHand;
                strNewHTML += 'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;';
                strNewHTML += 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + jQuery(this).attr('src') + '\', sizingMethod=\'scale\');';
                strNewHTML += imgStyle+'"></span>';
                if (prevStyle != ''){
                    strNewHTML = '<span style="position:relative;display:inline-block;'+prevStyle+imgHand+'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;'+'">' + strNewHTML + '</span>';
                }

                jQuery(this).hide();
                jQuery(this).after(strNewHTML);

            });

            // fix css background pngs
            jQuery(this).find("*").each(function(){
                var bgIMG = jQuery(this).css('background-image');
                if(bgIMG.indexOf(".png")!=-1){
                    var iebg = bgIMG.split('url("')[1].split('")')[0];
                    jQuery(this).css('background-image', 'none');
                    jQuery(this).get(0).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + iebg + "',sizingMethod='scale')";
                }
            });

            //fix input with png-source
            jQuery(this).find("input[src$=.png]").each(function() {
                var bgIMG = jQuery(this).attr('src');
                jQuery(this).get(0).runtimeStyle.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + bgIMG + '\', sizingMethod=\'scale\');';
                jQuery(this).attr('src', settings.blankgif)
            });

        }

        return jQuery;

    };

})(jQuery);

/**
 *  jquery.popupt
 *  (c) 2008 Semooh (http://semooh.jp/)
 *
 *  Dual licensed under the MIT (MIT-LICENSE.txt)
 *  and GPL (GPL-LICENSE.txt) licenses.
 *
 **/
(function($){
    $.fn.extend({
        imghover: function(opt){
            return this.each(function() {
                opt = $.extend({
                    prefix: '',
                    suffix: '_o',
                    src: '',
                    btnOnly: true,
                    fade: false,
                    fadeSpeed: 500
                }, opt || {});

                var node = $(this);
                if(!node.is('img')&&!node.is(':image')){
                    var sel = 'img,:image';
                    if (opt.btnOnly) sel = 'a '+sel;
                    node.find(sel).imghover(opt);
                    return;
                }

                var orgImg = node.attr('src');

                var hoverImg;
                if(opt.src){
                    hoverImg = opt.src;
                }else{
                    hoverImg = orgImg;
                    if(opt.prefix){
                        var pos = hoverImg.lastIndexOf('/');
                        if(pos>0){
                            hoverImg = hoverImg.substr(0,pos-1)+opt.prefix+hoverImg.substr(pos-1);
                        }else{
                            hoverImg = opt.prefix+hoverImg;
                        }
                    }
                    if(opt.suffix){
                        var pos = hoverImg.lastIndexOf('.');
                        if(pos>0){
                            hoverImg = hoverImg.substr(0,pos)+opt.suffix+hoverImg.substr(pos);
                        }else{
                            hoverImg = hoverImg+opt.suffix;
                        }
                    }
                }

                if(opt.fade){
                    var offset = node.offset();
                    var hover = node.clone(true);
                    hover.attr('src', hoverImg);
                    hover.css({
                        position: 'absolute',
                        left: offset.left,
                        top: offset.top,
                        zIndex: 1000
                    }).hide().insertAfter(node);
                    node.mouseover(
                        function(){
                            var offset=node.offset();
                            hover.css({
                                left: offset.left,
                                top: offset.top
                            });
                            hover.fadeIn(opt.fadeSpeed);
                            node.fadeOut(opt.fadeSpeed,function(){
                                node.show()
                            });
                        }
                        );
                    hover.mouseout(
                        function(){
                            node.fadeIn(opt.fadeSpeed);
                            hover.fadeOut(opt.fadeSpeed);
                        }
                        );
                }else{
                    node.hover(
                        function(){
                            node.attr('src', hoverImg)
                        },
                        function(){
                            node.attr('src', orgImg)
                        }
                        );
                }
            });
        }
    });
})(jQuery);

$(document).ready(function(){
    var wait="<img src=\"/Lay/centr/ajax.gif \" alt=\"czekaj\"/>";
    $(document).pngFix();
    $('img.hov').imghover({
        suffix: '2'
    });
    if (document.getElementById('DzialyTree')!=null) {
        $('#DzialyTree li:has(li)>img').attr('src','/Lay/min/plus2.gif').toggle(function(){
            $(this).attr('src','/Lay/min/minus2.gif');
            $(this).closest('li').children('ul').show('fast');
        }, function(){
            $(this).attr('src','/Lay/min/plus2.gif');
            $(this).closest("li").children('ul').hide('fast');
        //event.stopPropagation();
        });
        $('#DzialyTree ul ul').hide();
    }
    if (document.getElementById('NavPath_up')!=null){
        $('span.LstZadParr').css('cursor','pointer').toggle(function(){
            $(this).children("img").attr('src','/Lay/min/plus2.gif');
            $(this).next('div.LstZadParr').hide('fast');
            $(this).children("span.ParrTxt").replaceWith('<span class=\"ParrTxt\">Podobne zadania</span>');
        }, function(){
            $(this).children("img").attr('src','/Lay/min/minus2.gif');
            $(this).next('div.LstZadParr').show('fast');
            $(this).children("span.ParrTxt").replaceWith('<span class=\"ParrTxt\">Ukryj</span>');
        });
        $('span.LstZadParr').click();        
    }
    if (document.getElementById('feedback')!=null) {        
        $('#feedback form').submit(function(){            
            if ($('#feedback textarea[name=feed]').val()=="") return false;
            $.post('/feedback',$(this).serialize(),function(data) {
                $('#feedback').html(data);                
            });
            $('#feedback').html(wait);
            return false;
        });
    }    
    if (document.getElementById('RadP')!=null) {
        $('#RadR,#RadOR,#RadRH').click(function(){
            $('span.P').addClass("R").removeClass("P");
            $('#Generator div.P').addClass("R").removeClass("P");
        });
        $('#RadP,#RadZ,#RadOP,#RadPH').click(function(){
            $('span.R').addClass("P").removeClass("R");
            $('#Generator div.R').addClass("P").removeClass("R");
        });
        $('select').change(function(){
            $(this).prev().prev().trigger('click'); //.attr('checked', true);;
        });
    }

    $("#Generator form").submit(function()
    { 
        //alert ("Please select at least one selector: "+$("input[type='checkbox']:checked").length);
        if ($("input[type='checkbox']:checked").length==0) return false;
        else return true;
    });

    $("#RandRozButt").click(function(event){
        event.preventDefault(); //stop default browser behaviour
        $("#RandRoz").removeClass("RandRozS");
        $("#RandRozButt").addClass("RandRozS");
    //alert("This alert will be displayed without following the link");
    });

    /*$('form.QuickForm').submit(function(){
        if ($('form.QuickForm input[name=username]').val()==""||$('form.QuickForm input[name=password]').val()=="") return false;
        $.post('/login',$(this).serialize(),function(data) {
            if (data!=""){
                $('form.QuickForm').html(data);
            } else
        });
        //$('form.QuickForm').html(wait);
        return false;
    });*/
    $("span.LstZadKreAddZadHov").click(function(){
        var attr=$(this).attr('id').split(".");
        $("#KreBazaBack").data("sp",$("span[id^=ZKRE."+attr[1]+"]"));
        $.post('/zestawK',{
            NrZesB:attr[2],
            AddZadB:attr[1]
        },function(data) {
            var sp=$("#KreBazaBack").data("sp");
            if ($.trim(data.toString())=="error") {
                return;
            } else if ($.trim(data.toString()).substr(0, 6)=="MaxZad"){
                sp.html("<img src=\"/Lay/kreator/ZadError.png\" alt=\"Error\" /><span class=\"KreErr\">Za dużo zadań w zestawie.</span>");
            } else
                sp.html("<img src=\"/Lay/kreator/ZadAdded.png\" alt=\"Added\" />Zadanie dodane do zestawu.");
            sp.unbind("click");
            sp.removeClass("LstZadKreAddZadHov");
        },"html");
        return false;
    });
});    

function payment(typ,X,Y) {
    window.open("/trans/"+typ,"Payment","menubar=no,width="+X+",height="+Y+",toolbar=no,status=no,screenX=70,screenY=50");
//window.location = adr;
}
function test(numer) {
    window.open("/test/t"+numer+"/0","Tester","menubar=no,width=700px,height=550px,toolbar=no,status=no,screenX=120,screenY=120,scrollbars=yes");
//window.open("/test/"+numer+"/0","Rozwi\u0105zujesz zestaw numer "+numer,"menubar=no,width=700px,height=550px,toolbar=no,status=no,screenX=120,screenY=120,scrollbars=yes");
//window.location = adr;
}
/*$(document).ready(function(){
    });*/
