function removeCKEonClose()
{
    for(var key in CKEDITOR.instances)
    {
        CKEDITOR.remove(CKEDITOR.instances[key]);
    }
}

function tb_remove() {
    $("#TB_imageOff").unbind("click");
    $("#TB_closeWindowButton").unbind("click");
    $("#TB_window").fadeOut("fast",function(){
        $("#TB_window,#TB_overlay,#TB_HideSelect").trigger("unload").unbind().remove();
    });
    $("#TB_load").remove();
    if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
        $("body","html").css({
            height: "auto",
            width: "auto"
        });
        $("html").css("overflow","");
    }
    document.onkeydown = "";
    document.onkeyup = "";
    removeCKEonClose();
    return false;
}

$(document).ready(function(){
    Shadowbox.init();
    bindConfirms();
    bindNewWindow();
});

function postForm(form, div)
{
    $.ajax({
        type: "POST",
        url: $(form).attr("action"),
        data: $(form).serialize(),
        success:  function(data) {
            $(div).html(data);
        }
    });
    return false;
}

function print_r(theObj){
    if(theObj.constructor == Array ||
        theObj.constructor == Object){
        document.write("<ul>")
        for(var p in theObj){
            if(theObj[p].constructor == Array||
                theObj[p].constructor == Object){
                document.write("<li>["+p+"] => "+typeof(theObj)+"</li>");
                document.write("<ul>")
                print_r(theObj[p]);
                document.write("</ul>")
            }
            else
            {
                document.write("<li>["+p+"] => "+theObj[p]+"</li>");
            }
        }
        document.write("</ul>")
    }
}

function useFinder()
{
    for(var key in CKEDITOR.instances)
    {
        CKFinder.SetupCKEditor( CKEDITOR.instances[key], HTTP_PATH + "resources/ckfinder/" );
    }
}

function useCKE(where)
{
    for(var key in CKEDITOR.instances)
    {
        CKEDITOR.remove(CKEDITOR.instances[key]);
    }
    if($.isArray(where))
    {
        for(var key2 in where)
        {
            CKEDITOR.replace(where[key2]);
        }
    }
    else if(where)
    {
        CKEDITOR.replace(where);
    }
    else
    {
        CKEDITOR.replaceAll();
    }
}

function shiftContent(block, contents, id)
{
    if(id == undefined)
    {
        id = 0;
        for(var c in contents)
        {
            if(c != id)
                $(contents[c]).hide();
        //$(contents[c]).css('position', 'absolute');
        }
        $(block).css('position', 'relative');
    }
    
    var newID = id + 1;
    if(newID >= contents.length)
        newID = 0;
    $(contents[id]).delay(8000).fadeOut(100, function() {
        $(contents[newID]).fadeIn(100, function() {
            shiftContent(block, contents, newID);
        });
    });
}

$(function(){
    $("#hledatButton").button();
});


$(function () {
	$("#zarazeniProduktu").jstree({
	        "themes" : {
	            "theme" : "classic",
	            "dots" : true,
	            "icons" : false
	        },
		"plugins" : [ "themes", "html_data"]
	});
});
