/*                                                                                                                                                                                                           
 *  Copyright (c) 2008 Snapvine, LLC. All rights reserved.
 *                                                                                                  
 * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF Snapvine, LLC 
 *    The copyright notice above does not evidence any            
 *    actual or intended publication of such source code.       
*/

if (typeof(snapvine) == "undefined") {snapvine = function() {}};
if (typeof(snapvine.common) == "undefined") {snapvine.common = function() {}};
snapvine.common.Explanation = function(index, options) {
    this.init(index, options);
};

/* Class for Explanation.
 *
 * Requires jQuery.
 *
 * Correct usage:
 * 
 *
 */
snapvine.common.Explanation.prototype = {

    m_index: 0,                 // Unique ID for each explanation text.
    m_explanation: null,        // The explanation text DOM Element.
    m_css: {},                  // The positioning and sizing CSS attributes.
    
    m_timer: null,              // A JS Timer Object for hiding the explanation.
    m_timerInterval: 800,       // Duration in milliseconds for above timer.
    m_width: 300,               // Width of explanation text object.
    m_leftOffset: null,         // Distance to shift text object left from the center.
    m_position: "absolute",     // CSS position attribute.
    
    init: function(index, options) {
        this.m_index = index;
        this.m_explanation = $("#whats_this"+this.m_index+"_explanation").get(0);
        if (options.timerInterval )
            this.m_timerInterval = options.timerInterval;
        if (options.width)
            this.m_width = options.width;
        if (options.leftOffset)
            this.m_leftOffset = options.leftOffset;
        else
            this.m_leftOffset = Math.floor(this.m_width/2);
        if (options.position)
            this.m_position = options.position;
    },
    
    mouseover: function() {
        if (typeof this.m_timer != 'undefined') {
            clearTimeout(this.m_timer);
            this.m_timer = null;
        }
        
        var position = $("#whats_this"+this.m_index).offset();
        this.m_css = {
            top: position.top+10+'px',
            left: position.left-this.m_leftOffset+'px',
            width: this.m_width,
            position: this.m_position
        };
        $("#whats_this"+this.m_index+"_explanation").css(this.m_css).show(); 
    },
    
    mouseout: function() {
        _this = this;
        this.m_timer = setTimeout(function() {
                $("#whats_this"+_this.m_index+"_explanation").hide();
            }, this.m_timerInterval);
    }
};