/* Author: Ian Davis
   Author: Jason Spradlin <jason.spradlin@nerdery.com>
*/

// enclose function to prevent $ conflicts
(function($) {

    $(function() {

        var BWBR = BWBR || {};
        BWBR.layout = {
            resetBarHeight: function() {
                $('#insightsContainer .bar').css("height",$('#insightsContainer .active').height());
                $('#peopleContainer .bar').css("height",$('#peopleContainer .active').height());
                $('#careersContainer .bar').css("height",$('#careersContainer .active').height());
            }
        };

        /***********************/
        /** IDEA CLOUD PART 1 **/
        /***********************/
       
        var BWBR = BWBR || {};
        BWBR.ideaCloud = {

            /**
             * Initialize the BWBR.ideaCloud object
             *
             * @return void
             */
            init: function() {
                var ideaCloudObj = this;

                ideaCloudObj.resetLayout();

                $('#cloudKey a').unbind('click').click(function (e) {
                    e.preventDefault();
                    var idHolder = $(this).attr('id');
                    if (!$(this).hasClass('active')) {
                        $('.'+idHolder).show();
                    } else {
                        $('.'+idHolder).hide();
                    }
                    $(this).toggleClass('active');
                    $('#insightsContainer .bar').css("height",$('#insightsContainer .active').height());
                    ideaCloudObj.resetLayout();
                }, 500);
            },

            /**
             * Reset the layout of the idea cloud elements any time their
             * positions change.
             *
             * @return void
             */
            resetLayout: function() {

                $('.cloudPost').removeClass('cloud-1 cloud-2 cloud-3 cloud-4 cloud-5 cloud-6 rowOne rowTwo rowThree');
                $('.cloudPost:visible').each(function(index) {
                    $(this).addClass('cloud-' + ((index % 6) + 1));
                });
                rowArray = ['One', 'One', 'Two', 'Two', 'Two', 'Three'];
                $('.cloudPost:visible').each(function(index) {
                    $(this).addClass('row' + (rowArray[index % 6]));
                });

                // center post images vertically
                $('.cloudPost img').css(
                    'margin-top',
                    function() {
                        return -(($(this).height() - $(this).parent().height())/2);
                    }
                );
                
                this.truncateAllContent();
                
                // Fix for IE8 - Initial truncation is too short because of
                // delay in applying styles.
                var t = setTimeout(BWBR.ideaCloud.truncateAllContent, 200);

                BWBR.layout.resetBarHeight();
            },

            /**
             * Iterate through each cloud post and truncate the content to fit.
             *
             * @return void
             */
            truncateAllContent: function()
            {
                var ideaCloudObj = BWBR.ideaCloud;
                var content =  $('.cloudPost:visible');
                content.each(function() {
                    if ($(this).hasClass('rowOne')) {
                        var title = $(this).find('H2 A');
                        ideaCloudObj.truncateContent(title, 2);

                        var description = $(this).find('.body p .description');
                        ideaCloudObj.truncateContent(description, 3);
                    } else if ($(this).hasClass('rowTwo')) {
                        var title = $(this).find('H2 A');
                        ideaCloudObj.truncateContent(title, 2);

                        var description = $(this).find('.body p .description');
                        ideaCloudObj.truncateContent(description, 4);
                    } else {
                        var title = $(this).find('H2 A');
                        ideaCloudObj.truncateContent(title, 1);

                        var description = $(this).find('.body p .description');
                        ideaCloudObj.truncateContent(description, 2);
                    }
                });

            },

            /**
             * Truncate a content element's inner HTML to the prescribed number
             * of rows.
             *
             * @param container jQuery.fn The HTML element that needs to have
             *                            it's content truncated.
             * @param rows      integer   The number of rows to which the
             *                            content should be truncated.
             *
             * @return void
             */
            truncateContent: function(container, rows)
            {
                if (container.data('original_content')) {
                    container.html(container.data('original_content'));
                } else {
                    container.data('original_content', container.html());
                }
                var fontHeight = parseInt(container.css('font-size'));
                var maxHeight = ((fontHeight + 2) * rows) + 2;

                var iterations = 0;

                while ($(container).height() > maxHeight && iterations < 1000) {
                    iterations ++;
                    container.html(container.html().replace('...', '').replace(/.$/g, '').replace(/\s\w+$/g, '') + '...');
                }
            }
        };
        
        BWBR.ideaCloud.init();
        /******************/
        /**** Homepage ****/
        /******************/


        $('.homeISDItem').each(function(){
            $(this).data('oWidth', $(this).width());
            $(this).click(function(){
                $('.homeISDItem.active').removeClass('active');
                $('.superSmall').removeClass('superSmall').addClass('superSmallAnimating');
                $(this).addClass('animating');
                $(this).addClass('active');
                $(this).next().addClass('superSmall');
                $('.homeISDItem').each(function(){
                    if($(this).hasClass('animating')) {
                        $(this).animate({width:$(this).data('fWidth')},500,function(){
                            $(this).removeClass('animating');
                            $('.superSmallAnimating').removeClass('superSmallAnimating');
                        });
                        $(this).find('p').animate({opacity:1},500);
                    } else {
                        if ($(this).hasClass('superSmall')) {
                            $(this).animate({width:13},500);
                        } else {
                            $(this).animate({width:$(this).data('oWidth')},500);
                        }
                        $(this).find('p').animate({opacity:0},500);
                    }
                });
            });
        });

        var isActive = 0;


        /************************/
        /**** Search Toggles ****/
        /************************/


        $('#globalSearch button').click(function(event) {
            event.preventDefault();

            $('#globalSearch').children('input').stop();
            $('#globalSearch').stop();
            
            if (isActive == 1) {
                if ($('#globalSearch').children('input').val() == '' ) {
                    isActive = 0;
                    $('#globalSearch').children('input').animate({opacity: 0}, 'slow', function() {
                        $(this).css('display', 'none');
                        $('#globalSearch').animate({'width' : '27'}, 100);
                    }).blur();
                } else {
                    $('#globalSearchForm').submit();
                }
            } else {
                $('#globalSearch').animate({'width' : '170'}, 100, function() {
                    $('#globalSearch').children('input')
                                      .css('display', 'inline-block')
                                      .animate({opacity: 1}, 'slow')
                                      .focus();
                });
                isActive = 1;
            }

        });


        /****************************/
        /**** column link action ****/
        /****************************/
        /*
        $('.sectionInfo a').click(function(e) {
            e.preventDefault();
        });
        $('.active .sectionInfo a').click(function(e) {
            window.open($(this).attr('href'),'_self');
        });
        */
        $('.sectionCol').each(function(){
            if (!$(this).hasClass('active') && !$(this).parents('.openGallery').length && $(this).parents('#workContainer').length) {
                //$(this).css('width', $(this).find('img').width());
            } else if (!$(this).hasClass('active') && $(this).parents('.openGallery').length && $(this).parents('#workContainer').length) {
                $(this).css('width', 10);
            }
            $(this).click(function(){
                if (!$(this).hasClass('active')) {
                    if ($('.sectionCol.active').length) {
                        //goBackToWork();
                        window.open($(this).find('.sectionInfo a').attr('href'),'_self');
                    } else if ($(this).hasClass('externalLink')) {
                        window.open($(this).find('.sectionInfo a').attr('href'),'_blank');
                    } else {
                        window.open($(this).find('.sectionInfo a').attr('href'),'_self');
                    /*
                        $(this).addClass('animating');
                        $(this).addClass('active');
                        $('#mainWrap').animate({width:1060},300);
                        $('.sectionCol').delay(200).each(function(){
                            if($(this).hasClass('animating')) {
                                $(this).removeClass('animating');
                                $(this).removeClass('bar');
                                $(this).animate({width:960},500,function(){
                                    window.open($(this).find('.sectionInfo a').attr('href'),'_self');
                                });
                            } else {
                                $(this).animate({width:10},500);
                                $(this).addClass('bar');
                            }
                            $(this).find('.sectionThumb').hide();
                        });
                        $('.sectionIntroCol').delay(200).animate({width:0},500);
                        $('.sectionIntroCol *').hide();
                        $('.sectionContentCol').delay(200).animate({width:10},500);
                        $('.sectionContentCol *').hide();
                        */
                    }
                }
            });
        });

        /**********************/
        /**** Start Slider ****/
        /**********************/

        $('.slider').hSlider();

        /*****************************/
        /**** Workbook Add Button ****/
        /*****************************/

        $('#workbookDialog').toggle();
        $('#workbookDialog .close').click(function(){
           $("#workbookDialog").toggle();
        });

        $('#workbookAddRemove').click(function () {
            $(this).toggleClass('active');
        });
        $('.addRemove').unbind('click.workbook').bind('click.workbook', function(e) {
           e.preventDefault();
           var ajaxUrl = $(this).attr('href');
           $.ajax({
               url: ajaxUrl
               , success: function() {
                   $("#workbookDialog").css('visibility','visible');
                   $(".dialogTitleMessage").html("Congratulations");
                   $(".workbookDialogBody").html("You've added a page to your workbook.");
                   $("#workbookDialog").toggle();
               }
               , error: function() {
                   $(".dialogTitleMessage").html("Error");
                   $(".workbookDialogBody").html("There's been an error adding a page to your workbook.  Please try again or contact BWBR.");
                   $("#workbookDialog").toggle();
               }
           });
        });


        /******************************/
        /**** Workbook Submit Form ****/
        /******************************/



        $('.workbookBuildBtn').click(function () {
            if ($(this).hasClass('active')) {
                $('#workbook_build_proform').submit();
            } else {
                $(this).addClass('active');
                $(this).html('Build');
                $('#workbookBuildForm').show();
            }
        });

        $('#workbookBuildForm .close').click(function () {
            $(this).parent().hide();
            $('.workbookBuildBtn').removeClass('active');
            $('.workbookBuildBtn').html('Build Workbook');
        });

        if ($('#workbookBuildForm .fieldErrors').length) {
            $('.workbookBuildBtn').click();
        }



        /**********************************/
        /**** Workbook Preview Content ****/
        /**********************************/

        // If BWBR object doesn't exist, create it.
        var BWBR = BWBR || {};

        BWBR.workbook = {

            /**
             * Store whether an animation is active or not.
             *
             * @var boolean
             */
            isInAnimation: false,

            /**
             * Initialize the workbook object
             *
             * @return void
             */
            init: function()
            {
                var workbook = this;

                workbook.bindDefault();
                workbook.bindArrows();
                workbook.bindDelete();
                workbook.resetMoveableElements();

                $('#workbookContentList li').each(function() {
                    $(this).data('originalHeight', $(this).height());
                });

                // Reset the H3 padding-top to account for multi-line content.
                $('.moveable h3').css({
                    'padding-top': function() {
                        return (174 - $(this).height()) + 'px'
                    }
                })
            },

            /**
             * set default bindings
             *
             * @return void
             */
            bindDefault: function()
            {
                $('#workbookPage .workbookShowPreview, .workbookThumb.hasPreview').click(function () {
                    $(this).parent('.content').fadeOut('fast');
                    var listItem = $(this).closest('li');
                    listItem.animate({height:573},function(){
                            $(this).find('.previewContent').fadeIn('slow');
                        })
                });

                $('#workbookPage.subpage ul li .closePreview').click(function () {
                    $(this).parent('.previewContent').fadeOut('fast');
                    var listItem = $(this).closest('li');
                    listItem.animate({height:listItem.data('originalHeight')},function(){
                            $(this).find('.content').fadeIn('fast');
                        })
                });
            },

            /**
             * Bind the arrow buttons
             *
             * @return void
             */
            bindArrows: function()
            {
                var workbook = this;
                $('.moveable .moveableUp')
                    .unbind('click.workbook')
                    .bind('click.workbook', function() {
                        var listItem = $(this).closest('LI.moveable');
                        if (listItem.prev('.moveable').length) {
                            var swapItem = listItem.prev('.moveable');
                            workbook.movePage(listItem, swapItem, true);
                        }
                    }
                );
                $('.moveable .moveableDown')
                    .unbind('click.workbook')
                    .bind('click.workbook', function() {
                        var listItem = $(this).closest('LI.moveable');
                        if (listItem.next('.moveable').length) {
                            var swapItem = listItem.next('.moveable');
                            workbook.movePage(listItem, swapItem, false);
                        }
                    }
                );
            },

            /**
             * Bind the delete button.
             *
             * @return void
             */
            bindDelete: function()
            {
                var workbook = this;
                $('.moveable .moveabledDelete')
                    .unbind('click.workbook')
                    .bind('click.workbook', function() {
                        if (!workbook.getIsInAnimation()) {
                            workbook.setIsInAnimation(true);
                            var contentDiv = $(this).closest('.content');
                            var listItem = $(this).closest('.moveable');

                            var deleteUrl = $(this).attr('rel');

                            // send the delete request and don't remove until
                            // success
                            workbook.sendDeleteRequest(
                                deleteUrl,
                                function() {
                                    contentDiv.fadeOut('slow', function() {
                                        listItem.slideUp('slow', function() {
                                            listItem.remove();
                                            workbook.setIsInAnimation(false);
                                        });
                                    });
                                }, 1
                            );


                        }
                    }
                );
            },

            /**
             * Move the element whichever up or down in the list.
             *
             * @param currentItem jQuery.fn Item that will move
             * @param swapItem    jQuery.fn Item that it will be swapped with
             * @param moveUp      boolean   Item is moving up?  (otherwise down)
             *
             * @return void
             */
            movePage: function(currentItem, swapItem, moveUp) {
                var workbook = this;

                if (!workbook.getIsInAnimation()) {
                    workbook.setIsInAnimation(true);
                    var listClone = currentItem.clone(true);

                    if (moveUp) {
                        swapItem.before(listClone);
                    } else {
                        swapItem.after(listClone);
                    }

                    listClone.find('.content').fadeOut(0);
                    listClone.slideUp(0);

                    currentItem.find('.content').fadeOut('slow',function() {
                        currentItem.slideUp('slow', function() {
                            currentItem.remove();
                            workbook.sendUpdateSortRequest();
                            workbook.setIsInAnimation(false);
                        });
                        listClone.slideDown('slow', function() {
                            listClone.find('.content').fadeIn('slow', function() {

                            });
                        })
                    });
                }
            },

            /**
             * Reset the greyed out arrows for the first and last elements.
             * @return void
             */
            resetMoveableElements: function() {
                $('.moveable').removeClass('first').removeClass('last');
                $('.moveable:first').addClass('first');
                $('.moveable:last').addClass('last');
            },

            /**
             * setter for this.isInAnimation
             *
             * @param value boolean
             *
             * @return BWBR.workbook
             */
            setIsInAnimation: function(value)
            {
                if (typeof(value) === 'boolean') {
                    this.isInAnimation = value;
                } if (value === true) {
                    $('.moveable').addClass('first').addClass('last');
                } else {
                    this.resetMoveableElements();
                }
                return this;
            },

            /**
             * getter for this.isInAnimation
             *
             * @return boolean
             */
            getIsInAnimation: function()
            {
                return this.isInAnimation;
            },

            sendDeleteRequest: function(url, callback, attempt)
            {
                var workbook = this;
                jQuery.ajax({
                    url    : url,
                    type   : "GET",
                    success: function(data){
                        if (typeof(callback) == "function") {
                            callback();
                        }
                    },
                    error  : function() {
                        // try again, but only once.
                        if (attempt === 1) {
                            attempt ++;
                            workbook.sendDeleteRequest(url, callback, attempt);
                        }
                    }
                });
            },

            sendUpdateSortRequest: function(callback)
            {
                var moveableListArray = new Array();
                $('.moveable').each(function() {
                    moveableListArray.push($(this).attr('rel'));
                });
                var moveableList = moveableListArray.join('|');

                var url = BWBR_updateUrl || '/';
                url += '&updated_list=' + moveableList;
                url += '&timestamp=' + new Date().getTime();

                jQuery.ajax({
                    url    : url,
                    type   : "GET",
                    success: function(data){
                        if (typeof(callback) == "function") {
                            callback();
                        }
                    }
                });

            }

        };

        BWBR.workbook.init();



        /**********************/
        /**** prize action ****/
        /**********************/



        $('#prizeProcess span').click(function () {
            $('.active').removeClass('active');
            $(this).parent().addClass('active');
        });



        /**************/
        /**** work ****/
        /**************/



        $('#workProjectList .sliderItem a').click(function(e) {
            e.preventDefault();
        });

        $('#workProjectList .sliderItem').click(function(e){
            e.stopPropagation();
            if ($(this).find('a:first').attr('href')) {
                window.open($(this).find('a:first').attr('href'),'_self');
            }
            /*
            $(this).addClass('animate');
            $(this).parent().animate({left:0},500);
            $('#workProjectList .sliderItem').each(function(){
                if ($(this).hasClass('animate')) {
                    $(this).animate({width:960},500, function(){
                        window.open($(this).find('a:first').attr('href'),'_self');
                    });
                } else {
                    $(this).animate({width:0},500);
                }
                $(this).find('img').hide();
            });
            */
        });

        $('#workNavShelf').delay(500).slideDown(400);

        $('#workGalleryShelf').click(function(){
            if (!$(this).hasClass('active')) {
                $('#galleryPanel').animate({'left':0},300);
                $('#teamPanel').animate({'left':760},300);
                $('#detailsPanel').animate({'left':760},300);
            }
        });

        $('#workTeamShelf').click(function(){
            if (!$(this).hasClass('active')) {
                $('#galleryPanel').animate({'left':760},300);
                $('#teamPanel').animate({'left':0},300);
                $('#detailsPanel').animate({'left':760},300);
            }
        });

        $('#workDetailsShelf').click(function(){
            if (!$(this).hasClass('active')) {
                $('#galleryPanel').animate({'left':760},300);
                $('#teamPanel').animate({'left':760},300);
                $('#detailsPanel').animate({'left':0},300);
            }
        });

        $('.workShelfItem').click(function(){
            if (!$(this).hasClass('active')) {
                $('.workShelfItem.active').removeClass('active');
                $(this).addClass('active');
            }
        });

        $('#workGalleryList .sliderItem').click(function(){
            if (!$(this).hasClass('active')) {
                $('#workGalleryList .sliderItem.active').removeClass('active');
                $(this).addClass('active');
                var listPlacement = $("#workGalleryList .sliderItem").index(this);
                $('#galleryPanel .slider').hSlider('slideTo', listPlacement);
            }
        });

        $('#galleryPanel .sliderButton').click(function(){
            var direction = $(this).data('direction') || 1;
            var index = $('#galleryPanel .slider').hSlider('getIndex')-direction;
            $('#workGalleryList .slider').hSlider('slideTo', index);
            $('#workGalleryList .sliderItem.active').removeClass('active');
            $('#workGalleryList .sliderItem:eq('+index+')').addClass('active');
        });



        BWBR.layout.resetBarHeight();

        $('#teamPanel .sliderItem a').click(function(e) {
            e.preventDefault();
        });

        $('#teamPanel .sliderItem').click(function(e){
            e.stopPropagation();

            if ($(this).find('a:first').attr('href')) {
                window.open($(this).find('a:first').attr('href'),'_self');
            }
        });

        /****************/
        /**** people ****/
        /****************/

        $('#peopleLeadership .sliderItem a').click(function(e) {
            e.preventDefault();
        });

        $('#peopleLeadership .sliderItem').click(function(e){
            e.stopPropagation();
            if ($(this).find('a:first').attr('href')) {
                window.open($(this).find('a:first').attr('href'),'_self');
            }
        });

        $('.historyMilestone').click(function(){
            $('.historyMilestone.active').removeClass('active');
            $('#peopleHistoryMilestones p').removeClass('active');
            var activeMilestore = $(this).attr('id');
            $(this).addClass('active');
            $('.'+activeMilestore).addClass('active');
        });

        /*************************/
        /**** Feature Project ****/
        /*************************/



        $('#insightsGalleryShelf').click(function(){
            if (!$(this).hasClass('active')) {
                $('#featuredGalleryPanel').animate({'left':0},300);
                $('#featuredTeamPanel').animate({'left':760},300);
                $('#featuredDetailsPanel').animate({'left':760},300);
            }
        });

        $('#insightsTeamShelf').click(function(){
            if (!$(this).hasClass('active')) {
                $('#featuredGalleryPanel').animate({'left':760},300);
                $('#featuredTeamPanel').animate({'left':0},300);
                $('#featuredDetailsPanel').animate({'left':760},300);
            }
        });

        $('#insightsDetailsShelf').click(function(){
            if (!$(this).hasClass('active')) {
                $('#featuredGalleryPanel').animate({'left':760},300);
                $('#featuredTeamPanel').animate({'left':760},300);
                $('#featuredDetailsPanel').animate({'left':0},300);
            }
        });

        $('.insightsShelfItem').click(function(){
            if (!$(this).hasClass('active')) {
                $('.insightsShelfItem.active').removeClass('active');
                $(this).addClass('active');
            }
        });

        /******************/
        /**** Process ****/
        /*****************/

        var closePannels = function () {
            var OpenedPanel = $('.processTab.active');
                    OpenedPanel.removeClass('active');
                    OpenedPanel.animate({'height':71},300);
        };

        $('.processTab').click(function(){
            if (!$(this).hasClass('active')) {
                if ($('.processTab.active').length) {
                    closePannels();
                    /*
                    var OpenedPanel = $('.processTab.active');
                    OpenedPanel.removeClass('active');
                    OpenedPanel.animate({'height':71},300);*/
                }
                $(this).addClass('active');
                var subSize = $(this).find('.processTabContent').height();
                $(this).animate({'height':subSize},300);
            }
        });


        $('.slideUpDown').click(function(e){
            var parentTab = $(this).parent();
            if (parentTab.hasClass('active')) {
                e.stopPropagation();
                parentTab.removeClass('active');
                parentTab.animate({'height':71},300);
            }
        });


        $('.processTab a').click(function(e){
            e.preventDefault();
            e.stopPropagation();
            $('#darkShadows').show();
            var currentModal = $($(this).attr("href"));
            var currentWidowWidth = $(window).width();
            var newLeft = (currentWidowWidth/2)-currentModal.width()/2;
            currentModal.fadeIn('slow');
            currentModal.addClass('active');
            currentModal.css('left',newLeft);
            closePannels();
        });

        $('.processExampleContent .close').click(function(){
            $('#darkShadows').hide();
            $('.modalBox.active').hide();
        });

        /********************************/
        /**** F.A.Q Display Answeres ****/
        /********************************/

        $('.careerFaqQuestions li').click(function () {

            if (!$(this).hasClass('active')) {
                if ($('.faqAnswer.active').length) {
                    var OpenedPanel = $('.faqAnswer.active');
                    OpenedPanel.removeClass('active');
                    OpenedPanel.hide();
                }
                $('.careerFaqQuestions li.active').removeClass('active');
                $(this).addClass('active');
                $('.faqAnswer.faq0, .faqImage').hide();
                var faqAnswerStore = $(this).attr('id');
                $('.'+faqAnswerStore).show();
                $('.'+faqAnswerStore).addClass('active');

                BWBR.layout.resetBarHeight();
            }
        });

        /********************/
        /**** Idea Cloud ****/
        /********************/

        var BWBR = BWBR || {};
        BWBR.commentForm = {

            isOpen: false
            , $control: {}
            , $form: {}
            , errors: []
            , isError: false
            , elements: []
            , nameReg: /^\s*[a-zA-Z\.,\s]+\s*$/
            , emailReg: /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
            , commentMax: 300
            
            , init: function() {
                this.$control = $("#comment_form_link");
                this.$form = $("#comment_form");
                //this.$form.css({opacity: 0.0, visibility: "visible"});
                this.$form.css({opacity: 1.0, visibility: "visible"}); // Needs styling fixes- hidden form covers up the right nav >:O
                this.bind();
            }
            , bind: function() {
                var self = this;
                this.$control.click(function(){
                   $('html, body').animate({scrollTop: self.$form.offset().top}, 500);
                   
                   if (self.isOpen) {
                       return false;
                   }
                   
                   self.isOpen = true;
                   self.$form.animate({
                       opacity: 1.0
                   });
                   return false;
                });
                this.$form.submit(self.submit);
            }

            , validate: function() {
                var self = BWBR.commentForm;
                if (!self.nameReg.test($("#comment_form input[name=name]").val())) {
                    self.isError = true;
                    $("#comment_form label[for=name]").after('<span class="form_error">Please enter only letters, spaces and periods');
                }
                if (!self.emailReg.test($("#comment_form input[name=email]").val())) {
                    self.isError = true;
                    $("#comment_form label[for=email]").after('<span class="form_error">Please enter a valid email address</span>');
                }
                var clength = $("#comment_form textarea[name=comment]").val().length;
                if (clength > self.commentMax || clength < 3 ) {
                    self.isError = true;
                    $('#comment_form label[for=comment]').after('<span class="form_error">Please limit your comment to 3 to 300 characters</span>');
                }
            }

            , reset: function() {
                $('.form_error').remove();
                this.isError = false;
            }

            , submit: function(e) {
                var self = BWBR.commentForm;
                self.reset();
                self.validate();
                if (self.isError) {
                    e.preventDefault();
                    e.stopPropagation();
                    return false;
                } else {
                    return true;
                }
            }
        }

        BWBR.commentForm.init();

debug = BWBR;
    });
})(jQuery);
var debug = {};
/*****************/
/**** VideoJS ****/
/*****************/

VideoJS.setupAllWhenReady();



