﻿$(function() {
    var Class;
    registerNS("ChristmasImprints.JS");
    Class = ChristmasImprints.JS.Favourites = function(insertAfter, cardManager) {
        // Class entry point. Fired when instantiated.
        this.initialise(insertAfter, cardManager);
    }

    function initialiseStatic() {
        // Initialise any static variables here...
    }

    Class.prototype = {

        // Initialise any member variables here...
        initialise: function(insertAfter, cardManager) {
            this.imgDiv = {};
            this.cardManager = cardManager;
            this.root = document.createElement("div");
            YAHOO.util.Dom.addClass(this.root, "favourites");
            YAHOO.util.Dom.insertAfter(this.root, insertAfter);
        },

        addCard: function(id) {
            if (typeof (this.imgDiv[id]) == "undefined") {
                this.imgDiv[id] = document.createElement("div");
                alert("Adding " + id);

            }
        },

        removeCard: function(id) {
            if (typeof (this.imgDiv[id]) != "undefined") {
                document.removeChild(this.imgDiv[id]);
            }
        },

        onTweenComplete: function(id) {
            this.masterAlphaTween = null;
        },

        alphaTween: function(control, alpha, duration, id, autoAlpha) {
            var tween = new YAHOO.util.Anim(control);
            tween.attributes.opacity = { to: alpha };
            tween.duration = duration;
            tween.method = YAHOO.util.Easing.easeOutStrong;

            if (id != null) {
                this.isTweenComplete[id] = false;
                tween.onComplete.subscribe(gUtils.callback(this, this.onTweenComplete, new Array(id)));
            }

            if (alpha > 0) {
                if (YAHOO.util.Dom.getStyle(control, "display") == "none") {
                    YAHOO.util.Dom.setStyle(control, "opacity", 0);
                    YAHOO.util.Dom.setStyle(control, "display", "block");
                }
                if (alpha == 1) {
                    // Remove transparency properties on completion for 100% alpha tweens, this solves
                    // any funny rendering by some browsers...
                    if (YAHOO.env.ua.ie) {
                        tween.onComplete.subscribe(function() { YAHOO.util.Dom.setStyle(control, "opacity", 1); });
                    } else {
                        tween.onComplete.subscribe(function() { YAHOO.util.Dom.setStyle(control, "opacity", ""); });
                    }
                }
            }
            else if (autoAlpha == null || autoAlpha == true) {
                // Take components out of the display list when they are not visible...
                tween.onComplete.subscribe(function() { YAHOO.util.Dom.setStyle(control, "display", "none"); });
            }

            tween.animate();
            return tween;
        }



    };
    initialiseStatic();
});