
function drzewo_inicjuj(nazwa,id,tryb){
    switch(tryb){
        case "rozwiniete":
            jQuery("#zawartosc_"+nazwa+id).show();
            jQuery("#zwin_"+nazwa+id).show();
            jQuery("#rozwin_"+nazwa+id).hide();
            break;
        case "zwiniete":
        default:
            jQuery("#zawartosc_"+nazwa+id).hide();
            jQuery("#zwin_"+nazwa+id).hide();
            jQuery("#rozwin_"+nazwa+id).show();
            break;
    }
}

function drzewo_pokaz(nazwa,id,tryb) {
    switch(tryb){
        case "slide":
            jQuery("#zawartosc_"+nazwa+id).slideDown("slow");
            jQuery("#zwin_"+nazwa+id).show();
            jQuery("#rozwin_"+nazwa+id).hide();
            break;
        case "fade":
            jQuery("#zawartosc_"+nazwa+id).fadeIn("slow");
            jQuery("#zwin_"+nazwa+id).show();
            jQuery("#rozwin_"+nazwa+id).hide();
            break;
        case "show":
        default:
            jQuery("#zawartosc_"+nazwa+id).show("slow");
            jQuery("#zwin_"+nazwa+id).show();
            jQuery("#rozwin_"+nazwa+id).hide();
            break;
    }
}

function drzewo_ukryj(nazwa,id,tryb){	
    switch(tryb){
        case "slide":
            jQuery("#zawartosc_"+nazwa+id).slideUp("slow");
            jQuery("#zwin_"+nazwa+id).hide();
            jQuery("#rozwin_"+nazwa+id).show();
            break;
        case "fade":
            jQuery("#zawartosc_"+nazwa+id).fadeOut("slow");
            jQuery("#zwin_"+nazwa+id).hide();
            jQuery("#rozwin_"+nazwa+id).show();
            break;
        case "show":
        default:
            jQuery("#zawartosc_"+nazwa+id).hide("slow");
            jQuery("#zwin_"+nazwa+id).hide();
            jQuery("#rozwin_"+nazwa+id).show();
            break;
    }
}

function bezpiecznaNazwa(str) {
    pl = new Array ('ó', 'ą', 'ś', 'ł', 'ż', 'ź', 'ć', 'ń', 'Ó', 'Ą', 'Ś', 'Ł', 'Ż', 'Ź', 'Ć', 'Ń', ' ');
    un = new Array ('o', 'a', 's', 'l', 'z', 'z', 'c', 'n', 'O', 'A', 'S', 'L', 'Z', 'Z', 'C', 'N', '_');
    tmp = Array()
    for(i=0; i<str.length;i++){
        tmp[i] = str.charAt(i)
        for(j=0; j < pl.length;j++){
            if(str.charAt(i)==pl[j])
                tmp[i] = un[j]
        }
    }
    return tmp.join().replace(/([^A-z0-9._-])/g, '')
}

function pokazYoutube(){
    jQuery("a[href^=http://www.youtube.com/watch]").each(function(i){
        elem = this.href;
        ref = elem.replace("http://www.youtube.com/watch?v=","")
        jQuery("a[href="+elem+"]").replaceWith('<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/'+ref+'&hl=pl&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+ref+'&hl=pl&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>');
    });
}

function disableSelection(target){
    if (typeof target.onselectstart!="undefined") //IE route
        target.onselectstart=function(){
            return false
            }
    else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
        target.style.MozUserSelect="none"
    else //All other route (ie: Opera)
        target.onmousedown=function(){
            return false
            }
    target.style.cursor = "default"
}

function inicjujGallery(kontener){
    jQuery('ul.galeria_list').galleria({
        history   : true, // activates the history object for bookmarking, back-button etc.
        clickNext : true, // helper for making the image clickable
        insert    : kontener, // the containing selector for our main image
        onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes

            // fade in the image & caption
            if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) { // FF/Win fades large images terribly slow
                image.css('display','none').fadeIn(1000);
            }

            // fetch the thumbnail container
            var _li = thumb.parents('li');

            // fade out inactive thumbnail
            _li.siblings().children('img.selected').fadeTo(500,0.3);

            // fade in active thumbnail
            thumb.fadeTo('fast',1).addClass('selected');

            // add a title for the clickable image
            image.attr('title','Następny obraz >>');
            var baner = jQuery(kontener);
            baner.css('text-align', 'center');
            var r = image.width()/image.height();
            if(image.width()>image.height()){
                var nw = 500;
                var nh = nw/r;
                if(nh>300){
                    nh=300;
                    nw = r*nh;
                }
                image.width(nw);
                image.height(nh);
            }else{
                nh = 300;
                nw = r*nh;
                if(nw>500){
                    nw=500;
                    nh = nw/r;
                }
                image.width(nw);
                image.height(nh);
            }
        },
        onThumb : function(thumb) { // thumbnail effects goes here

            // fetch the thumbnail container

            var _li = thumb.parents('li');
            var oh = thumb.height();
            var ow = thumb.width();
            var ratio = ow/oh;
            //if(thumb.width()>_li.width()){
            if(thumb.width()>thumb.height()){
                thumb.width(45);
                var nh = 45.0/ratio;
                thumb.height(nh)
            }else{
                thumb.height(45);
                var nw = ratio*45;
                thumb.width(nw);
            }
            // if thumbnail is active, fade all the way.
            var _fadeTo = _li.is('.active') ? '1' : '0.3';

            // fade in the thumbnail when finnished loading
            thumb.css({
                display:'none',
                opacity:_fadeTo
            }).fadeIn(1500);

            // hover effects
            thumb.hover(
                function() {
                    thumb.fadeTo('fast',1);
                },
                function() {
                    _li.not('.active').children('img').fadeTo('fast',0.3);
                } // don't fade out if the parent is active
                )
        }
    });

    jQuery('ul.galeria_list').css('display','block');
}
