/// <reference path="jquery-1.4.2.min.js" />
/// <reference path="jquery-ui-1.8.6.custom.min.js" />

/*********************************
General Functions
**********************************/

function redirect(page) {
    window.location.href = page
}

function OpenWindow(page, params) {
    open_window(page, params)
}

function open_window(page, params) {
    window.open(page, "popup", params)
}

function IsNumeric(sText) {
    var ValidChars = "0123456789.";
    var IsNumber = true;
    var Char;

    for (i = 0; i < sText.length && IsNumber == true; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
        }
    }
    return IsNumber;
}

function stopBubbling(e) {

    if (!e)
        e = window.event;

    if (e.stopPropagation)
        e.stopPropagation();

    if (e.preventDefault)
        e.preventDefault();

    e.cancelBubble = true;
    e.cancel = true;
    e.returnValue = false;
    return false;

}

function DefaultButton(btnID, e) {
    default_button(btnID, e)
}

function default_button(btnID, e) {

    var btn = document.getElementById(btnID);

    if (document.all) {
        if (e.keyCode == 13) {
            stopBubbling(e)
            btn.click();
        }
    } else if (document.getElementById || document.layers) {


        if (e.which == 13) {

            if (btn && btn.tagName == 'A') {

                if (btn.onclick) {
                    result = btn.onclick();
                }

                if (typeof (result) == 'undefined' || result) {
                    eval(btn.getAttribute('href'));
                }

            } else if (btn && btn.click) {

                stopBubbling(e)
                btn.click();

            } else if (btn && btn.onclick) {

                var temp = eval(btn.onclick);
                if (temp) {
                    stopBubbling(e)
                    temp(e);
                }

            }
        }
    }
}

var emailSignupInitialText;
var emailSignupTbx;

function EmailSignup(tbxID, initialText, listName, mobile, e) {
    var tbx = $get(tbxID);

    if (tbx) {

        emailSignupInitialText = initialText;
        emailSignupTbx = tbx;

        if (tbx.value == '' || tbx.value == initialText) {
            setTimeout('alert(\'Invalid Email Address\');', 100);
        } else {
            if (mobile) {
                Saffire.Core.Web.WebServices.GeneralService.EmailSignup(tbx.value, listName, EmailSignupSuccessMobile, EmailSignupError);
            } else {
                Saffire.Core.Web.WebServices.GeneralService.EmailSignup(tbx.value, listName, EmailSignupSuccess, EmailSignupError);
            }

        }
    } else {
        setTimeout('alert(\'Invalid Email Address\');', 100);
    }
}

function EmailSignupSuccess(result) {
    if (result.result == 1) {
        emailSignupTbx.value = emailSignupInitialText;

        OpenModal('modal', 'I_thanks.aspx?e=' + result.message, '510px', '140px', 'no')
    } else {
        alert(result.message)
    }
}

function EmailSignupSuccessMobile(result) {
    if (result.result == 1) {
        var redirectPage = 'I_thanks.aspx?e=' + result.message
        emailSignupTbx.value = emailSignupInitialText;

        window.location = redirectPage;
    } else {
        alert(result.message)
    }
}

function EmailSignupError(result) {
    alert(result.message);
}


function Search(initialText, tbx) {
    if (tbx) {
        var Query = tbx.value;
        if (Query == '' || Query == initialText) {
            setTimeout('alert(\'Invalid Search Criteria\');', 100)
        } else {
            redirect('search.aspx?q=' + Query);
        }
    }
}


/***IMAGE CACHING FUNCTIONS***/
function MM_swapImgRestore() { //v3.0

    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; } 
    }
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}
/***/
/**MODAL MANAGEMENT**/

var CurrentModal;
var CurrentModalOnCloseDoPostBack = false;
var CurrentModalOnCloseTargetID = '';
var CurrentModalOnCloseArgument = '';
var CurrentModalContext = null;
var CurrentModalOpeningParent = null;
var CurrentModalOnCloseCallbackFunction = '';

function OpenModal(behaviorID, url, width, height, OpenModalParams) {
    var m = $find(behaviorID);
    if (m) {

        CurrentModal = m

        var scrolling = 'NO';

        if (OpenModalParams) {
            CurrentModalOnCloseDoPostBack = OpenModalParams.OnClosePostBack;
            CurrentModalOnCloseTargetID = OpenModalParams.OnCloseTargetID;
            CurrentModalOnCloseArgument = OpenModalParams.OnCloseArgument;

            CurrentModalContext = OpenModalParams.UserContext;
            CurrentModalOpeningParent = OpenModalParams.Parent;
            CurrentModalOnCloseCallbackFunction = OpenModalParams.OnCloseCallbackFunction;

            if (OpenModalParams.ScrollFrame && OpenModalParams.ScrollFrame == true) {
                scrolling = 'auto';
            }
        }

        if (url != '') {
            var mContent = $get(behaviorID + '_content')
            if (mContent) {
                mContent.innerHTML = '<iframe src=\'' + url + '\' width=\'' + width + '\' height=\'' + height + '\' scrolling=\'' + scrolling + '\' frameborder=\'0\'/>';
            }
        }

        m.show()
        return true;
    } else {
        return false;
    }

}

function OpenModalParams() {
    var OnClosePostBack = false;
    var OnCloseTargetID = '';
    var OnCloseArgument = '';
    var UserContext = null;
    var OnCloseCallbackFunction = null;
    var Parent = null;
    var ScrollFrame = false;
}



function HideModal(HideModalParams) {

    var m = CurrentModal;

    if (m) {

        var mContent = $get(m._id + '_content')
        if (mContent) {
            mContent.innerHTML = '';
        }

        m.hide();

        var _EventArgs = (CurrentModalOnCloseArgument == '') ? '' : CurrentModalOnCloseArgument;
        if (HideModalParams) {
            _EventArgs = (HideModalParams.EventArgs == 'undefined') ? '' : HideModalParams.EventArgs;

            if (HideModalParams.CancelOnCloseDoPostBack) {
                CurrentModalOnCloseDoPostBack = false;
            }
        }


        if (CurrentModalOnCloseDoPostBack) {

            if (CurrentModalOpeningParent) {
                CurrentModalOpeningParent.UpdatePage(CurrentModalOnCloseTargetID, _EventArgs);
            } else {
                UpdatePage(CurrentModalOnCloseTargetID, _EventArgs);
            }

        } else if (CurrentModalOnCloseCallbackFunction) {

            var _tmp = CurrentModalOnCloseCallbackFunction;

            if (typeof (_tmp) == 'function') {
                _tmp(_EventArgs, CurrentModalContext);
            } else {

                _tmp = _tmp + '({ \'EventTargetID\':\'' + CurrentModalOnCloseTargetID + '\', \'EventArgs\':\'' + _EventArgs + '\' })'

                if (CurrentModalOpeningParent) {
                    CurrentModalOpeningParent.eval(_tmp);
                } else {
                    eval(_tmp);
                }
            }
        }

        CurrentModal = null;
        CurrentModalOnCloseDoPostBack = false;
        CurrentModalOnCloseTargetID = '';
        CurrentModalOpeningParent = null;

    }
}

function HideModalParams() {
    var EventArgs;
    var CancelOnCloseDoPostBack = false;
}

function ModalOnCloseCallbackParams() {
    var EventTargetID = '';
    var EventArgs = '';
}

/***/
/***PopupControlExtender***/

function ShowQuickDialog(behaviorID, params) {
    var pce = $find(behaviorID);
    if (pce) {
        if (params) {
            pce._popupBehavior.set_parentElementID(params.targetElementID);
            pce.set_OffsetX(params.offSetX);
            pce.set_OffsetY(params.offSetY);
        }

        pce.showPopup();
    }
}

function HideQuickDialog(behaviorID) {
    var pce = $find(behaviorID);
    if (pce) {
        pce.hidePopup();
    }
}

function ShowQuickDialogParams() {
    offSetX = 0;
    offSetY = 0;
    targetElementID = '';
}

/***/

function UpdatePage(target, args) {
    setTimeout('__doPostBack(\'' + target + '\', \'' + args + '\')', 100)
}

function ChangePaginationPageSize(ddlID, baseURL) {
    var ddl = $get(ddlID);

    if (baseURL.indexOf('?') == -1) {
        baseURL += "?"
    } else {
        baseURL += "&"
    }

    redirect(baseURL + 'cp=1&ps=' + ddl[ddl.selectedIndex].value);
}

function GetFlashMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    } else {
        return document[movieName]
    }
}

function ClearDefaultText(tbx, defaultText) {

    if (tbx) {
        if (tbx.value == defaultText) {
            tbx.value = '';
        }
    }
}

/***********************************************
* Textarea Maxlength script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function ismaxlength(obj, maxLength) {
    var mlength = obj.getAttribute ? parseInt(maxLength) : ""
    if (obj.getAttribute && obj.value.length > mlength)
        obj.value = obj.value.substring(0, mlength)
}

/***********************************************
* Found at http://groups.google.com/group/microsoft.public.dotnet.framework.aspnet/msg/f2234ba565b8effa?dmode=source&output=gplain
***********************************************/

function SetUniqueRadioButton(nameregex, current) {
    re = new RegExp(nameregex);
    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i]
        if (elm.type == 'radio') {
            if (re.test(elm.name)) {
                elm.checked = false;
            }
        }
    }
    current.checked = true;
}


/*********************************
Fan Pick 
**********************************/

function FanPick(sender, entityTypeName, entityID) {

    Saffire.Events.Web.WebServices.EventsService.SaveFanPick(entityTypeName, entityID
                                , function (result, context) {
                                    if (result && result.result == 1) {

                                        var bodyOffsetTop = $(window).scrollTop();
                                        context.childNodes[0].src = SITEBASEURL + 'App_Themes/' + SITETHEME + '/images/icon_isafan.gif';

                                        window.scrollTo(0, bodyOffsetTop); //ie fix for versions 7 and under

                                        sender.onclick = null;

                                        Saffire.Events.Web.WebServices.EventsService.GetEventFanPickCount(entityID
                                            , function (result, context) {
                                                if (result) {
                                                    if (result > 0) {
                                                        $(context).parent().children().filter("span").text(result + ' Fans')
                                                    }
                                                }
                                            }
                                            , function () { }
                                            , sender);

                                    }
                                }
                                , function (sender, args) { alert(args.message) }
                                , sender
                                );
}


/*********************************
My Pick 
**********************************/

var _currentMyPickSender = null;

function MyEventPick(sender, entityID, userID, onSuccessCallback) {

    _currentMyPickSender = sender;

    Saffire.Core.Web.WebServices.UsersService.IsAuthenticated(userID
                    , function (result) {

                        if (result) {

                            MyEventPickSave({ 'userID': userID, 'eventID': entityID, 'successCallback': onSuccessCallback, 'sender': sender })

                        } else {

                            OpenModal('modal', SITEBASEURL + 'i_login.aspx', '600px', '435px', { 'OnClosePostBack': false, 'UserContext': { 'sender': sender, 'eventID': entityID, 'successCallback': onSuccessCallback, 'sender': sender }, 'OnCloseCallbackFunction':
                            function (userID, context) {

                                if (userID > 0) {
                                    MyEventPickSave({ 'eventID': entityID, 'userID': userID, 'successCallback': context.successCallback, 'sender': context.sender });
                                }

                            } 
                            }
                            );
                        }

                    }
                    , function (result) {
                        alert("Error communicating with the server")
                    })

}

function MyEventPickSave(data) {

    var userID = data.userID;
    var eventID = data.eventID;

    Saffire.Events.Web.WebServices.EventsService.SaveMyEventPick(eventID, userID
                                , function (result) {
                                    if (result.result == 1) {

                                        var bodyOffsetTop = $(window).scrollTop();
                                        var thanksDialog = $('<div id="myEventPickDialog" class="modal_content" Style="border: solid 10px #ffffff; padding: 15px;"></div>').insertBefore(data.sender);
                                        thanksDialog.html('<h1>Thanks!</h1>Event added to My Events')

                                        $(thanksDialog).dialog({
                                            height: 200
                                            , width: 320
                                            , closeText: ''
                                            , show: 'slide'
                                            , collision: 'fit'
                                            , close: function () { $('#myEventPickDialog').remove() }
                                        })

                                        $(thanksDialog).dialog('open').position({ my: "center", at: "center", of: window }).delay(3500).hide('slide');

                                        window.scrollTo(0, bodyOffsetTop); //ie fix for versions 7 and under


                                        if (data.sender) {
                                            data.sender.onclick = null;
                                            data.sender.title = 'Saved to My Events'
                                            data.sender.innerHTML = 'Saved to My Events'
                                        }

                                        if (typeof (data.successCallback) == 'function') {
                                            data.successCallback()
                                        }

                                    }
                                }
                                , function (sender, args) { alert(args.message) }

                                );
}


function RemoveMyEventPick(sender, eventID, userID, callbackFunction) {

    var confirmed = confirm('Are you sure you want to remove this event from My Picks?');
    if (confirmed) {

        Saffire.Events.Web.WebServices.EventsService.RemoveMyEventPick(eventID, userID
            , function (result, context) {
                if (result.result == 1) {
                    if (callbackFunction != 'undefined') {
                        if (typeof (callbackFunction) == 'function') {
                            callbackFunction();
                        } else {
                            eval(callbackFunction);
                        }
                    }
                }
            }
            , function (sender, args) { alert(args.message) }
            , sender
        );

    }
}

/*******************************
Audio Button
********************************/

var CurrentImgID = '';
var CurrentTrack = '';

function playSoundClip(track, imgID) {

    var isPlayCommand = true;

    if (CurrentImgID != '') {
        if (CurrentImgID != imgID) {
            stopSoundClip()
        } else {
            isPlayCommand = false
        }
    }

    var player = getSoundClipPlayer();
    if (player) {
        player.PlayMusic(track);
        swapAudioClipImg(imgID)
        if (isPlayCommand) {
            CurrentImgID = imgID;
            CurrentTrack = track;
        } else {
            CurrentImgID = '';
            CurrentTrack = '';
        }
    }
}

function stopSoundClip() {
    swapAudioClipImg(CurrentImgID)
    CurrentImgID = '';
    CurrentTrack = '';
}

function getSoundClipPlayer() {
    var player = GetFlashMovie('soundClip');
    return player
}

function swapAudioClipImg(imgID) {
    var img = $get(imgID);
    if (img) {
        if (img.src.indexOf('music_on.gif') != -1) {
            img.src = SITEBASEURL + 'App_Themes/' + SITETHEME + '/images/music_off.gif';
        } else {
            img.src = SITEBASEURL + 'App_Themes/' + SITETHEME + '/images/music_on.gif';
        }
    }
}

function CreateAudioFlashPlayer() {

    if ($get('soundClipContainer') == null) {

        window["soundClip"] = new Object()
        var swf = new deconcept.SWFObject(noCacheIE(SITEBASEURL + "Events/Flash/music_player.swf"), "soundClip", "24", "19", "8", "#FFFFFF");
        swf.addParam("wmode", "transparent");

        $('<div id="soundClipContainer"></div>').appendTo('body');

        swf.write('soundClipContainer');

    }

}

/***********************
Users Service
************************/
var userIsAuthenticated = false;
function isAuthenticated(uid) {

    Saffire.Core.Web.WebServices.UsersService.IsAuthenticated(uid
                    , function (result) {
                        userIsAuthenticated = result;
                    }
                    , function (result) {
                        alert("Error communicating with the server")
                    })

    return userIsAuthenticated;
}

/*****************************
Calendar Service
******************************/

function ProduceVCalendarFile(entityType, entityID) {

    $('<iframe />', {
        id: 'vCalFrame'
        , src: SITEBASEURL + 'services/calendarFileServer.aspx?entityType=' + entityType + '&id=' + entityID
        , style: "width:0px; height:0px; display:none"
    }).appendTo('body');

}

/*******************************
Audio Button
********************************/

var CurrentImgID = '';
var CurrentTrack = '';

function playSoundClip(track, imgID) {

    var isPlayCommand = true;

    if (CurrentImgID != '') {
        if (CurrentImgID != imgID) {
            stopSoundClip()
        } else {
            isPlayCommand = false
        }
    }

    var player = getSoundClipPlayer();
    if (player) {
        player.PlayMusic(track);
        swapAudioClipImg(imgID)
        if (isPlayCommand) {
            CurrentImgID = imgID;
            CurrentTrack = track;
        } else {
            CurrentImgID = '';
            CurrentTrack = '';
        }
    }
}

function stopSoundClip() {
    swapAudioClipImg(CurrentImgID)
    CurrentImgID = '';
    CurrentTrack = '';
}

function getSoundClipPlayer() {
    var player = GetFlashMovie('soundClip');
    return player
}

function swapAudioClipImg(imgID) {
    var img = $get(imgID);
    if (img) {
        if (img.src.indexOf('music_on.gif') != -1) {
            img.src = SITEBASEURL + 'App_Themes/' + SITETHEME + '/images/music_off.gif';
        } else {
            img.src = SITEBASEURL + 'App_Themes/' + SITETHEME + '/images/music_on.gif';
        }
    }
}

function CreateAudioFlashPlayer() {

    if ($get('soundClipContainer') == null) {

        window["soundClip"] = new Object()
        var swf = new deconcept.SWFObject(noCacheIE(SITEBASEURL + "Events/Flash/music_player.swf"), "soundClip", "24", "19", "8", "#FFFFFF");
        swf.addParam("wmode", "transparent");

        $('<div id="soundClipContainer"></div>').appendTo('body');

        swf.write('soundClipContainer');

    }

}

/**photo gallery modal**/

(function ($) {

    $.fn.dialogPhotoGallery = function (options) {

        var $this = this;

        var _defaultOptions = {
            startID: 0,
            action: '',
            datasource: null,
            width: 400,
            height: 400
        }

        if (typeof (options) == 'string') {
            var action = options;

            options = _defaultOptions

            if (action == 'show') {
                options.action = "show";
            } else if (action == 'close') {
                options.action = "close";
            }

        } else {
            options = $.extend(_defaultOptions, options);
        }


        if (options.action == "show") {
            show();
        } else if (options.action == "close") {
            close();
        } else {
            set_currentID(0);
            set_currentIndex(0);
            init()
        }

        function init() {


            $this.dialog({
                modal: true,
                draggable: false,
                closeText: '',
                autoOpen: false,
                width: options.width,
                height: options.height
            });

            if (get_datasource() == null && options.datasource != null) {
                set_datasource(options.datasource);
            }

            $this.find(".previousButton").bind("click", _showPreviousPhoto);
            $this.find(".nextButton").bind("click", _showNextPhoto);
            $this.find(".closeButton").bind("click", close);

        }

        function show() {


            _setupDatasource()

            if (get_currentID() != options.startID) {
                set_currentID(options.startID);
                set_currentIndex(_getIDIndex(get_currentID()));
            }

            if (get_datasource().length > 0) {
                _setupPhoto(get_currentIndex())
            }

            _setupPreviousNextButtons()

            $this.dialog("open");
            $this.css("display", "block")

            $this.trigger("show", { currentPhotoID: get_currentID() })

        }

        function close() {

            $this.dialog("close");
            $this.css("display", "none")

            $this.trigger("closed")
        }

        /**Properties**/

        function get_datasource() { return $this.data("data") }
        function set_datasource(value) { $this.data("data", value) }

        function get_currentID() { return $this.data("currentID") }
        function set_currentID(value) { $this.data("currentID", value) }

        function get_currentIndex() { return $this.data("currentIndex") }
        function set_currentIndex(value) { $this.data("currentIndex", value) }

        /**PRIVATE MEMBERS**/

        function _setupDatasource() {

        }

        function _setupPhoto(indx) {
            var tmp = get_datasource();

            var $featImg = $(".featureImage");
            $featImg.attr('src', tmp[indx].src);
            $featImg.attr('alt', tmp[indx].caption);
            $this.find(".caption").html(tmp[indx].caption);

            set_currentIndex(indx);
            set_currentID(tmp[indx].id);
        }

        function _showPreviousPhoto() {


            var indx = get_currentIndex()

            if (indx > 0) {
                _setupPhoto(indx - 1);
                _setupPreviousNextButtons();
                $this.trigger("show", { currentPhotoID: get_currentID() })
            }

        }

        function _showNextPhoto() {

            var indx = get_currentIndex()

            if (indx < get_datasource().length - 1) {
                _setupPhoto(indx + 1);
                _setupPreviousNextButtons()
                $this.trigger("show", { currentPhotoID: get_currentID() });
            }
        }

        function _getIDIndex(id) {

            var tmp = get_datasource()

            if (id > 0) {
                for (var x = 0; x < tmp.length; x++) {
                    if (tmp[x].id == id) {
                        return x
                    }
                }
            }
            return 0;
        }

        function _setupPreviousNextButtons() {

            var tmp = get_datasource();
            var indx = get_currentIndex()


            if (indx == 0) {
                $this.find(".previousButton").css("display", "none")
            } else {
                $this.find(".previousButton").css("display", "block")
            }

            if (indx == tmp.length - 1) {
                $this.find(".nextButton").css("display", "none")
            } else {
                $this.find(".nextButton").css("display", "block")
            }
        }

        function _retrieveDataFromService(serviceMethod) {

        }

        return this;

    };
})(jQuery);

/* Copyright (c) 2007 Tom Deater (http://www.tomdeater.com)
* Licensed under the MIT License:
* http://www.opensource.org/licenses/mit-license.php
*/

(function ($) {
    /**
    * attaches a character counter to each textarea element in the jQuery object
    * usage: $("#myTextArea").charCounter(max, settings);
    */

    $.fn.charCounter = function (max, settings,hideTextCounter) {
        var counterDisplay = 'block';
        if(hideTextCounter){
        counterDisplay = 'none';
        }

        max = max || 100;
        settings = $.extend({
            container: "<span style='display:" + counterDisplay + "'></span>",
            classname: "charcounter",
            format: "<span class='tiny'><span class='number'>%1</span>&nbsp;left</span>",
            pulse: true,
            delay: 0
        }, settings);
        var p, timeout;

        function count(el, container) {
            el = $(el);
            if (el.val().length > max) {
                el.val(el.val().substring(0, max));
                if (settings.pulse && !p) {
                    pulse(container, true);
                };
            };
            if (settings.delay > 0) {
                if (timeout) {
                    window.clearTimeout(timeout);
                }
                timeout = window.setTimeout(function () {
                    container.html(settings.format.replace(/%1/, (max - el.val().length)));
                }, settings.delay);
            } else {
                container.html(settings.format.replace(/%1/, (max - el.val().length)));
            }
        };

        function pulse(el, again) {
            if (p) {
                window.clearTimeout(p);
                p = null;
            };
            el.animate({ opacity: 0.1 }, 100, function () {
                $(this).animate({ opacity: 1.0 }, 100);
            });
            if (again) {
                p = window.setTimeout(function () { pulse(el) }, 200);
            };
        };

        return this.each(function () {
            var container = (!settings.container.match(/^<.+>$/))
				? $(settings.container)
				: $(settings.container)
					.insertAfter(this)
					.addClass(settings.classname);
            $(this)
				.bind("keydown", function () { count(this, container); })
				.bind("keypress", function () { count(this, container); })
				.bind("keyup", function () { count(this, container); })
				.bind("focus", function () { count(this, container); })
				.bind("mouseover", function () { count(this, container); })
				.bind("mouseout", function () { count(this, container); })
				.bind("paste", function () {
				    var me = this;
				    setTimeout(function () { count(me, container); }, 10);
				});
            if (this.addEventListener) {
                this.addEventListener('input', function () { count(this, container); }, false);
            };
            count(this, container);
        });
    };

})(jQuery);

