function invisionApi()
{
    this.boardUrl = 'http://boards.baltimoreravens.com';
    this.memberData = null;
    this.articleData = null;
    this.articleComments = null;
    this.systemSettings = null;
    this.guid = null;
    this.commentsStart = 0;
    this.reputation = {};
}
    invisionApi.prototype.getMemberData = function( returnCallBack ) {
        var thisObj = this;
        jQuery.getJSON(this.boardUrl + "/index.php?app=core&module=ravensLogin&jsoncallback=?", function(json) {
            if ( json.status != 'ok' ) {
                return false;
            }

            if ( json.memberData && typeof json.memberData === 'object' && json.memberData.id > 0 ) {
                thisObj.memberData = json.memberData;
            } else {
                thisObj.memberData = 0;
            }
            returnCallBack(thisObj);
         } );
    }

    invisionApi.prototype.fetchCommentSystemDataByGuid = function (guid, returnCallBack) {
        var thisObj = this;
        jQuery.getJSON(this.boardUrl + "/index.php?app=forums&module=ravensComments&guid=" + escape(escape(guid)) + "&limit=10&jsoncallback=?", function (json) {
            if (json.status != 'ok' || typeof json.articleData !== 'object') {
                return false;
            }

            thisObj.articleData = json.articleData;

            if (typeof json.articleComments === 'object' && json.articleComments.length > 0) {
                thisObj.articleComments = json.articleComments;
            } else {
                thisObj.articleComments = null; // ADDED BY MATTHEW AND SHANNON TO FIX STUFF
            }

            if (typeof json.systemSettings === 'object' && json.systemSettings.length > 0) {
                thisObj.systemSettings = json.systemSettings;
            } else {
                thisObj.systemSettings = null; // ADDED BY MATTHEW AND SHANNON TO FIX STUFF
            }

            returnCallBack(thisObj);
        });
    }

    invisionApi.prototype.fetchCommentSystemDataByUrl = function( url, returnCallBack ) {
        var thisObj = this;
        jQuery.getJSON(this.boardUrl + "/index.php?app=forums&module=ravensComments&do=fetchCommentsByUrl&url=" + escape(escape(url)) + "&limit=10&jsoncallback=?", function(json) {
            if ( json.status != 'ok' || typeof json.articleData !== 'object' ) {
                return false;
            }

            thisObj.articleData = json.articleData;

            if ( typeof json.articleComments === 'object' && json.articleComments.length > 0 )
            {
                thisObj.articleComments = json.articleComments;
            }

            if ( typeof json.systemSettings === 'object' && json.systemSettings.length > 0 )
            {
                thisObj.systemSettings = json.systemSettings;
            }

            returnCallBack(thisObj);
         } );
    }

    invisionApi.prototype.writeLoginBar = function() {
        var loginBar = document.getElementById("headerSocialBar");
        if ( !loginBar ) {
            document.writeln("\n<div id=\"headerSocialBar\"></div>");
            loginBar = document.getElementById("headerSocialBar");
        }

        if ( this.memberData == null )
        {
            this.getMemberData( function(thisObj){thisObj.writeLoginBar();} );
            return;
        }

        var str='';
        if (  this.memberData != 0 ) {
            document.getElementById("headerSocialBar").className = 'loggedIn';
            str+='\n\t<div id="socialBarDropWrap">';
            str+='\n\t\t<div id="socialBarDropContainer">';
            str+='\n\t\t\t<p class="socialBarDropTitle"><span>THE</span>FLOCK</p>';
            str+='\n\t\t\t<ul class="socialDropList">';

            // Add link list
            jQuery.each(this.memberData.links,function(id,link) {
                str+='\n\t\t\t\t<li><a href="'+link.href+'">'+link.title+'</a></li>';
            } );

            str+='\n\t\t\t</ul>';
            str+='\n\t\t\t<a id="socialDropLogout" href="'+this.memberData.logout.href + '&amp;return=' + location.href+'">'+this.memberData.logout.title+'</a>';
            str+='\n\t\t</div>';
            str+='\n\t\t<div id="socialBarWelcome"><a href="'+this.memberData.profile.href+'">'+this.memberData.name+'</a></div>';
            str+='\n\t</div>';
            str+='\n\t<a id="socialBarLogout" href="'+this.memberData.logout.href + '&amp;return=' + location.href+'">'+this.memberData.logout.title+'</a><img src="'+this.memberData.photo+'" id="socialBarIcon" width="31" height="31" />\n';
        } else {
                //GUEST
                str+='\n\t<div id="socialBarDropWrap">';
                str+='\n\t\t<div id="socialBarDropContainer">';
                str+='\n\t\t\t<p class="socialBarDropTitle">Log In To The Flock</p>';
                str+='\n\t\t\t<p>Enter your member name and password to sign in.</p>';
                str+='\n\t\t\t<p><a href="'+this.boardUrl+'/interface/facebook/index.php?reg=1"><img src="'+this.boardUrl+'/public/style_images/ravens/facebook_login.png" alt="" /></a></p>';
                str+='\n\t\t\t<p><a href="'+this.boardUrl+'/interface/twitter/index.php?reg=1"><img src="'+this.boardUrl+'/public/style_images/ravens/twitter_login.png" alt="" /></a></p>';
                str+='\n\t\t\t<form action="'+this.boardUrl+'/index.php?app=core&amp;module=global&amp;section=login&amp;do=process" method="post">';
                str+='\n\t\t\t\t<fieldset>';
                str+='\n\t\t\t\t\t<input type="hidden" name="return" id="return" value="'+ escape(location.href) +'" />';
                str+='\n\t\t\t\t\t<label for="username">Username or Email*</label>';
                str+='\n\t\t\t\t\t<input type="text" name="username" id="username" />';
                str+='\n\t\t\t\t\t<label for="password">Password*</label>';
                str+='\n\t\t\t\t\t<input type="password" name="password" id="password" /><br />';
                str+='\n\t\t\t\t\tRemember me?&nbsp;<input type="checkbox" checked="checked" name="rememberMe" value="1" id="remember" style="width: 20px;"/><br />';
                str+='\n\t\t\t\t\t<button type="submit">Submit</button>';
                str+='\n\t\t\t\t</fieldset>';
                str+='\n\t\t\t</form>';
                str+='\n\t\t\t<a href="#mainFooter" class="socialDropLink">Looking for your PSL login?</a>';
                str+='\n\t\t\t<a href="'+this.boardUrl+'/index.php?app=core&amp;module=global&amp;section=lostpass" class="socialDropLink">Forget your password?</a>';
                str+='\n\t\t\t<a href="'+this.boardUrl+'/index.php?app=core&amp;module=global&amp;section=register" id="socialDropLogout" class="socialDropLink">Want to sign up?</a>';
                str+='\n\t\t</div>';
                str += '\n\t\t<div id="socialBarWelcome"><img src="http://www.baltimoreravens.com/media/navigation/social_bar_myravens.jpg" /></div>';
                str+='\n\t\t<a id="socialBarLogin" href="'+this.boardUrl+'/index.php?app=core&amp;module=global&amp;section=login">Login</a>';
                str+='\n\t</div>&nbsp;|&nbsp;<a id="socialBarJoin" href="'+this.boardUrl+'/index.php?app=core&amp;module=global&amp;section=register">Join</a><img src="http://boards.baltimoreravens.com/public/style_images/ravens/profile/default_thumb.png" width="31" height="31" id="socialBarIcon" />\n';
        }
        loginBar.innerHTML = str;
    }
    invisionApi.prototype.getNewCommentsByGuid = function (guid) {// ADDED BY MATTHEW AND SHANNON TO FIX STUFF
        this.fetchCommentSystemDataByGuid(guid, function (thisObj) { thisObj.writeCommentsByGuid(guid); }); // ADDED BY MATTHEW AND SHANNON TO FIX STUFF
    }; // ADDED BY MATTHEW AND SHANNON TO FIX STUFF
    invisionApi.prototype.writeCommentsByGuid = function( guid ) {
        var thisObj = this;
        thisObj.guid = guid;

        // Check for commentSystem container, create one if none exist.
        var commentBar = document.getElementById("commentSystem");
        if ( !commentBar ) {
            document.writeln("\n<div id=\"commentSystem\"></div>");
            commentBar = document.getElementById("commentSystem");
        }

        // Check if we have the articleData, if not get it
        if ( this.articleData == null ) {
            this.fetchCommentSystemDataByGuid( guid, function(thisObj){thisObj.writeCommentsByGuid(guid);}  );
            return;
        }

        var str = ''; //'<div id="respond">';

        // Add guidelines, if they were given
        /*if ( this.systemSettings != null && this.systemSettings.guidelines != null ) {
            str+='<p id="commentSystem-Guidelines"><b>Guidelines:&nbsp;</b>'+this.systemSettings.guidelines+'</p>';
            str+='<br />';
        }*/

        if ( this.memberData != null && this.memberData != 0 )
        {
            str+='<p id="commentSystem-Guidelines"><strong>Guidelines:</strong>&nbsp;Fan feedback should be within the <a href="http://boards.baltimoreravens.com/index.php?app=forums&module=extras&section=boardrules" target="top">guidelines</a> for the community. These guidelines will be used to identify those comments that will be removed from display on the site. Please keep your comments relevant to the topic, not abusive or combatant towards other fans, and don\'t share any personal details. Use the + and - buttons to help keep the community at its best. Comments post to the site shortly after submitting.</p>';

            str+='<h3>Leave a Reply</h3>';
            str+='<div id="commentSystem-reply">';
            str+='<form id="commentSystem-replyForm" action="'+this.boardUrl+'" method="post" enctype="multipart/form-data">';
            str+='<fieldset>';
            str+='<input type="hidden" id="app" name="app" value="forums" />';
            str+='<input type="hidden" id="module" name="module" value="post" />';
            str+='<input type="hidden" id="section" name="section" value="post" />';
            str+='<input type="hidden" id="do" name="do" value="remotePost" />';
            str+='<input type="hidden" id="p" name="p" value="0" />';
            str+='<input type="hidden" id="t" name="t" value="'+thisObj.articleData.tid+'" />';
            str+='<input type="hidden" id="f" name="f" value="'+thisObj.articleData.fid+'" />';
            str+='<input type="hidden" id="auth_key" name="auth_key" value="'+this.memberData.formHash+'" />';
            str+='<input type="hidden" id="enabletrack" name="enabletrack" value="0" />';
            str+='<input type="hidden" id="preview" name="preview" value="0" />';
            str+='</fieldset>';
            str+='<fieldset class="submit">';
            str+='<textarea name="Post" id="Post" rows="5" cols="60"></textarea>';
            str+='<button type="submit" id="submitBtn">Submit</button>';
            str+='</fieldset>';
            str+='</form>';
            str+='</div>';
        }

        if ( this.memberData == null )
        {
            this.getMemberData( function(thisObj){thisObj.writeCommentsByGuid( guid );} );
            return;
        } else if ( this.memberData == 0 ) {
            str+='<p id="commentSystem-userBar">You must be <a href="'+this.boardUrl+'/index.php?app=core&amp;module=global&amp;section=login&amp;referer='+location.href+'"><b>logged in</b></a> to post a comment.</p>';
        } else {
            str+='<p id="commentSystem-userBar">You are logged in as <a href="'+this.memberData.profile.href+'"><b>'+this.memberData.name+'</b></a>.</p>';
        }

        //str+='</div>';
        str+='<br />';
        str+='<table width="656" height="31" cellspacing="0" cellpadding="0" border="0" bgcolor="#e8e8e8"><tbody><tr>';
        str+='<td width="144"><span class="commentstitle">'+this.articleData.posts+' Comments</span></td>';
        str+='<td>Sort By: <span class="commentFilter newest selected" style="font-weight: bold;">Newest First</span> | <span class="commentFilter oldest" style="text-decoration: underline; font-weight: bold; cursor: pointer;">Oldest First</span> | <span class="commentFilter recommended" style="text-decoration: underline; font-weight: bold; cursor: pointer;">Most Recommended</span></td>';
        str+='</tr></tbody></table>';

        // Top Pagination
        if ( this.articleComments != null && this.articleComments.length > 0 && this.articleData.posts > 10 )
        {
            totalPages = Math.ceil( this.articleData.posts / 10 );
            currentPage = this.commentsStart > 0 ? (this.commentsStart / 10) + 1 : 1;

            str+='<div id="commentSystem-topPagination"><span class="total">Page ' + currentPage + ' of ' + totalPages + '</span><ul>';

            if ( currentPage > 3 ) { str+='<li class="first"><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilter(\'newest\', 10, 0);">First</a></li>'; }
            if ( currentPage > 1 ) { str+='<li class="prev"><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilter(\'newest\', 10, ' + (this.commentsStart - 10) + ');">Previous</a></li>'; }
            if ( currentPage - 2 > 0 ) { str+='<li><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilter(\'newest\', 10, ' + (this.commentsStart - 20) + ');">' + (currentPage - 2) + '</a></li>'; }
            if ( currentPage - 1 > 0 ) { str+='<li><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilter(\'newest\', 10, ' + (this.commentsStart - 10) + ');">' + (currentPage - 1) + '</a></li>'; }
            str+='<li class="active">' + currentPage + '</li>';
            if ( currentPage + 1 <= totalPages ) { str+='<li><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilter(\'newest\', 10, ' + (this.commentsStart + 10) + ');">' + (currentPage + 1) + '</a></li>'; }
            if ( currentPage + 2 <= totalPages ) { str+='<li><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilter(\'newest\', 10, ' + (this.commentsStart + 20) + ');">' + (currentPage + 2) + '</a></li>'; }
            if ( currentPage < totalPages ) { str+='<li class="next"><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilter(\'newest\', 10, ' + (this.commentsStart + 10) + ');">Next</a></li>'; }
            if ( currentPage + 3 <= totalPages ) { str+='<li class="last"><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilter(\'newest\', 10, ' + ((totalPages -1) * 10) + ');">Last</a></li>'; }
            str+='</ul></div>';
        } else {
            str+='<div id="commentSystem-pagination no_pages">Page 1 of 1</div>';
        }

        str+='<div id="commentList">';
        str+='<ul id="commentsList_'+guid+'">';

        if ( this.articleComments != null && this.articleComments.length > 0 )
        {
            jQuery.each(this.articleComments,function(id, data) {
                var repStyle = data.rep_points > 0 ? 'positive' : (data.rep_points < 0 ? 'negative' : 'zero' );

                str+='<li id="li-comment-'+data.pid+'" class="li-comment">';

                // Reputation
                str+='<div id="rep_post_'+data.pid+'" class="li-comment-rep">';
                str+='<span title="Reputation" class="reputation ' + repStyle + ' rep_show">'+data.rep_points+'</span>';
                if ( thisObj.memberData != 0 && data.userCanRate ) {
                    //str+='<ul>';
                    str+='<a title="Vote this post up" class="rep_up" href="'+thisObj.boardUrl+'/index.php?app=core&amp;module=global&amp;section=reputation&amp;do=add_rating&amp;app_rate=forums&amp;type=pid&amp;type_id='+data.pid+'&amp;rating=1&amp;secure_key='+thisObj.memberData.formHash+'&amp;post_return='+data.pid+'"><img src="' + thisObj.boardUrl + '/public/style_images/ravens/add.png" alt="Vote this post up" /></a>';
                    str+='<a title="Vote this post down" class="rep_down" href="'+thisObj.boardUrl+'/index.php?app=core&amp;module=global&amp;section=reputation&amp;do=add_rating&amp;app_rate=forums&amp;type=pid&amp;type_id='+data.pid+'&amp;rating=-1&amp;secure_key='+thisObj.memberData.formHash+'&amp;post_return='+data.pid+'"><img src="' + thisObj.boardUrl + '/public/style_images/ravens/delete.png" alt="Vote this post down" /></a>';
                    //str+='<li><span class="rep_up" style="cursor: pointer;" title="Vote this post up"><img src="' + thisObj.boardUrl + '/public/style_images/ravens/add.png" alt="+" /></span></li>';
                    //str+='<li><span class="rep_down" style="cursor: pointer;" title="Vote this post down"><img src="' + thisObj.boardUrl + '/public/style_images/ravens/delete.png" alt="-" /></span></li>';
                    //str+='</ul>';
                }
                str+='</div>';

                if ( thisObj.memberData != 0 && data.userCanRate ) {
                    jQuery(document).ready(function() {
                        thisObj.registerReputation( 'rep_post_' + data.pid, { app: 'forums', type: 'pid', typeid: data.pid }, parseInt(data.rep_points) );
                    } );
                }

                // User information
                str+='<div class="li-comment-head">';
                str+='<strong><a href="'+thisObj.boardUrl+'/index.php?showuser='+data.memberData.member_id+'">'+data.memberData.members_display_name+'<img width="48" height="48" class="avatar avatar-48 photo" src="'+(data.memberData.pp_thumb_photo ? data.memberData.pp_thumb_photo : 'http://boards.baltimoreravens.com/public/style_images/ravens/profile/default_thumb.png')+'" alt="" /></a></strong>';
                str+='<br />Posted<br/><a href="'+thisObj.boardUrl+'/index.php?showtopic='+data.topic_id+'&amp;view=findpost&amp;p='+data.pid+'">'+data.formattedPostDate+'</a>';
                str+='</div>';

                // Article  comment
                str+='<div id="comment-'+data.pid+'"  class="li-comment-body">'+data.post+'</div>';

                str+='</li>';
            } );
        }
        str+='</ul></div>';

        // Bottom Pagination
        if ( this.articleComments != null && this.articleComments.length > 0 && this.articleData.posts > 10 )
        {
            totalPages = Math.ceil( this.articleData.posts / 10 );
            currentPage = this.commentsStart > 0 ? (this.commentsStart / 10) + 1 : 1;

            str+='<div id="commentSystem-bottomPagination"><span class="total">Page ' + currentPage + ' of ' + totalPages + '</span><ul>';

            if ( currentPage > 3 ) { str+='<li class="first"><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilter(\'newest\', 10, 0);">First</a></li>'; }
            if ( currentPage > 1 ) { str+='<li class="prev"><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilter(\'newest\', 10, ' + (this.commentsStart - 10) + ');">Previous</a></li>'; }
            if ( currentPage - 2 > 0 ) { str+='<li><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilter(\'newest\', 10, ' + (this.commentsStart - 20) + ');">' + (currentPage - 2) + '</a></li>'; }
            if ( currentPage - 1 > 0 ) { str+='<li><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilter(\'newest\', 10, ' + (this.commentsStart - 10) + ');">' + (currentPage - 1) + '</a></li>'; }
            str+='<li class="active">' + currentPage + '</li>';
            if ( currentPage + 1 <= totalPages ) { str+='<li><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilter(\'newest\', 10, ' + (this.commentsStart + 10) + ');">' + (currentPage + 1) + '</a></li>'; }
            if ( currentPage + 2 <= totalPages ) { str+='<li><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilter(\'newest\', 10, ' + (this.commentsStart + 20) + ');">' + (currentPage + 2) + '</a></li>'; }
            if ( currentPage < totalPages ) { str+='<li class="next"><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilter(\'newest\', 10, ' + (this.commentsStart + 10) + ');">Next</a></li>'; }
            if ( currentPage + 3 <= totalPages ) { str+='<li class="last"><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilter(\'newest\', 10, ' + ((totalPages -1) * 10) + ');">Last</a></li>'; }
            str+='</ul></div>';
        }

        commentBar.innerHTML = str;
    }
    
    invisionApi.prototype.writeCommentsByUrl = function( guid ) {
        var thisObj = this;
        thisObj.guid = guid;

        // Check for commentSystem container, create one if none exist.
        var commentBar = document.getElementById("commentSystem");
        if ( !commentBar ) {
            document.writeln("\n<div id=\"commentSystem\"></div>");
            commentBar = document.getElementById("commentSystem");
        }

        // Check if we have the articleData, if not get it
        if ( this.articleData == null ) {
            this.fetchCommentSystemDataByUrl( guid, function(thisObj){thisObj.writeCommentsByUrl(guid);}  );
            return;
        }

        var str = ''; //'<div id="respond">';

        // Add guidelines, if they were given
        /*if ( this.systemSettings != null && this.systemSettings.guidelines != null ) {
            str+='<p id="commentSystem-Guidelines"><b>Guidelines:&nbsp;</b>'+this.systemSettings.guidelines+'</p>';
            str+='<br />';
        }*/

        if ( this.memberData != null && this.memberData != 0 )
        {
            str+='<p id="commentSystem-Guidelines"><strong>Guidelines:</strong>&nbsp;Fan feedback should be within the <a href="http://boards.baltimoreravens.com/index.php?app=forums&module=extras&section=boardrules" target="top">guidelines</a> for the community. These guidelines will be used to identify those comments that will be removed from display on the site. Please keep your comments relevant to the topic, not abusive or combatant towards other fans, and don\'t share any personal details. Use the + and - buttons to help keep the community at its best. Comments post to the site shortly after submitting.</p>';

            str+='<h3>Leave a Reply</h3>';
            str+='<div id="commentSystem-reply">';
            str+='<form id="commentSystem-replyForm" action="'+this.boardUrl+'" method="post" enctype="multipart/form-data">';
            str+='<fieldset>';
            str+='<input type="hidden" id="app" name="app" value="forums" />';
            str+='<input type="hidden" id="module" name="module" value="post" />';
            str+='<input type="hidden" id="section" name="section" value="post" />';
            str+='<input type="hidden" id="do" name="do" value="remotePost" />';
            str+='<input type="hidden" id="p" name="p" value="0" />';
            str+='<input type="hidden" id="t" name="t" value="'+thisObj.articleData.tid+'" />';
            str+='<input type="hidden" id="f" name="f" value="'+thisObj.articleData.fid+'" />';
            str+='<input type="hidden" id="auth_key" name="auth_key" value="'+this.memberData.formHash+'" />';
            str+='<input type="hidden" id="enabletrack" name="enabletrack" value="0" />';
            str+='<input type="hidden" id="preview" name="preview" value="0" />';
            str+='</fieldset>';
            str+='<fieldset class="submit">';
            str+='<textarea name="Post" id="Post" rows="5" cols="60"></textarea>';
            str+='<button type="submit" id="submitBtn">Submit</button>';
            str+='</fieldset>';
            str+='</form>';
            str+='</div>';
        }

        if ( this.memberData == null )
        {
            this.getMemberData( function(thisObj){thisObj.writeCommentsByUrl( guid );} );
            return;
        } else if ( this.memberData == 0 ) {
            str+='<p id="commentSystem-userBar">You must be <a href="'+this.boardUrl+'/index.php?app=core&amp;module=global&amp;section=login&amp;referer='+location.href+'"><b>logged in</b></a> to post a comment.</p>';
        } else {
            str+='<p id="commentSystem-userBar">You are logged in as <a href="'+this.memberData.profile.href+'"><b>'+this.memberData.name+'</b></a>.</p>';
        }

        //str+='</div>';
        str+='<br />';
        str+='<table width="656" height="31" cellspacing="0" cellpadding="0" border="0" bgcolor="#e8e8e8"><tbody><tr>';
        str+='<td width="144"><span class="commentstitle">'+this.articleData.posts+' Comments</span></td>';
        str+='<td>Sort By: <span class="commentFilter newest selected" style="font-weight: bold;">Newest First</span> | <span class="commentFilter oldest" style="text-decoration: underline; font-weight: bold; cursor: pointer;">Oldest First</span> | <span class="commentFilter recommended" style="text-decoration: underline; font-weight: bold; cursor: pointer;">Most Recommended</span></td>';
        str+='</tr></tbody></table>';

        // Top Pagination
        if ( this.articleComments != null && this.articleComments.length > 0 && this.articleData.posts > 10 )
        {
            totalPages = Math.ceil( this.articleData.posts / 10 );
            currentPage = this.commentsStart > 0 ? (this.commentsStart / 10) + 1 : 1;

            str+='<div id="commentSystem-topPagination"><span class="total">Page ' + currentPage + ' of ' + totalPages + '</span><ul>';

            if ( currentPage > 3 ) { str+='<li class="first"><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilterUrl(\'newest\', 10, 0);">First</a></li>'; }
            if ( currentPage > 1 ) { str+='<li class="prev"><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilterUrl(\'newest\', 10, ' + (this.commentsStart - 10) + ');">Previous</a></li>'; }
            if ( currentPage - 2 > 0 ) { str+='<li><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilterUrl(\'newest\', 10, ' + (this.commentsStart - 20) + ');">' + (currentPage - 2) + '</a></li>'; }
            if ( currentPage - 1 > 0 ) { str+='<li><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilterUrl(\'newest\', 10, ' + (this.commentsStart - 10) + ');">' + (currentPage - 1) + '</a></li>'; }
            str+='<li class="active">' + currentPage + '</li>';
            if ( currentPage + 1 <= totalPages ) { str+='<li><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilterUrl(\'newest\', 10, ' + (this.commentsStart + 10) + ');">' + (currentPage + 1) + '</a></li>'; }
            if ( currentPage + 2 <= totalPages ) { str+='<li><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilterUrl(\'newest\', 10, ' + (this.commentsStart + 20) + ');">' + (currentPage + 2) + '</a></li>'; }
            if ( currentPage < totalPages ) { str+='<li class="next"><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilterUrl(\'newest\', 10, ' + (this.commentsStart + 10) + ');">Next</a></li>'; }
            if ( currentPage + 3 <= totalPages ) { str+='<li class="last"><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilterUrl(\'newest\', 10, ' + ((totalPages -1) * 10) + ');">Last</a></li>'; }
            str+='</ul></div>';
        } else {
            str+='<div id="commentSystem-pagination no_pages">Page 1 of 1</div>';
        }

        str+='<div id="commentList">';
        str+='<ul id="commentsList_'+guid+'">';

        if ( this.articleComments != null && this.articleComments.length > 0 )
        {
            jQuery.each(this.articleComments,function(id, data) {
                var repStyle = data.rep_points > 0 ? 'positive' : (data.rep_points < 0 ? 'negative' : 'zero' );

                str+='<li id="li-comment-'+data.pid+'" class="li-comment">';

                // Reputation
                str+='<div id="rep_post_'+data.pid+'" class="li-comment-rep">';
                str+='<span title="Reputation" class="reputation ' + repStyle + ' rep_show">'+data.rep_points+'</span>';
                if ( thisObj.memberData != 0 && data.userCanRate ) {
                    //str+='<ul>';
                    str+='<a title="Vote this post up" class="rep_up" href="'+thisObj.boardUrl+'/index.php?app=core&amp;module=global&amp;section=reputation&amp;do=add_rating&amp;app_rate=forums&amp;type=pid&amp;type_id='+data.pid+'&amp;rating=1&amp;secure_key='+thisObj.memberData.formHash+'&amp;post_return='+data.pid+'"><img src="' + thisObj.boardUrl + '/public/style_images/ravens/add.png" alt="Vote this post up" /></a>';
                    str+='<a title="Vote this post down" class="rep_down" href="'+thisObj.boardUrl+'/index.php?app=core&amp;module=global&amp;section=reputation&amp;do=add_rating&amp;app_rate=forums&amp;type=pid&amp;type_id='+data.pid+'&amp;rating=-1&amp;secure_key='+thisObj.memberData.formHash+'&amp;post_return='+data.pid+'"><img src="' + thisObj.boardUrl + '/public/style_images/ravens/delete.png" alt="Vote this post down" /></a>';
                    //str+='<li><span class="rep_up" style="cursor: pointer;" title="Vote this post up"><img src="' + thisObj.boardUrl + '/public/style_images/ravens/add.png" alt="+" /></span></li>';
                    //str+='<li><span class="rep_down" style="cursor: pointer;" title="Vote this post down"><img src="' + thisObj.boardUrl + '/public/style_images/ravens/delete.png" alt="-" /></span></li>';
                    //str+='</ul>';
                }
                str+='</div>';

                if ( thisObj.memberData != 0 && data.userCanRate ) {
                    jQuery(document).ready(function() {
                        thisObj.registerReputation( 'rep_post_' + data.pid, { app: 'forums', type: 'pid', typeid: data.pid }, parseInt(data.rep_points) );
                    } );
                }

                // User information
                str+='<div class="li-comment-head">';
                str+='<strong><a href="'+thisObj.boardUrl+'/index.php?showuser='+data.memberData.member_id+'">'+data.memberData.members_display_name+'<img width="48" height="48" class="avatar avatar-48 photo" src="'+(data.memberData.pp_thumb_photo ? data.memberData.pp_thumb_photo : 'http://boards.baltimoreravens.com/public/style_images/ravens/profile/default_thumb.png')+'" alt="" /></a></strong>';
                str+='<br />Posted<br/><a href="'+thisObj.boardUrl+'/index.php?showtopic='+data.topic_id+'&amp;view=findpost&amp;p='+data.pid+'">'+data.formattedPostDate+'</a>';
                str+='</div>';

                // Article  comment
                str+='<div id="comment-'+data.pid+'"  class="li-comment-body">'+data.post+'</div>';

                str+='</li>';
            } );
        }
        str+='</ul></div>';

        // Bottom Pagination
        if ( this.articleComments != null && this.articleComments.length > 0 && this.articleData.posts > 10 )
        {
            totalPages = Math.ceil( this.articleData.posts / 10 );
            currentPage = this.commentsStart > 0 ? (this.commentsStart / 10) + 1 : 1;

            str+='<div id="commentSystem-bottomPagination"><span class="total">Page ' + currentPage + ' of ' + totalPages + '</span><ul>';

            if ( currentPage > 3 ) { str+='<li class="first"><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilterUrl(\'newest\', 10, 0);">First</a></li>'; }
            if ( currentPage > 1 ) { str+='<li class="prev"><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilterUrl(\'newest\', 10, ' + (this.commentsStart - 10) + ');">Previous</a></li>'; }
            if ( currentPage - 2 > 0 ) { str+='<li><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilterUrl(\'newest\', 10, ' + (this.commentsStart - 20) + ');">' + (currentPage - 2) + '</a></li>'; }
            if ( currentPage - 1 > 0 ) { str+='<li><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilterUrl(\'newest\', 10, ' + (this.commentsStart - 10) + ');">' + (currentPage - 1) + '</a></li>'; }
            str+='<li class="active">' + currentPage + '</li>';
            if ( currentPage + 1 <= totalPages ) { str+='<li><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilterUrl(\'newest\', 10, ' + (this.commentsStart + 10) + ');">' + (currentPage + 1) + '</a></li>'; }
            if ( currentPage + 2 <= totalPages ) { str+='<li><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilterUrl(\'newest\', 10, ' + (this.commentsStart + 20) + ');">' + (currentPage + 2) + '</a></li>'; }
            if ( currentPage < totalPages ) { str+='<li class="next"><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilterUrl(\'newest\', 10, ' + (this.commentsStart + 10) + ');">Next</a></li>'; }
            if ( currentPage + 3 <= totalPages ) { str+='<li class="last"><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilterUrl(\'newest\', 10, ' + ((totalPages -1) * 10) + ');">Last</a></li>'; }
            str+='</ul></div>';
        }

        commentBar.innerHTML = str;
    }

    invisionApi.prototype.updateCommentsByFilterUrl = function( changeFilter, limit, offset ) {
        var thisObj = this;
        var comments = document.getElementById('commentsList_'+thisObj.guid);

        var sortKey;
        var sortBy;

        if ( changeFilter == 'recommended' ) {
            sortKey = 'rep_points';
            sortBy = 'desc';

        } else if ( changeFilter == 'oldest' ) {
            sortKey = 'post_date';
            sortBy = 'asc';
        } else {
            sortKey = 'post_date';
            sortBy = 'desc';
        }

        setOffset = '';
        if ( parseInt(offset) >= 0 ) {
            setOffSet =  '&offSet=' + parseInt(offset);
            thisObj.commentsStart = parseInt(offset);
        }

        setLimit = '&limit=' + (parseInt(limit) > 0 ?  parseInt(limit) : 10);

        jQuery.getJSON(thisObj.boardUrl + "/index.php?app=forums&module=ravensComments&do=fetchCommentsByUrl&url=" + escape(escape(thisObj.guid)) + "&sortKey="+sortKey+"&sortBy="+sortBy+setLimit+setOffSet+"&jsoncallback=?", function(json) {
            if ( json.status != 'ok' || typeof json.articleData !== 'object' ) {
                return false;
            }

            thisObj.articleData = json.articleData;

            if ( typeof json.articleComments === 'object' && json.articleComments.length > 0 )
            {
                thisObj.articleComments = json.articleComments;
            }

            if ( typeof json.systemSettings === 'object' && json.systemSettings.length > 0 )
            {
                thisObj.systemSettings = json.systemSettings;
            }

            jQuery('.commentstitle').html(thisObj.articleData.posts + ' Comments');

            // Top Pagination
            if ( thisObj.articleComments != null && thisObj.articleComments.length > 0 && thisObj.articleData.posts > 10 )
            {
                totalPages = Math.ceil( thisObj.articleData.posts / 10 );
                currentPage = thisObj.commentsStart > 0 ? (thisObj.commentsStart / 10) + 1 : 1;

                var filterHtml = '<span class="total">Page ' + currentPage + ' of ' + totalPages + '</span><ul>';
                if ( currentPage > 3 ) { filterHtml+='<li class="first"><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilterUrl(\''+changeFilter+'\', 10, 0);">First</a></li>'; }
                if ( currentPage > 1 ) { filterHtml+='<li class="prev"><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilterUrl(\''+changeFilter+'\', 10, ' + (thisObj.commentsStart - 10) + ');">Previous</a></li>'; }
                if ( currentPage - 2 > 0 ) { filterHtml+='<li><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilterUrl(\''+changeFilter+'\', 10, ' + (thisObj.commentsStart - 20) + ');">' + (currentPage - 2) + '</a></li>'; }
                if ( currentPage - 1 > 0 ) { filterHtml+='<li><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilterUrl(\''+changeFilter+'\', 10, ' + (thisObj.commentsStart - 10) + ');">' + (currentPage - 1) + '</a></li>'; }
                filterHtml+='<li class="active">' + currentPage + '</li>';
                if ( currentPage + 1 <= totalPages ) { filterHtml+='<li><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilterUrl(\''+changeFilter+'\', 10, ' + (thisObj.commentsStart + 10) + ');">' + (currentPage + 1) + '</a></li>'; }
                if ( currentPage + 2 <= totalPages ) { filterHtml+='<li><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilterUrl(\''+changeFilter+'\', 10, ' + (thisObj.commentsStart + 20) + ');">' + (currentPage + 2) + '</a></li>'; }
                if ( currentPage < totalPages ) { filterHtml+='<li class="next"><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilterUrl(\''+changeFilter+'\', 10, ' + (thisObj.commentsStart + 10) + ');">Next</a></li>'; }
                if ( currentPage + 3 <= totalPages ) { filterHtml+='<li class="last"><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilterUrl(\''+changeFilter+'\', 10, ' + ((totalPages -1) * 10) + ');">Last</a></li>'; }
                filterHtml+='</ul>';
                jQuery('#commentSystem-topPagination').html(filterHtml);
                jQuery('#commentSystem-bottomPagination').html(filterHtml);
            }

            var str ='';
            if ( thisObj.articleComments != null && thisObj.articleComments.length > 0 )
            {
                jQuery.each(thisObj.articleComments,function(id, data) {
                    var repStyle = data.rep_points > 0 ? 'positive' : (data.rep_points < 0 ? 'negative' : 'zero' );

                    str+='<li id="li-comment-'+data.pid+'" class="li-comment">';

                     // Reputation
                    str+='<div id="rep_post_'+data.pid+'" class="li-comment-rep">';
                    str+='<span title="Reputation" class="reputation ' + repStyle + ' rep_show">'+data.rep_points+'</span>';
                    if ( thisObj.memberData != 0 && data.userCanRate ) {
                        //str+='<ul>';
                        str+='<a title="Vote this post up" class="rep_up" href="'+thisObj.boardUrl+'/index.php?app=core&amp;module=global&amp;section=reputation&amp;do=add_rating&amp;app_rate=forums&amp;type=pid&amp;type_id='+data.pid+'&amp;rating=1&amp;secure_key='+thisObj.memberData.formHash+'&amp;post_return='+data.pid+'"><img src="' + thisObj.boardUrl + '/public/style_images/ravens/add.png" alt="+" /></a>';
                        str+='<a title="Vote this post down" class="rep_down" href="'+thisObj.boardUrl+'/index.php?app=core&amp;module=global&amp;section=reputation&amp;do=add_rating&amp;app_rate=forums&amp;type=pid&amp;type_id='+data.pid+'&amp;rating=-1&amp;secure_key='+thisObj.memberData.formHash+'&amp;post_return='+data.pid+'"><img src="' + thisObj.boardUrl + '/public/style_images/ravens/delete.png" alt="-" /></a>';
                        //str+='<li><span class="rep_up" style="cursor: pointer;" title="Vote this post up"><img src="' + thisObj.boardUrl + '/public/style_images/ravens/add.png" alt="+" /></span></li>';
                        //str+='<li><span class="rep_down" style="cursor: pointer;" title="Vote this post down"><img src="' + thisObj.boardUrl + '/public/style_images/ravens/delete.png" alt="-" /></span></li>';
                        //str+='</ul>';
                    }
                    str+='</div>';

                    // User information
                    str+='<div class="li-comment-head">';
                    str+='<strong>'+data.memberData.members_display_name+'<img width="48" height="48" class="avatar avatar-48 photo" src="'+(data.memberData.pp_thumb_photo ? data.memberData.pp_thumb_photo : 'http://boards.baltimoreravens.com/public/style_images/ravens/profile/default_thumb.png')+'" alt="" /></strong>';
                    str+='<br />Posted<br/><a href="'+thisObj.boardUrl+'/index.php?showtopic='+data.topic_id+'&amp;view=findpost&amp;p='+data.pid+'">'+data.formattedPostDate+'</a>';
                    str+='</div>';

                    // Article  comment
                    str+='<div id="comment-'+data.pid+'"  class="li-comment-body">'+data.post+'</div>';

                    str+='</li>';
                } );
                comments.innerHTML = str;

                jQuery.each(thisObj.articleComments,function(id, data) {
                    if ( thisObj.memberData != 0 && data.userCanRate ) {
                        thisObj.registerReputation( 'rep_post_' + data.pid, { app: 'forums', type: 'pid', typeid: data.pid }, parseInt(data.rep_points) );
                    }
                } );

                jQuery('.commentFilter').each( function() {
                    if ( jQuery(this).hasClass(changeFilter) ) {
                        jQuery(this).attr('style','font-weight: bold;');
                        jQuery(this).addClass('selected');
                    } else {
                        jQuery(this).attr('style', 'text-decoration: underline; font-weight: bold; cursor: pointer;');
                        jQuery(this).removeClass('selected');
                    }
                });
            }
        } );
    }

    invisionApi.prototype.updateCommentsByFilter = function( changeFilter, limit, offset ) {
        var thisObj = this;
        var comments = document.getElementById('commentsList_'+thisObj.guid);

        var sortKey;
        var sortBy;

        if ( changeFilter == 'recommended' ) {
            sortKey = 'rep_points';
            sortBy = 'desc';

        } else if ( changeFilter == 'oldest' ) {
            sortKey = 'post_date';
            sortBy = 'asc';
        } else {
            sortKey = 'post_date';
            sortBy = 'desc';
        }

        setOffset = '';
        if ( parseInt(offset) >= 0 ) {
            setOffSet =  '&offSet=' + parseInt(offset);
            thisObj.commentsStart = parseInt(offset);
        }

        setLimit = '&limit=' + (parseInt(limit) > 0 ?  parseInt(limit) : 10);

        jQuery.getJSON(thisObj.boardUrl + "/index.php?app=forums&module=ravensComments&guid=" + escape(escape(thisObj.guid)) + "&sortKey="+sortKey+"&sortBy="+sortBy+setLimit+setOffSet+"&jsoncallback=?", function(json) {
            if ( json.status != 'ok' || typeof json.articleData !== 'object' ) {
                return false;
            }

            thisObj.articleData = json.articleData;

            if ( typeof json.articleComments === 'object' && json.articleComments.length > 0 )
            {
                thisObj.articleComments = json.articleComments;
            }

            if ( typeof json.systemSettings === 'object' && json.systemSettings.length > 0 )
            {
                thisObj.systemSettings = json.systemSettings;
            }

            jQuery('.commentstitle').html(thisObj.articleData.posts + ' Comments');

            // Top Pagination
            if ( thisObj.articleComments != null && thisObj.articleComments.length > 0 && thisObj.articleData.posts > 10 )
            {
                totalPages = Math.ceil( thisObj.articleData.posts / 10 );
                currentPage = thisObj.commentsStart > 0 ? (thisObj.commentsStart / 10) + 1 : 1;

                var filterHtml = '<span class="total">Page ' + currentPage + ' of ' + totalPages + '</span><ul>';
                if ( currentPage > 3 ) { filterHtml+='<li class="first"><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilter(\''+changeFilter+'\', 10, 0);">First</a></li>'; }
                if ( currentPage > 1 ) { filterHtml+='<li class="prev"><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilter(\''+changeFilter+'\', 10, ' + (thisObj.commentsStart - 10) + ');">Previous</a></li>'; }
                if ( currentPage - 2 > 0 ) { filterHtml+='<li><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilter(\''+changeFilter+'\', 10, ' + (thisObj.commentsStart - 20) + ');">' + (currentPage - 2) + '</a></li>'; }
                if ( currentPage - 1 > 0 ) { filterHtml+='<li><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilter(\''+changeFilter+'\', 10, ' + (thisObj.commentsStart - 10) + ');">' + (currentPage - 1) + '</a></li>'; }
                filterHtml+='<li class="active">' + currentPage + '</li>';
                if ( currentPage + 1 <= totalPages ) { filterHtml+='<li><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilter(\''+changeFilter+'\', 10, ' + (thisObj.commentsStart + 10) + ');">' + (currentPage + 1) + '</a></li>'; }
                if ( currentPage + 2 <= totalPages ) { filterHtml+='<li><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilter(\''+changeFilter+'\', 10, ' + (thisObj.commentsStart + 20) + ');">' + (currentPage + 2) + '</a></li>'; }
                if ( currentPage < totalPages ) { filterHtml+='<li class="next"><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilter(\''+changeFilter+'\', 10, ' + (thisObj.commentsStart + 10) + ');">Next</a></li>'; }
                if ( currentPage + 3 <= totalPages ) { filterHtml+='<li class="last"><a href="#commentSystem" onClick="javascript:invisionApi.updateCommentsByFilter(\''+changeFilter+'\', 10, ' + ((totalPages -1) * 10) + ');">Last</a></li>'; }
                filterHtml+='</ul>';
                jQuery('#commentSystem-topPagination').html(filterHtml);
                jQuery('#commentSystem-bottomPagination').html(filterHtml);
            }

            var str ='';
            if ( thisObj.articleComments != null && thisObj.articleComments.length > 0 )
            {
                jQuery.each(thisObj.articleComments,function(id, data) {
                    var repStyle = data.rep_points > 0 ? 'positive' : (data.rep_points < 0 ? 'negative' : 'zero' );

                    str+='<li id="li-comment-'+data.pid+'" class="li-comment">';

                     // Reputation
                    str+='<div id="rep_post_'+data.pid+'" class="li-comment-rep">';
                    str+='<span title="Reputation" class="reputation ' + repStyle + ' rep_show">'+data.rep_points+'</span>';
                    if ( thisObj.memberData != 0 && data.userCanRate ) {
                        //str+='<ul>';
                        str+='<a title="Vote this post up" class="rep_up" href="'+thisObj.boardUrl+'/index.php?app=core&amp;module=global&amp;section=reputation&amp;do=add_rating&amp;app_rate=forums&amp;type=pid&amp;type_id='+data.pid+'&amp;rating=1&amp;secure_key='+thisObj.memberData.formHash+'&amp;post_return='+data.pid+'"><img src="' + thisObj.boardUrl + '/public/style_images/ravens/add.png" alt="+" /></a>';
                        str+='<a title="Vote this post down" class="rep_down" href="'+thisObj.boardUrl+'/index.php?app=core&amp;module=global&amp;section=reputation&amp;do=add_rating&amp;app_rate=forums&amp;type=pid&amp;type_id='+data.pid+'&amp;rating=-1&amp;secure_key='+thisObj.memberData.formHash+'&amp;post_return='+data.pid+'"><img src="' + thisObj.boardUrl + '/public/style_images/ravens/delete.png" alt="-" /></a>';
                        //str+='<li><span class="rep_up" style="cursor: pointer;" title="Vote this post up"><img src="' + thisObj.boardUrl + '/public/style_images/ravens/add.png" alt="+" /></span></li>';
                        //str+='<li><span class="rep_down" style="cursor: pointer;" title="Vote this post down"><img src="' + thisObj.boardUrl + '/public/style_images/ravens/delete.png" alt="-" /></span></li>';
                        //str+='</ul>';
                    }
                    str+='</div>';

                    // User information
                    str+='<div class="li-comment-head">';
                    str+='<strong>'+data.memberData.members_display_name+'<img width="48" height="48" class="avatar avatar-48 photo" src="'+(data.memberData.pp_thumb_photo ? data.memberData.pp_thumb_photo : 'http://boards.baltimoreravens.com/public/style_images/ravens/profile/default_thumb.png')+'" alt="" /></strong>';
                    str+='<br />Posted<br/><a href="'+thisObj.boardUrl+'/index.php?showtopic='+data.topic_id+'&amp;view=findpost&amp;p='+data.pid+'">'+data.formattedPostDate+'</a>';
                    str+='</div>';

                    // Article  comment
                    str+='<div id="comment-'+data.pid+'"  class="li-comment-body">'+data.post+'</div>';

                    str+='</li>';
                } );
                comments.innerHTML = str;

                jQuery.each(thisObj.articleComments,function(id, data) {
                    if ( thisObj.memberData != 0 && data.userCanRate ) {
                        thisObj.registerReputation( 'rep_post_' + data.pid, { app: 'forums', type: 'pid', typeid: data.pid }, parseInt(data.rep_points) );
                    }
                } );

                jQuery('.commentFilter').each( function() {
                    if ( jQuery(this).hasClass(changeFilter) ) {
                        jQuery(this).attr('style','font-weight: bold;');
                        jQuery(this).addClass('selected');
                    } else {
                        jQuery(this).attr('style', 'text-decoration: underline; font-weight: bold; cursor: pointer;');
                        jQuery(this).removeClass('selected');
                    }
                });
            }
        } );
    }

     invisionApi.prototype.submitPost = function( jqueryFormObj ) {
        var thisObj = this;
        //var post = jqueryFormObj(":textarea");
        //post.val( escape(post.val()) );

        //alert(jqueryFormObj("#Post").val());
        //var formData = jqueryFormObj.serialize()
        var formData = '';
        jQuery(':input', jqueryFormObj).each(function() {
            formData = formData + "&" + this.name + "=" + (this.name == 'Post'?escape(escape(this.value)):escape(this.value));
        } );

        jQuery.getJSON(thisObj.boardUrl + "/index.php?app=forums&module=post&section=post&do=remotePost&jsoncallback=?", formData, function(json, textStatus) {
            thisObj.updateCommentsByFilter('newest',0,0);
        } );
     }

     invisionApi.prototype.registerReputation = function( id, url, rating ) {
         thisObj = this;

        if( !jQuery( '#' + id ) ){ return; }

        // Find rep up

        // Following only good for jQuery 1.3
        //var rep_up = jQuery( '#' + id).closest('.rep_up');
        var selector = '#' + id;
        var rep_up = jQuery(selector).find('.rep_up:first');
        var rep_down = jQuery(selector).find('.rep_down:first');
        var sendUrl = thisObj.boardUrl + '/index.php?app=core&module=ajax&section=reputation&do=add_rating&returnType=json&app_rate=' + url.app + '&type=' + url.type + '&type_id=' + url.typeid + '&secure_key=' + thisObj.memberData.formHash;
//alert(rep_up.html());
        if (rep_up) {
            rep_up.bind( 'click', {obj: thisObj, pid: id}, function(event){
                event.data.obj.repRate(1, event.data.pid);
                return false;
            } );
        }

        if (rep_down) {
            rep_down.bind( 'click', {obj: thisObj, pid: id}, function(event){
                event.data.obj.repRate(-1, event.data.pid);
                return false;
            } );
        }

        thisObj.reputation[ id ] = { obj: jQuery(selector), url: url, sendUrl: sendUrl, currentRating: rating || 0 };
     }

     invisionApi.prototype.repRate = function( type, id ) {

        thisObj = this;
        var value = ( type == 1 ) ? 1 : -1;

        if ( !thisObj.reputation[ id ] ) {
            return;
        } else {
            var rep = thisObj.reputation[ id ];
        }

        // Send ping
        jQuery.getJSON( rep.sendUrl + '&rating=' + value + '&jsoncallback=?', function(json,textStatus) {
            if( json.status == 'ok' ) {

                try {
                    // It worked! Hide the rep buttons
                    rep.obj.find('.rep_up:first').hide();
                    rep.obj.find('.rep_down:first').hide();
                } catch(err) { }

                // Update the figure
                var rep_display = rep.obj.find('.rep_show:first');
                if ( rep_display ) {
                    rep_display.nextAll().removeClass('positive negative zero');

                    var newValue = rep.currentRating + value;

                    if( newValue > 0 ) {
                        rep_display.addClass('positive');
                    } else if( newValue < 0 ) {
                        rep_display.addClass('negative');
                    } else {
                        rep_display.addClass('zero');
                    }

                    rep_display.html( newValue );
                }
            } else {
                alert('Rating failed: ' + json.status );
            }
        } );
        //rep.obj.remove("ul");
        //rep.obj.append.text("You do not have permission to vote.").show().fadeOut(3000);
     }
var invisionApi = new invisionApi();
jQuery(document).ready(function() {
        jQuery('.commentFilter').click(function() {
            if ( jQuery(this).hasClass('selected') )
            {
                return;
            }
            var filterClass = jQuery(this).attr("class").replace(/commentFilter /, '');
            invisionApi.updateCommentsByFilter(filterClass, 0, 0);
        });

        jQuery('#submitBtn').click(function() {
            if ( jQuery("#commentSystem-replyForm #Post").val().length < 4 ) {
                if ( jQuery("#commentSystem-replyError").length == 0 ) {
                    jQuery("#commentSystem-reply").append("<div id='commentSystem-replyError'>Your comment must consist of at least 4 characters. Thank you.</div>");
                }
                jQuery("#commentSystem-replyError").show().fadeOut(3000);
                 return false;
            }
            invisionApi.submitPost(jQuery("#commentSystem-replyForm"));
            jQuery("#commentSystem-replyForm").text("Thank you for your comment!").show().fadeOut(5000);
            return false;
        });

       jQuery('#ipsCommentBox-form').submit(function(){
            return false;
        });
} );
jQuery(document.createElement('link')).attr({media: 'screen', href: 'http://boards.baltimoreravens.com/style_images/ravens/articleComments.css', type: 'text/css', rel: 'stylesheet'}).appendTo(document.getElementsByTagName('head')[0]);
