﻿/// <reference name="MicrosoftAjax.js"/>

Type.registerNamespace("Nunusoft.Web.Controls");

Nunusoft.Web.Controls.SoftwareWebCard = function(element) {
    Nunusoft.Web.Controls.SoftwareWebCard.initializeBase(this, [element]);
    this._containerWindow = null;
    this._ratingControl = null;
    this._dataSource = null;
    this._imgIcon = null;
    this._hlIcon = null;
    this._hlShortDesc = null;
    //    this._hlBuy = null;
    //    this._hlDownload = null;
    //    this._hlComments = null;
    this._btnBuy = null;
    this._btnDownload = null;
    this._btnComments = null;
    this._divRegularPrice = null;
    this._divCurrentPrice = null;
    this._clientRenderOnInit = null;
}

Nunusoft.Web.Controls.SoftwareWebCard.prototype = {
    get_containerWindow: function() { return this._containerWindow; },
    set_containerWindow: function(value) { this._containerWindow = value; },

    get_ratingControl: function() { return this._ratingControl; },
    set_ratingControl: function(value) { this._ratingControl = value; },

    get_dataSource: function() { return this._dataSource; },
    set_dataSource: function(value) { this._dataSource = value; },

    get_imgIcon: function() { return this._imgIcon; },
    set_imgIcon: function(value) { this._imgIcon = value; },

    get_hlIcon: function() { return this._hlIcon; },
    set_hlIcon: function(value) { this._hlIcon = value; },

    get_hlShortDesc: function() { return this._hlShortDesc; },
    set_hlShortDesc: function(value) { this._hlShortDesc = value; },

//    get_hlBuy: function() { return this._hlBuy; },
//    set_hlBuy: function(value) { this._hlBuy = value; },

//    get_hlDownload: function() { return this._hlDownload; },
//    set_hlDownload: function(value) { this._hlDownload = value; },

//    get_hlComments: function() { return this._hlComments; },
    //    set_hlComments: function(value) { this._hlComments = value; },

    get_btnBuy: function() { return this._btnBuy; },
    set_btnBuy: function(value) { this._btnBuy = value; },

    get_btnDownload: function() { return this._btnDownload; },
    set_btnDownload: function(value) { this._btnDownload = value; },

    get_btnComments: function() { return this._btnComments; },
    set_btnComments: function(value) { this._btnComments = value; },


    get_divRegularPrice: function() { return this._divRegularPrice; },
    set_divRegularPrice: function(value) { this._divRegularPrice = value; },

    get_divCurrentPrice: function() { return this._divCurrentPrice; },
    set_divCurrentPrice: function(value) { this._divCurrentPrice = value; },

    get_clientRenderOnInit: function() { return this._clientRenderOnInit; },
    set_clientRenderOnInit: function(value) { this._clientRenderOnInit = value; },


    add_onRatingClick: function(h) { this.get_events().addHandler("onRatingClick", h); },
    remove_onRatingClick: function(h) { this.get_events().removeHandler("onRatingClick", h); },

    _ratingControl_click: function(e) {
        var h = this.get_events().getHandler("onRatingClick");
        if (h)
            h(this, e);
    },

    Render: function() {
        if (this._dataSource) {
            this._containerWindow.set_title(this._dataSource.Name);
            this._containerWindow.set_titleLink(this._dataSource.DetailLink);
            this._containerWindow.Render();
            this._imgIcon.src = this._dataSource.IconUrl;
            this._hlIcon.href = this._dataSource.DetailLink;
            this._hlShortDesc.innerHTML = this._dataSource.ShortDescription;
            this._hlShortDesc.title = this._dataSource.ShortDescription;
            this._hlShortDesc.href = this._dataSource.DetailLink;

            this._hlBuy.href = this._dataSource.BuyLink;
            this._hlBuy.target = "_blank";

            this._hlDownload.href = this._dataSource.DownloadLink;
            this._hlComments.href = this._dataSource.CommentsLink;

            this._divRegularPrice.innerHTML = this._dataSource.RegularPrice;
            this._divCurrentPrice.innerHTML = this._dataSource.CurrentPrice;

            this._ratingControl.set_currentRate(this._dataSource.Rate);
            this._ratingControl.Render();
        }

    },

    initialize: function() {
        Nunusoft.Web.Controls.SoftwareWebCard.callBaseMethod(this, 'initialize');
        $addHandler(this._ratingControl.get_element(), "click", Function.createDelegate(this, this._ratingControl_click));
        if (this._clientRenderOnInit)
            this.Render();
        // Add custom initialization here
    },
    dispose: function() {
        //Add custom dispose actions here
        Nunusoft.Web.Controls.SoftwareWebCard.callBaseMethod(this, 'dispose');
    }
}
Nunusoft.Web.Controls.SoftwareWebCard.registerClass('Nunusoft.Web.Controls.SoftwareWebCard', Sys.UI.Control);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
