
var globalQTE=1;

function callbacksJS(Nom) {
    jQuery("#DivInfoFav").center();
    $('DivInfoFav').innerHTML = Nom;
    $('DivInfoFav').setStyle('display', 'block');
    setTimeout("ClearDivInfoFav()", 1000);
}

function ClearDivInfoFav() {
    $('DivInfoFav').innerHTML = '';
    $('DivInfoFav').setStyle('display', 'none');
}

function changebuttonstate(nomcontrolcomm, nomcontroltrigger) {

    var charLength = jQuery("#" + nomcontrolcomm).val().length;

    if (charLength == 0) {
        jQuery("#" + nomcontroltrigger).attr("class", "NotExistPanierComments addComment");
    }
    else {
        jQuery("#" + nomcontroltrigger).attr("class", "ExistPanierComments addComment");
    }

    return false;
}

jQuery(document).ready(function () {
    var elemroot = jQuery(".thumbLabel");
    elemroot.children().each(function () {
        jQuery(this).textTruncate({
            width: 185,
            tail: ' ...',
            tooltip: true
        });
    });

    var elemroot = jQuery(".thumbLabelProduit");
    elemroot.children().each(function () {
        jQuery(this).textTruncate({
            width: 330,
            tail: ' ...',
            tooltip: true
        });
    });
});

jQuery(window).load(function () {

    var posmousex = -1;
    var posmousey = -1;

    var overlayElem;
    var posmouseywindow = -1;
    var posmousexwindow = -1;
    var startLoad = new Date();

    jQuery(".inputqte").live('keyup', function (event) {
        var qte = jQuery(this).val();
        if (qte == '')
            qte = 1;
        globalQTE = qte;
    });

    jQuery(document).mousemove(function (e) {
        posmousexwindow = e.pageX;
        posmouseywindow = e.pageY;
    });

    /*
    jQuery("select").each(function() {
    jQuery(this).attr("class","chosen");
    jQuery(this).chosen();	
    });
    */

    // initialisation des tooltip "classiques"
    /*
    jQuery("a[title]").tooltip({
    tipClass: 'tooltip',
    delay: 0,
    position: "bottom right",
    offset: [10, 0]
    });
    */

    jQuery.fn.center = function () {
        this.css('position', 'absolute');
        this.css('top', ((jQuery(window).height() - this.outerHeight()) / 2) + jQuery(window).scrollTop() + 'px');
        this.css('left', ((jQuery(window).width() - this.outerWidth()) / 2) + jQuery(window).scrollLeft() + 'px');

        return this;
    }

    jQuery(function () {
        jQuery(document).keydown(function (event) {

            if (!jQuery("*:focus").is("textarea") && event.keyCode == 13 && jQuery(location).attr('href').toLowerCase().indexOf("login.aspx") < 0) {
                return false;
            }

        });
    });

    var msk;

    jQuery("img[typeappel='addvariantes'],img[typeappel='addvariantesbep'],a[typeappel='addpanier'],a[typeappel='addpanierbep'],#reperecliquable[typeappel='addpanier'],#reperecliquable[typeappel='addpanierbep'],a[typeappel='addvariantes'],a[typeappel='addvariantesbep'],#reperecliquable[typeappel='addvariantes'],#reperecliquable[typeappel='addvariantesbep']").live('click', function (e) {
        var triggers = jQuery(this).overlay({
            api: true,
            load: true,
            closeOnClick: false,
            closeOnEsc: false,
            mask: {},
            onBeforeLoad: function () {
                var typeappel = this.getTrigger().attr("typeappel");
                var overlayConfig = this.getConf();
                var trigger = this.getTrigger();
                var content = "";
                var title = "";
                var theFooter = "";
                var nomcontrol = "";

                if (typeappel == 'addpanier') { //Ajouter au panier direct
                    nomcontrol = "#askWindow";

                    var refarticle = this.getTrigger().attr("articleref");
                    title = this.getTrigger().attr("content");
                    theFooter = "";

                    var resultat = SpelogAjaxObjects.AskWindow(refarticle, 1, null);
                    WinAskcallback(resultat);
                    content = jQuery(nomcontrol).html();
                    this.getOverlay().html(content);
                }
                else if (typeappel == 'addpanierbep') { //Ajouter au indicent direct
                    nomcontrol = "#askWindow";

                    var refarticle = this.getTrigger().attr("articleref");
                    var idincident = this.getTrigger().attr("idincident");
                    theFooter = "";

                    var resultat = SpelogAjaxObjects.AskWindowBEP(refarticle, idincident, null).value;
                    content = resultat.HTML;
                    title = resultat.INTITULE;

                    this.getOverlay().html('<div class="header">' + title + '</div><div class="content">' + content + '</div><div class="footer">' + theFooter + '</div>');
                }
                else if (typeappel == 'addvariantes') {
                    nomcontrol = "#zoneaddvariantes";

                    var ajaxvar1 = this.getTrigger().attr("ajaxvar1");
                    var ajaxvar2 = this.getTrigger().attr("ajaxvar2");
                    var ajaxvar3 = this.getTrigger().attr("ajaxvar3");

                    var resultat = SpelogAjaxObjects.AskWindowVariants(ajaxvar1, ajaxvar2, ajaxvar3, null).value;
                    content = resultat.HTML;
                    title = resultat.INTITULE;

                    this.getOverlay().html('<div class="header"><span class="title">' + title + '</span><a class="close"></a></div><div class="content">' + content + '</div><div class="footer">' + theFooter + '</div>');
                }
                else if (typeappel == 'addvariantesbep') {
                    nomcontrol = "#zoneaddvariantes";

                    var ajaxvar1 = this.getTrigger().attr("ajaxvar1");
                    var ajaxvar2 = this.getTrigger().attr("ajaxvar2");
                    var ajaxvar3 = this.getTrigger().attr("ajaxvar3");
                    var ajaxvar4 = this.getTrigger().attr("ajaxvar4");

                    var resultat = SpelogAjaxObjects.AskWindowVariantsBEP(ajaxvar1, ajaxvar2, ajaxvar3, ajaxvar4, null).value;
                    content = resultat.HTML;
                    title = resultat.INTITULE;

                    this.getOverlay().html('<div class="header"><span class="title">' + title + '</span><a class="close"></a></div><div class="content">' + content + '</div><div class="footer">' + theFooter + '</div>');
                }

                this.getConf().top = (jQuery(window).height() / 2) - (jQuery(nomcontrol).height() / 2);
                this.getConf().left = (jQuery(window).width() / 2) - (jQuery(nomcontrol).width() / 2);
            },
            onLoad: function () {
                var self = this;
                closers = this.getOverlay().find(".close");
                closers.click(function (e) {
                    self.close();
                });
            },
            onBeforeClose: function () {
            },
            onClose: function () {
            }
        });
    });


    jQuery(".appareilphotoarticle").tooltip(
            {
                tip: '#photoarticle',
                effect: 'fade',
                fadeOutSpeed: 100,
                predelay: 100,
                position: "center right",
                offset: [0, 20],
                onBeforeShow: function () {
                    theUrl = this.getTrigger().attr("photo");
                    theHeader = this.getTrigger().attr("header");
                    theFooter = this.getTrigger().attr("footer");
                    this.getTip().html('<div class="header">' + theHeader + '</div><div class="content"><img src="' + theUrl + '"/></div><div class="footer">' + theFooter + '</div>');
                }
            });

    jQuery(".appareilphotoschema").tooltip(
            {
                tip: '#photoschema',
                effect: 'fade',
                fadeOutSpeed: 100,
                predelay: 100,
                position: "center right",
                offset: [0, 20],
                onBeforeShow: function () {
                    theUrl = this.getTrigger().attr("photo");
                    theHeader = this.getTrigger().attr("header");
                    theFooter = this.getTrigger().attr("footer");
                    this.getTip().html('<div class="header">' + theHeader + '</div><div class="content"><img src="' + theUrl + '"/></div><div class="footer">' + theFooter + '</div>');
                }
            });

    jQuery(".photo").tooltip(
                                {
                                    tip: '#photo',
                                    delay: 0,
                                    position: "center right",
                                    offset: [0, 20],
                                    onBeforeShow: function () {
                                        theUrl = this.getTrigger().attr("photo");
                                        theHeader = this.getTrigger().attr("header");
                                        theFooter = this.getTrigger().attr("footer");
                                        this.getTip().html('<div class="header">' + theHeader + '</div><div class="content"><img src="' + theUrl + '"/></div><div class="footer">' + theFooter + '</div>');
                                    }
                                });

    jQuery(".information").tooltip({
        tip: '#zoneinfo',
        delay: 0,
        position: "center right",
        offset: [0, 20],
        onBeforeShow: function () {
            theHeader = this.getTrigger().attr("header");
            theFooter = this.getTrigger().attr("footer");
            theContent = this.getTrigger().attr("content");
            this.getTip().html('<div class="header">' + theHeader + '</div><div class="content">' + theContent + '</div><div class="footer">' + theFooter + '</div>');
        }
    });

    jQuery(".DivCustomfield,.pictoCustomField").tooltip(
	    {
	        tip: '#zonecustomfield',
	        delay: 0,
	        position: "bottom right",
	        offset: [0, 0],
	        onBeforeShow: function () {
	            theHeader = this.getTrigger().attr("header");
	            theFooter = this.getTrigger().attr("footer");
	            theContentName = this.getTrigger().attr("contentname");
	            theContent = jQuery('#' + theContentName).html();
	            this.getTip().html('<div class="header">' + theHeader + '</div><div class="content">' + theContent + '</div><div class="footer">' + theFooter + '</div>');
	        }
	    });

    jQuery(".DivMedia[rel]").live('click', function (e) {
        e.preventDefault();

        // save overlay
        overlayElem = jQuery(this);

        // load overlay
        jQuery(this).overlay({
            mask: {},
            api: true,
            load: true,
            onBeforeLoad: function () {
                theHeader = this.getTrigger().attr("header");
                theFooter = this.getTrigger().attr("footer");
                theContentName = this.getTrigger().attr("contentname");
                theContent = jQuery('#' + theContentName).html();
                this.getOverlay().html('<div class="header"><div class="left">' + theHeader + '</div><div class="right" onmousedown="overlayElem.overlay().close();"></div></div><div class="content">' + theContent + '</div><div class="footer">' + theFooter + '</div>');

                this.getConf().top = (jQuery(window).height() / 2) - (jQuery(this.getOverlay()).height() / 2);
                this.getConf().left = (jQuery(window).width() / 2) - (jQuery(this.getOverlay()).width() / 2);
            }
        });
    });

    jQuery(".histoart").tooltip({
        tip: '#zonehistoart',
        delay: 0,
        position: "center right",
        offset: [0, 20],
        onBeforeShow: function () {
            theHeader = this.getTrigger().attr("header");
            theFooter = this.getTrigger().attr("footer");
            theContentName = this.getTrigger().attr("contentname");
            theContent = jQuery('#' + theContentName).html();
            this.getTip().html('<div class="header">' + theHeader + '</div><div class="content">' + theContent + '</div><div class="footer">' + theFooter + '</div>');
        }
    });

    jQuery(".information").tooltip({
        tip: '#zoneinfo',
        delay: 0,
        position: "center right",
        offset: [0, 20],
        onBeforeShow: function () {
            theHeader = this.getTrigger().attr("header");
            theFooter = this.getTrigger().attr("footer");
            theContent = this.getTrigger().attr("content");
            this.getTip().html('<div class="header">' + theHeader + '</div><div class="content">' + theContent + '</div><div class="footer">' + theFooter + '</div>');
        }
    });

    jQuery(".informationleft").tooltip({
        tip: '#zoneinfo',
        delay: 0,
        position: "center left",
        offset: [20, 0],
        onBeforeShow: function () {
            theDisplay = this.getTrigger().attr("display");
            theHeader = this.getTrigger().attr("header");
            theFooter = this.getTrigger().attr("footer");
            theContent = this.getTrigger().attr("content");
            this.getTip().html('<div class="header">' + theHeader + '</div><div class="content">' + theContent + '</div><div class="footer">' + theFooter + '</div>');
        }
    });

    jQuery(".addComment, .ExistPanierComments").tooltip({
        tip: '#zonecommentaires',
        delay: 0,
        position: "center left",
        offset: [20, 0],
        onBeforeShow: function () {
            theHeader = this.getTrigger().attr("header");
            theFooter = this.getTrigger().attr("footer");
            theajaxId = this.getTrigger().attr("ajaxid");
            theajaxType = this.getTrigger().attr("ajaxtype");
            theContent = SpelogAjaxObjects.GetCtrlPanierInfosForReading(theajaxId, theajaxType, null).value;

            this.getTip().html('<div class="header">' + theHeader + '</div><div class="content">' + theContent + '</div><div class="footer">' + theFooter + '</div>');
        }
    });

    jQuery(".addComment[rel]").live('click', function (e) {
        e.preventDefault();

        // load overlay
        jQuery(this).overlay({
            mask: {},
            api: true,
            load: true,
            closeOnClick: false,
            onBeforeLoad: function () {

                var panierid = this.getTrigger().attr("panierid");
                var theajaxtriggernom = this.getTrigger().attr("theajaxtriggernom");

                var content = SpelogAjaxObjects.GetCtrlPanierInfos(panierid, theajaxtriggernom, null).value;

                var overlay = this.getOverlay();
                overlay.html(content);

                var trigger = this.getTrigger();
                var overlayConfig = this.getConf();

                overlayConfig.top = trigger.offset().top;
                overlayConfig.left = trigger.offset().left - 300; // décalage de 300px vers la gauche

            },
            onLoad: function () {
                var self = this;
                closers = this.getOverlay().find(".close");
                closers.click(function (e) {
                    self.close();
                });
            }
        });
    });

    jQuery(document).ready(function () {
        if (!!('ontouchstart' in window)) {
            jQuery('.scroller').touchScroll();
        }
    });
});


/*******************************************************/
/*!
* jQuery scrollintoview() plugin and :scrollable selector filter
*
* Version 1.8 (14 Jul 2011)
* Requires jQuery 1.4 or newer
*
* Copyright (c) 2011 Robert Koritnik
* Licensed under the terms of the MIT license
* http://www.opensource.org/licenses/mit-license.php
*/

(function ($) {
    var converter = {
        vertical: { x: false, y: true },
        horizontal: { x: true, y: false },
        both: { x: true, y: true },
        x: { x: true, y: false },
        y: { x: false, y: true }
    };

    var settings = {
        duration: "fast",
        direction: "both"
    };

    var rootrx = /^(?:html)$/i;
    // gets border dimensions
    var borders = function (domElement, styles) {
        styles = styles || (document.defaultView && document.defaultView.getComputedStyle ? document.defaultView.getComputedStyle(domElement, null) : domElement.currentStyle);
        var px = document.defaultView && document.defaultView.getComputedStyle ? true : false;
        var b = {

            top: (parseFloat(px ? styles.borderTopWidth : $.css(domElement, "borderTopWidth")) || 0),

            left: (parseFloat(px ? styles.borderLeftWidth : $.css(domElement, "borderLeftWidth")) || 0),

            bottom: (parseFloat(px ? styles.borderBottomWidth : $.css(domElement, "borderBottomWidth")) || 0),

            right: (parseFloat(px ? styles.borderRightWidth : $.css(domElement, "borderRightWidth")) || 0)

        };

        return {

            top: b.top,

            left: b.left,

            bottom: b.bottom,

            right: b.right,

            vertical: b.top + b.bottom,

            horizontal: b.left + b.right

        };

    };



    var dimensions = function ($element) {

        var win = $(window);

        var isRoot = rootrx.test($element[0].nodeName);

        return {

            border: isRoot ? { top: 0, left: 0, bottom: 0, right: 0} : borders($element[0]),

            scroll: {

                top: (isRoot ? win : $element).scrollTop(),

                left: (isRoot ? win : $element).scrollLeft()

            },

            scrollbar: {

                right: isRoot ? 0 : $element.innerWidth() - $element[0].clientWidth,

                bottom: isRoot ? 0 : $element.innerHeight() - $element[0].clientHeight

            },

            rect: (function () {

                var r = $element[0].getBoundingClientRect();

                return {

                    top: isRoot ? 0 : r.top,

                    left: isRoot ? 0 : r.left,

                    bottom: isRoot ? $element[0].clientHeight : r.bottom,

                    right: isRoot ? $element[0].clientWidth : r.right

                };

            })()

        };

    };

    $.fn.extend({

        scrollintoview: function (options) {

            /// <summary>Scrolls the first element in the set into view by scrolling its closest scrollable parent.</summary>

            /// <param name="options" type="Object">Additional options that can configure scrolling:

            ///        duration (default: "fast") - jQuery animation speed (can be a duration string or number of milliseconds)

            ///        direction (default: "both") - select possible scrollings ("vertical" or "y", "horizontal" or "x", "both")

            ///        complete (default: none) - a function to call when scrolling completes (called in context of the DOM element being scrolled)

            /// </param>

            /// <return type="jQuery">Returns the same jQuery set that this function was run on.</return>



            options = $.extend({}, settings, options);

            options.direction = converter[typeof (options.direction) === "string" && options.direction.toLowerCase()] || converter.both;



            var dirStr = "";

            if (options.direction.x === true) dirStr = "horizontal";

            if (options.direction.y === true) dirStr = dirStr ? "both" : "vertical";



            var el = this.eq(0);

            var scroller = el.closest(":scrollable(" + dirStr + ")");



            // check if there's anything to scroll in the first place

            if (scroller.length > 0) {

                scroller = scroller.eq(0);



                var dim = {

                    e: dimensions(el),

                    s: dimensions(scroller)

                };



                var rel = {

                    top: dim.e.rect.top - (dim.s.rect.top + dim.s.border.top),

                    bottom: dim.s.rect.bottom - dim.s.border.bottom - dim.s.scrollbar.bottom - dim.e.rect.bottom,

                    left: dim.e.rect.left - (dim.s.rect.left + dim.s.border.left),

                    right: dim.s.rect.right - dim.s.border.right - dim.s.scrollbar.right - dim.e.rect.right

                };



                var animOptions = {};



                // vertical scroll

                if (options.direction.y === true) {

                    if (rel.top < 0) {

                        animOptions.scrollTop = dim.s.scroll.top + rel.top;

                    }

                    else if (rel.top > 0 && rel.bottom < 0) {

                        animOptions.scrollTop = dim.s.scroll.top + Math.min(rel.top, -rel.bottom);

                    }

                }



                // horizontal scroll

                if (options.direction.x === true) {

                    if (rel.left < 0) {

                        animOptions.scrollLeft = dim.s.scroll.left + rel.left;

                    }

                    else if (rel.left > 0 && rel.right < 0) {

                        animOptions.scrollLeft = dim.s.scroll.left + Math.min(rel.left, -rel.right);

                    }

                }



                // scroll if needed

                if (!$.isEmptyObject(animOptions)) {

                    if (rootrx.test(scroller[0].nodeName)) {

                        scroller = $("html,body");

                    }

                    scroller

                        .animate(animOptions, options.duration)

                        .eq(0) // we want function to be called just once (ref. "html,body")

                        .queue(function (next) {

                            $.isFunction(options.complete) && options.complete.call(scroller[0]);

                            next();

                        });

                }

                else {

                    // when there's nothing to scroll, just call the "complete" function

                    $.isFunction(options.complete) && options.complete.call(scroller[0]);

                }

            }



            // return set back

            return this;

        }

    });



    var scrollValue = {

        auto: true,

        scroll: true,

        visible: false,

        hidden: false

    };



    $.extend($.expr[":"], {

        scrollable: function (element, index, meta, stack) {

            var direction = converter[typeof (meta[3]) === "string" && meta[3].toLowerCase()] || converter.both;

            var styles = (document.defaultView && document.defaultView.getComputedStyle ? document.defaultView.getComputedStyle(element, null) : element.currentStyle);

            var overflow = {

                x: scrollValue[styles.overflowX.toLowerCase()] || false,

                y: scrollValue[styles.overflowY.toLowerCase()] || false,

                isRoot: rootrx.test(element.nodeName)

            };



            // check if completely unscrollable (exclude HTML element because it's special)

            if (!overflow.x && !overflow.y && !overflow.isRoot) {
                return false;
            }

            var size = {
                height: {
                    scroll: element.scrollHeight,
                    client: element.clientHeight
                },
                width: {
                    scroll: element.scrollWidth,
                    client: element.clientWidth
                },
                // check overflow.x/y because iPad (and possibly other tablets) don't dislay scrollbars
                scrollableX: function () {
                    return (overflow.x || overflow.isRoot) && this.width.scroll > this.width.client;
                },
                scrollableY: function () {
                    return (overflow.y || overflow.isRoot) && this.height.scroll > this.height.client;
                }
            };
            return direction.y && size.scrollableY() || direction.x && size.scrollableX();
        }
    });
})(jQuery);
/*******************************************************/


{ // a dummy block, so I can collapse all the meta stuff in the editor
    /****************************************************************************
    * jQuery 1.3.x plugin to shorten styled text to fit in a block, appending
    * an ellipsis ("...", &hellip;, Unicode: 2026) or other text.
    * (Only supports ltr text for now.)
    *
    * This is achieved by placing the text of the 'selected' element (eg. span or
    * div) inside a table and measuring its width. If it's too big to big to fit in
    * the element's parent block it's shortened and measured again until it (and
    * appended ellipsis or text) fits inside the block. A tooltip on the 'selected'
    * element displays the full original text.
    *
    * If the browser supports truncating text using the 'text-overflow:ellipsis'
    * CSS property then that will be used (if the text to append is the default
    * ellipsis).
    *
    * If the text is truncated by the plugin any markup in the text will be
    * stripped (eg: "<a" starts stripping, "< a" does not). This behaviour is
    * dictated by the jQuery .text(val) method.
    * The appended text may contain HTML however (a link or span for example).
    *
    * Usage Example ('selecting' a div with an id of "element"):

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    <script type="text/javascript" src="jquery.textTruncate.js"></script>
    <script type="text/javascript">
    $(function() {
    $("#element").textTruncate();
    });
    </script>

    * By default the plugin will use the parent block's width as maximum width and
    * an ellipsis as appended text when truncating.
    *
    * There are three ways of configuring the plugin:
    *
    * 1) Passing a configuration hash as the plugin's argument, eg:

    .textTruncate({
    width: 300,
    tail: ' <a href="#">more</a>',
    tooltip: false
    });

    * 2) Using two optional arguments (deprecated!):
    * width = the desired pixel width, integer
    * tail = text/html to append when truncating
    *
    * 3) By changing the plugin defaults, eg:

    $.fn.textTruncate.defaults.tail = ' <a href="#">more</a>';

    * Note: there is no default width (unless you create one).
    *
    * You may want to set the element's css to {visibility:hidden;} so it won't
    * initially flash at full width.
    *
    *
    * Created by M. David Green (www.mdavidgreen.com) in 2009. Free to use for
    * personal or commercial purposes under MIT (X11) license with no warranty
    *
    * Heavily modified/simplified/improved by Marc Diethelm (http://web5.me/).
    *
    ****************************************************************************/
}


(function ($) {

    $.fn.textTruncate = function () {

        var userOptions = {};
        var args = arguments; // for better minification
        var func = args.callee // dito; and much shorter than $.fn.textTruncate

        if (args.length) {

            if (args[0].constructor == Object) {
                userOptions = args[0];
            } else if (args[0] == "options") {
                return $(this).eq(0).data("options-truncate");
            } else {
                userOptions = {
                    width: parseInt(args[0]),
                    tail: args[1]
                }
            }
        }

        this.css("visibility", "hidden"); // Hide the element(s) while manipulating them

        // apply options vs. defaults
        var options = $.extend({}, func.defaults, userOptions);


        /**
        * HERE WE GO!
        **/
        return this.each(function () {

            var $this = $(this);
            $this.data("options-truncate", options);

            /**
            * If browser implements text-overflow:ellipsis in CSS and tail is "...", use it!
            **/
            if (options.tail == "..." && func._native) {

                this.style[func._native] = "ellipsis";
                /*var css_obj = {}
                css_obj[func._native] = "ellipsis";
                $this.css(css_obj);*/
                $this.css("visibility", "visible");

                return true;
            }

            var width = options.width || $this.parent().width();

            var text = $this.text();
            var textlength = text.length;
            var css = "padding:0; margin:0; border:none; font:inherit;";
            var $table = $('<table style="' + css + 'width:auto;zoom:1;position:absolute;"><tr style="' + css + '"><td style="' + css + 'white-space:nowrap;">' + options.tail + '</td></tr></table>');
            var $td = $("td", $table);
            $this.html($table);

            var tailwidth = $td.width();
            var targetWidth = width - tailwidth;

            $td.text(text);

            if ($td.width() > width) {
                if (options.tooltip) {
                    $this.attr("title", text);
                }

                while ($td.width() >= targetWidth) {
                    textlength--;
                    $td.html($td.html().substring(0, textlength)); // .html(val) is faster than .text(val) and we already used .text(val) to strip/escape html
                }

                text = $.trim($td.html());
                $this.html(text + options.tail);

            } else {
                $this.html(text);
            }

            this.style.visibility = "visible";

            return true;
        });

        return true;

    };


    var css = document.documentElement.style;
    var _native = false;

    if ("textOverflow" in css) {
        _native = "textOverflow";
    } else if ("OTextOverflow" in css) {
        _native = "OTextOverflow";
    }

    $.fn.textTruncate._native = _native;


    $.fn.textTruncate.defaults = {
        tail: "&hellip;",
        tooltip: true
    };

})(jQuery);

