version = navigator.appVersion.toLowerCase();
agent = navigator.userAgent.toLowerCase();
ie = (version.indexOf('msie')>-1);
win = (version.indexOf('windows')>-1);
opera = (agent.indexOf('opera')>-1);
ie50 = (version.indexOf('msie 5.0')>-1);

function prn() {
    document.write(' \074span\076\&bull\;\074/span\076 \074a href=\"javascript:goprn();\"\076Vytisknout stránku\074/a\076');
}
function goprn() {
    window.print();
}
function fav() {
    if ((opera) && (win)) return false;
    else if ((ie) && (win)) document.write(' \074span\076\&bull\;\074/span\076 \074a href=\"javascript:gofav();\"\076Přidat web do záložek\074/a\076');
}
function gofav() {
    window.external.addFavorite('http://www.reptarium.cz/','Reptárium.cz - teraristika a herpetologie');
}

var MyCookie = 
{
    Write:function(name,value,days)
    {
        var D = new Date();
        D.setTime(D.getTime()+86400000*days)
        document.cookie = escape(name)+"="+escape(value)+((days == null)?"":(";expires="+D.toGMTString()))+";path=/";
        return (this.Read(name) == value);
    },
    Read:function(name)
    {
        var EN=escape(name)
        var F=' '+document.cookie+';', S=F.indexOf(' '+EN);
        return S==-1 ? null : unescape( F.substring(EN=S+EN.length+2,F.indexOf(';',EN)) );
    }
}

function ShowAll() {
    $('.tax_collapsible .body').slideDown('fast');
    $('.tax_collapsible').removeClass("collapsed");
}

function HideAll() {
    //  $(".system_hide").slideUp("fast").each( function (i) { MyCookie.Write( this.id , '', -1); });
    $('.tax_collapsible .body').slideUp('fast');
    $('.tax_collapsible').addClass("collapsed");
}

$(document).ready(function() {

    $('#fotoeditor').load(function() {
        var h = 0;

        if (this.contentDocument.getElementById('fotoeditor_upload')) {
            h = h + 77;
        }
        if (this.contentDocument.getElementById('fotoeditor_delete')) {
            h = h + 177;
        }

        $(this).height(h);
    })

    $('.collapsed').each( function (i) {
        var cook = '';
        if ($(this).hasClass("tax_collapsible")) {
            cook = MyCookie.Read( this.id );
        }
        if ( cook != 'show') {
            $(this).children('.body').slideUp('fast');
        } else {
            $(this).removeClass("collapsed");
        }
    });

    $('.collapsible .title a').click(function(event){
        if ($(this).parents(".collapsible:first").hasClass("collapsed")) {
            $(this).parents(".collapsible:first").removeClass("collapsed");
            $(this).parents(".title").next(".body").slideDown('fast');
        } else {
            $(this).parents(".collapsible:first").addClass("collapsed");
            $(this).parents(".title").next(".body").slideUp('fast');
        }
     
        return false;
    });

    $('.tax_collapsible .title a').click(function(event){
        var taxid = $(this).parents(".tax_collapsible:first").attr("id");
        if ($(this).parents(".tax_collapsible:first").hasClass("collapsed")) {
            $(this).parents(".tax_collapsible:first").removeClass("collapsed");
            $(this).parents(".title").next(".body").slideDown('fast');
            MyCookie.Write(taxid, 'show', 30);
        } else {
            $(this).parents(".tax_collapsible:first").addClass("collapsed");
            $(this).parents(".title").next(".body").slideUp('fast');
            MyCookie.Write(taxid, '', -1);
        }
     
        return false;
    });

    $('.tipable').tooltip({
        track: true,
        delay: 0,
        bodyHandler: function() {
            return $(this).parent().next().html();
        },
        showURL: false
    });

    $('#chained-region_0').chainSelect('#chained-region_1','/ajax/regions/',
    {
        usePost: true,
        defaultValue : 0,
        before:function (target) //before request hide the target combobox and display the loading message
        {
            //                        $("#loading").css("display","block");
            $(target).css("display","none");
        },
        after:function (target) //after request show the target combobox and hide the loading message
        {
            //                        $("#loading").css("display","none");
            $(target).css("display","inline");
        }
    });
  
});
