﻿///<reference path="jquery-1.2.6-vsdoc.js" />
///<reference path="Renderer.js" />
///<reference path="GetData.js" />


Type.registerNamespace("KMDA.Babyolifant");

// Constructor
KMDA.Babyolifant.DashboardItem = function(section) {

    //KMDA.Babyolifant.DashboardItem.initializeBase(this, [element]);
    this.DashboardItemType = section.Type;
    this.Width = section.Width;
    this.Height = section.Height;
    this.x = section.x;
    this.y = section.y;
    this.OldExternalId = "";
    this.ExternalId = "";
    this.HtmlTemplate = "";
    this.ParentElement = new Object();
    this.ExternalScript = section.ExternalScript;
}

KMDA.Babyolifant.DashboardItem.prototype = {
    DashboardItemType: "",
    Width: 0,
    Height: 0,
    x: 0,
    y: 0,
    OldExternalId: "",
    ExternalId: "",
    Visible: false,
    HtmlTemplate: "",
    ParentElement: new Object(),
    ExternalScript: false,

    RenderContent: function(parent, newexternalid) {



        //avoid rerendering of unchanged content
        //if (this.ExternalId != newexternalid) {

        var itemdiv = $('#' + this.DashboardItemType, $(parent));
        var datacontainer = $('.datacontainer', itemdiv);

        datacontainer.html(this.HtmlTemplate.replace(/@itemid@/g, newexternalid));


        try {
            var componentTracker = _gat._getTracker(gCode);
            componentTracker._trackPageview(this.DashboardItemType + '_LOADED');
        } catch (err) { }




    },
    PreloadContent: function() {
    },
    getItemSucces: function() {
        var obj = this;

        return function(data) {

            obj.ExternalId = data.ExternalId;
        }
    },
    CreateDashboardItem: function(dashboard) {
        itemdiv = $("<div class=\"dashboarditem clearfix\" id='" + this.DashboardItemType + "'></div>");
        datacontainerdiv = $("<div class=\"datacontainer\"></div>");
        screendiv = $("<div class=\"screen\"></div>");

        itemdiv.css("width", this.Width);
        itemdiv.css("height", this.Height);
        itemdiv.css("top", this.y);
        itemdiv.css("left", this.x);

        itemdiv.append(datacontainerdiv);

        dashboard.append(itemdiv);

        this.OldExternalId = this.ExternalId;
    },
    MoveOrHideDashboardItem: function(itemdiv) {

        itemdiv.animate({ "left": this.x, "top": this.y }, function() { itemdiv.fadeIn("slow"); });
    },
    RemoveDashboardItem: function(itemdiv) {
        //remove item/ only hide is also possible

        //itemdiv.fadeOut("slow", function() { itemdiv.remove(); });
        itemdiv.fadeOut("slow");
    }
}

function Transition(datacontainer, Html) {
    return function() {

        datacontainer.html(Html);

    }
}
function ReAppear(screen) {
    return function() {
        screen.fadeOut("fast");
    }
}
KMDA.Babyolifant.DashboardItem.registerClass('KMDA.Babyolifant.DashboardItem', Sys.UI.Control);


KMDA.Babyolifant.BlogItem = function(someparam, DashboardItemType) {

    KMDA.Babyolifant.BlogItem.initializeBase(this, [DashboardItemType]);
    this.SomeParam = someparam;
}


// Notify ScriptManager that this is the end of the script.
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
