﻿function loadContent(idNode, idBlock) {
    loader("divContent");
    ncService.getContent(idNode, idBlock, loadContentSuccess, loadContentFailure);
}
function showBlock(idNode, idBlock) {
    $("#divContent #" + idBlock).slideDown("slow").css("display", "block");
    $("#divContent .divBlock").not("#" + idBlock).slideUp("slow").css("display", "none");

}

function loadContentSuccess(args) {
    //document.getElementById("divContent").innerHTML = result;
    $("#divContent").html("" + args);
    $("#divContent .divBlock").backgroundCanvas();
    //$(window).load(function() { DrawBackground($("#divContent .divBlock")); });
    //$(window).resize(function() { DrawBackground($("#divContent .divBlock")); });
    DrawBackground($("#divContent .divBlock"))
}

function loadContentFailure(args) {
    //document.getElementById("divContent").innerHTML = result;
    $("#divContent").html("<div style='background-color:white;color:red'><h5>An error occurred while loading. Please try again or Refresh the page using Ctrl-F5. If the problem persists please contact us.</h5><br /> Error : " + args + "</div>");
    $("#divContent .divBlock").backgroundCanvas();
    DrawBackground($("#divContent .divBlock"))
}


function showAll(idNode) {
    $("#divContent .divBlock").slideDown("slow").css("display", "block");
    //$('.divBlock').corners("10px");
}


$(function() {



    //Rounded corners
    //$('.divBlock').corners("10px");
    //$('#divMain').corners("10px bottom");
    //$('.Menu').corners("10px top");
    // $('.divNodeMenu').corners("5px bottom-right");
//===============


}
);

// Insert the Canvas Object into the div with id #MyDiv 
$(document).ready(function() {
$(".divBlock").backgroundCanvas();
});

function redrawBlock(IDBlock, doShow) {
    //When manually maximizing/minimizing blocks
    var divBody = $("#block" + IDBlock).find(".divBody");
    if ($.browser.msie) {
        //Remove previous RESIZE event handeler from block to clear memory
        divBody.unbind("resize");
        //Re-add new Resize event handler
        divBody.resize(function() { DrawBackground($("#block" + IDBlock)); });
        if (doShow) {
            divBody.show("slow");
        } else divBody.hide("slow");
    }
    else {
        if (doShow) {
            divBody.css("display", "block");
        } else divBody.css("display", "none");
        DrawBackground($("#block" + IDBlock));
    }
}

function repaintBlock(IDBlock) {
    // For automatically redrawing blocks with dynamicly loaded data
    var divBody = $("#block" + IDBlock).find(".divBody");
    divBody.hide();
    //Remove previous RESIZE event handeler from block to clear memory
    divBody.unbind("resize");
    //Re-add new Resize event handler
    divBody.resize(function() { DrawBackground($("#block" + IDBlock)); });
    divBody.show("slow", function() { DrawBackground($("#block" + IDBlock)); });
}


// Helper function to draw background for convienience
function DrawBackground(elem) {
    // Paints on the background canvas with the PaintFunction you must provide!
    elem.backgroundCanvasPaint(MyBackgroundPaintFkt);
}

// Draw the background  on load and resize
$(window).load(function() { DrawBackground($(".divBlock")); });
$(window).resize(function() { DrawBackground($(".divBlock")); });

// This is the canvas paint function you have to provide. Don't care about the canvas, just draw on it!
function MyBackgroundPaintFkt(context, width, height, canvas, $canvas, $canvasDiv, $content, $element) {
    var options = { x: -2, height: height, width: width, radius: 10, border: 4 };

    // Draw a red red border round corner rectangle
    context.fillStyle = $(".jsDummy").css("border-color");
    $.canvasPaint.roundedRect(context, options);

    // Draw the gradient filled inner rectangle
    var backgroundGradient = context.createLinearGradient(0, 0, 0, height - 10);

    backgroundGradient.addColorStop(0, $(".jsDummy").css("color"));
    backgroundGradient.addColorStop(1, $(".jsDummy").css("background-color"));

    options.border = 5;
    context.fillStyle = backgroundGradient;
    $.canvasPaint.roundedRect(context, options);
}
    
    

