function nufgen_jnice_links(reference) {
    if(typeof(reference) == "undefined") {
        var reference = $('a.button', document);
    }
    // Dynamic buttons
    $(reference).each(function(i) {
        var buttonuri = ( typeof($(this).attr('href')) != "undefined" ) ? $(this).attr('href') : '';
        var buttonclick = ( typeof($(this).attr('onclick')) != "undefined" ) ? $(this).attr('onclick') : '';
        var buttonclass = ( typeof($(this).attr('class')) != "undefined" ) ? $(this).attr('class') : '';
        var buttontitle = ( typeof($(this).attr('title')) != "undefined" ) ? $(this).attr('title') : '';
        var buttontxt = $(this).text();

        buttonclass += " jNiceButton";

        var finalbutton = '<button class="'+ buttonclass +'" title="'+ buttontitle +'" onclick="'+ buttonclick +'"><span><span>'+ buttontxt +'</span></span></button>';
        finalbutton = $(finalbutton).hover(function() {
            $(this).children('span').addClass('hover');
        },function() {
            $(this).children('span').removeClass('hover');
        }).click(function() {
            if(buttonuri == "javascript:history.go(-1)") {
                history.go(-1);
            }
            else {
      var domain = /^(https?|ftp|news|nntp|telnet|irc|ssh|sftp|webcal):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)*(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.exec(window.location);                                                                                                                                        
      var isInternal = new RegExp("^(https?|ftp|news|nntp|telnet|irc|ssh|sftp|webcal):\/\/" + domain[2], "i");
      if (isInternal.test(buttonuri)) {
            pageTracker._trackPageview(buttonuri.replace(isInternal, ''));
      } else {
	        pageTracker._trackPageview('/outgoing/' + buttonuri.replace(/^(https?|ftp|news|nntp|telnet|irc|ssh|sftp|webcal):\/\//i, '').split('/').join('--'));
      }
                window.location.href = buttonuri;
            }
        }).filter('button').attr('rel',buttonuri);

        // Check for Mac browsers
        if( /Mac/.test(navigator.platform) ) {
            $(finalbutton).addClass('isMac');
        }

        $(this).after(finalbutton).remove();
    });
}


/* ---------------
 * SWFOBJECT
 * --------------- */

// Universal Flash settings

var installedVersionObj = swfobject.getFlashPlayerVersion();
if( (installedVersionObj.major == 9 && installedVersionObj.release >= 124) || installedVersionObj.major >= 10) {
    var userHasFlashVersion = true;
}
else {
    var userHasFlashVersion = false;
    var noFlashContent = '<div class="noFlashSupport"><h3>Insufficient Flash Support</h3><p>Flash Player 9.0.124 or greater is required to view this content, but you either don\'t have Flash or need to upgrade to a new version. You can download the latest Flash Player from <a href="http://www.macromedia.com/go/getflashplayer" target="_blank">Adobe</a>.</p></div>';
}
var flashVersion = "9.0.124";
var expressInstall = "/_ui/nufgen/swf/expressintall.swf";


$(document).ready(function(){
    $('.pager').prepend('<span class="intro">Pages:</span>');

    nufgen_jnice_links( $('a.button, .mainContent div.comment a') );
    $('form').jNice({enableTextFields:false, enableSelectFields:false});

    $('.pager').wrap('<div class="pagerWrap"></div>');
    $('.pagerWrap').append('<div class="clear"></div>');

    // Polls
    $('div.poll button, #advpoll-cancel-form button').each(function() {
        $(this).after('<div class="clear"></div>');
        $(this).css('float','right');
    });

    if(userHasFlashVersion && nufFlashBanner) {
        var params = {
            path : nufFlashBanner,
            width: "100%",
            height: "100%",
            element : "topHolderFlashPlaceholder",

            flashvars : {
                cloudFLV: "/_ui/srawby/flv/clouds.mov",
                xmlFile: "/_ui/srawby/xml/heros.xml",
                swfPath: "/_ui/srawby/swf/home/",
                fullscreenpage: "true",
                fsreturnpage: "true",
                smoothing: "false",
                deblocking: "3"
            },
            params : {
                allowfullscreen: "true",
                quality: "best",
                wmode: "transparent",
                smoothing: "false"
            }
        };

        $('.top-holder.flashPlaceholder .top:eq(0)').prepend('<div id="'+params.element+'"></div>');
        swfobject.embedSWF(params.path, params.element, params.width, params.height, flashVersion, expressInstall, params.flashvars, params.params)
        $('.top-holder.flashPlaceholder .top:eq(0)').css({'backgroundColor':'transparent', 'backgroundImage':'none'});
        $('.top-holder.flashPlaceholder').css('visibility', 'visible');
    } else {
        $('.top-holder.flashPlaceholder').css('visibility', 'visible');
    }

    var activeDomain = window.location.href.replace(/\.com\/.*/,'').replace(/http:\/\//,'');
    $("#center a[@href^=http]").not("[@href*='"+activeDomain+".com']").addClass('extLink').attr('target','_blank');

});
