﻿
  /*
  * @jslint          2009-01-28
  */

MSLM.animation = {};

MSLM.animation.bgswitch = {

    __version: 1.0, // class version
    __class: 'MSLM.animation.bgswitch', // class name

    // set default options
    _oDefaults: {
        bgTrigger: "#toolbar .bgswitch li a",
        arrColor: ["green", "blue", "orange", "red"],
        arrColorValue: ["#14502e", "#2d465c", "#f4791c", "#6a3d3a"],
        cookieIdentifier: "WLMBgColor"
    },

    /**
    * Setup
    * @return {Void}
    */
    _setUp: function(oOptions) {
        var _scope = MSLM.animation.bgswitch;
        
        // merge options and defaults
        _scope._oOpt = jQuery.extend({}, _scope._oDefaults, oOptions);
        _scope._oDefaults = null;
        
        jQuery(_scope._oOpt.bgTrigger).bind("click.bgswitch", this._changeBGColour);
        jQuery(_scope._oOpt.bgTrigger).bind("click.bgswitch", this._setCookie);
        jQuery(_scope._oOpt.bgTrigger).bind("focus.bgswitch", this._blurElement);
    },

    _changeBGColour: function() {
        var _scope = MSLM.animation.bgswitch;
		var image = null;
		
        if (jQuery("#content").size() === 0) {
            image = "http://messenger.live.de/images/backgrounds/home_body_" + this.className + ".jpg"; 
        }
        else {
            image = "http://messenger.live.de/images/backgrounds/content_body_" + this.className + ".jpg";
        }
        var bgColor = _scope._oOpt.arrColorValue[jQuery.inArray(this.className, _scope._oOpt.arrColor)];
        
        /* Browser switch for IE6 */
        jQuery.each(jQuery.browser, function(i, val) {
            if (i == "msie" && jQuery.browser.version.substr(0, 1) == "6") {
                window.setTimeout(function setBGImage() { jQuery("body").css("background", bgColor + " url(" + image + ") repeat-x left top"); }, 0);
            }
            else {
                jQuery("body").css("background", bgColor + " url(" + image + ") repeat-x left top");
            }
        });

        return false;
    },

    _blurElement: function() {
        this.blur();
    },

    _setCookie: function() {
        var _scope = MSLM.animation.bgswitch;
        var expires = new Date();
        var oneMonth = expires.getTime() + (1000 * 60 * 60 * 24 * 30); //30 days
        expires.setTime(oneMonth);
        document.cookie = _scope._oOpt.cookieIdentifier + "=" + this.className + "; expires=" + expires.toGMTString() + "; path=/";
    },
    

    /**
    * Get singleton instance
    * @param {Object} [oOptions]
    * @return {Instance}
    */
    getInstance: function(oOptions) {
        return MSLM.animation.bgswitch.initialize(oOptions);
    },

    /**
    * Constructor
    * @param {Object} [oOptions]
    * @constructor
    */
    initialize: function(oOptions) {
        // fake singleton
        if (this._oOpt) {
            return this;
        }
        // setup 
        this._setUp(oOptions);
        // fake singleton
        return this;
    }


};

MSLM.animation.toggleBox = {

    __version: 1.1, // class version
    __class: 'MSLM.animation.toggleBox', // class name

    // set default options
    _oDefaults: {
},

open: function(openerElement, container) {
    if (!openerElement.hasClass("close")) {
        container.toggle();
        openerElement.addClass("close");
    }
},

open2: function(openerElement, container, openerElement2) {
    if (!openerElement.hasClass("close") && !openerElement2.hasClass("close")) {
        container.toggle();
        openerElement.addClass("close");
        openerElement2.hasClass("close");
    }
},

close: function(openerElement, container, form) {
    container.toggle();
    openerElement.removeClass("close");
    if (form && form[0] && form[0].reset) {
        form[0].reset();
    }
    if (form) {
        jQuery('.error', form).removeClass('error');
    }
},

close2: function(openerElement, container, form, openerElement2) {
    container.toggle();
    openerElement.removeClass("close");
    openerElement2.removeClass("close");
    if (form && form[0] && form[0].reset) {
        form[0].reset();
    }
    if (form) {
        jQuery('.error', form).removeClass('error');
    }
}
};
