﻿/// <reference name="MicrosoftAjax.js"/>

Type.registerNamespace("Zoomarine");

Zoomarine.Season = function(element) {

    Zoomarine.Season.initializeBase(this, [element]);

};

Zoomarine.Season.prototype = 
{

    initialize: function() {
        Zoomarine.Season.callBaseMethod(this, 'initialize');
    },

    dispose: function() {
        Zoomarine.SeasonDay.callBaseMethod(this, 'dispose');
    }

}

Zoomarine.SeasonElement = function(element) {

    this._tooltip = null;
    this._tooltipPanelId = null;
    this._buttonId = null;
    this._active = true;
    Zoomarine.SeasonElement.initializeBase(this, [element]);

}

Zoomarine.SeasonElement.prototype = {

    initialize: function() {
        Zoomarine.SeasonElement.callBaseMethod(this, 'initialize');

        this._mouseOverHandler = Function.createDelegate(this, this._onMouseOver);
        this._mouseOutHandler = Function.createDelegate(this, this._onMouseOut);
        this._clickHandler = Function.createDelegate(this, this._onClick)

        $addHandlers(this.get_element(), { 'mouseover': this._mouseOverHandler, 'mouseout': this._mouseOutHandler, 'click': this._clickHandler }, this);
    },

    dispose: function() {
        $clearHandlers(this.get_element());

        delete this._mouseOverHandler;
        delete this._mouseOutHandler;
        delete this._clickHandler;
        Zoomarine.SeasonElement.callBaseMethod(this, 'dispose');
    },

    get_active: function() {
        return this._active;
    },

    set_active: function(value) {
        this._active = value;
    },

    get_tooltip: function() {
        return this._tooltip;
    },

    set_tooltip: function(value) {
        this._tooltip = value;
    },

    get_tooltipPanelId: function() {
        return this._tooltipPanelId;
    },

    set_tooltipPanelId: function(value) {
        this._tooltipPanelId = value;
    },

    get_buttonId: function() {
        return this._buttonId;
    },

    set_buttonId: function(value) {
        this._buttonId = value;
    },

    _onMouseOver: function(e) {
        if (this._tooltip != null && this._tooltip != "" && !Zoomarine.Season.TooltipLocked)
            $get(this._tooltipPanelId).style.display = "block";
    },

    _onMouseOut: function(e) {
        $get(this._tooltipPanelId).style.display = "none";
    },

    _onClick: function(e) {
        if (!this._active) return;
        this.select();
        __doPostBack(this._buttonId, '');
        if (Zoomarine.Season.elementSelected) Zoomarine.Season.elementSelected(this);

        var handler = this.get_events().getHandler('click');
        if (handler != null) handler(this, Sys.EventArgs.Empty);
    },

    select: function() {
        if (Zoomarine.Season.selectedElement) Zoomarine.Season.selectedElement.unselect();
        this._class = this.get_element().className;
        this.get_element().className += " Emphasy";
        Zoomarine.Season.selectedElement = this;
    },

    unselect: function() {
        this.get_element().className = this._class;
        Zoomarine.Season.selectedElement = null;
    }

}

Zoomarine.SeasonElement.registerClass('Zoomarine.SeasonElement', Sys.UI.Control);

Zoomarine.SeasonDay = function(element) {
    Zoomarine.SeasonDay.initializeBase(this, [element]);
}

Zoomarine.SeasonDay.prototype = {

    initialize: function() {
        Zoomarine.SeasonDay.callBaseMethod(this, 'initialize');
    },

    dispose: function() {
        Zoomarine.SeasonDay.callBaseMethod(this, 'dispose');
    },
    
    select: function() {
        if (Zoomarine.Season.selectedElement) Zoomarine.Season.selectedElement.unselect();
        this._backgroundColor = this.get_element().style.backgroundColor;
        this.get_element().style.backgroundColor = '#ff8ab8';
        Zoomarine.Season.selectedElement = this;
    },

    unselect: function() {
        this.get_element().style.backgroundColor = this._backgroundColor;
        Zoomarine.Season.selectedElement = null;
    }
}

Zoomarine.SeasonDay.registerClass('Zoomarine.SeasonDay', Zoomarine.SeasonElement);
Zoomarine.Season.TooltipLocked = false;

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
