/*
    artistCasing code by Gareth Senior, Jan 2009.
        gareth53@gmail.com
        http://www.gareth53.co.uk

    Feel free to use and abuse as you see fit.
    Like I care.
    I take no responsibility for anything.
    It wasn't my fault. You ain't seen me, right?
*/
artistCasing = {
    upCase: function(letter) {
        return letter.toUpperCase();
    },
    upCase3: function(letter) {
        return letter.substr(0,2) + letter.substr(2,1).toUpperCase();
    },
    upCase2: function(letter) {
        return letter.substr(0,2).toUpperCase() + letter.substr(2);
    },
    processCase: function(str) {
        s = str.toLowerCase();
        // replace underscores with spaces
        s = s.replace(/_/g, " ");
        // capitalize a-z chars that follow word boundaries
        // although, rather than using boundary here, we define something tighter
        // we don't want to correct encoded entites ('&amp;') for example
        s = s.replace(/^[a-z]|[\s'\-\(\.\"]+[a-z]/gi, this.upCase);
        // now, the special cases and roman numerals
        s = s.replace(/\baka\b|\busa\b|\buk\b|\bmc\b|\bdj\b|\btv\b|\bok\b|\bM{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})\b/gi, this.upCase);
        // do MCs before McS, correcting DJs here too
        s = s.replace(/Djs\b|Mcs\b/g, this.upCase2);
        // special case for McManus-type names
        s = s.replace(/Mc([a-z])/g, this.upCase3);
        return s;
    },
    strip:function(str) {
        // strips non alpha-numeric characters and spaces - for comparison purposes
        return str.replace(/[^a-zA-Z0-9]+/g, '').toLowerCase();
    },
    fixCase: function(str) {
        // first test the exceptions array
        loopStop = this.exceptions.length;
        strCompare = this.strip(str);
        for (i=0 ; i < loopStop; i++) {
            if (strCompare == this.strip(this.exceptions[i])) {
                return this.exceptions[i];
                break;
            }
        }
        // failing a match in ther exceptions
        // process the string and return it
        return this.processCase(str);
    },
    
    exceptions: Array(
        "2Pac",
        "¡Forward, Russia!",
        "The Almighty RSO",
        "a-ha",
        "ABC",
        "AC/DC",
        "AFI",
        "A-James &amp; The GranDDaDDy",
        "AM60",
        "AntiHero",
        "aPAtT",
        "ARE Weapons",
        "ATC",
        "BBM",
        "BBMak",
        "Bell X1",
        "bis",
        "bob hund",
        "Booker T. &amp; The MGs",
        "BoDeans",
        "BT",
        "B*Witched",
        "C+C Music Factory",
        "Carter USM",
        "cLOUDDEAD",
        "CNN",
        "COGASM",
        "CSS",
        "CCS",
        "D:Ream",
        "The dB's",
        "The deBretts",
        "dEUS",
        "D4L",
        "DC Yeager",
        "DJ GQ",
        "DJ MA1",
        "DMX",
        "ELO",
        "EMF",
        "ESG",
        "FC/Kahuna",
        "fIREHOSE",
        "FM",
        "FMB",
        "FR3E",
        "The GC5",
        "GBH",
        "Guns N' Roses", // included for standardisation rather than casing correction
        "GWAR",
        "HAL",
        "HiM",
        "iLiKETRAiNS",
        "INXS",
        "ist",
        "JET",
        "Junkie XL",
        "JJ72",
        "JK",
        "JLS",
        "KC and the Sunshine Band",
        "k.d. lang",
        "KLF",
        "KMFDM",
        "KRS-One",
        "KT Tunstall",
        "Lady GaGa",
        "LCD Soundsystem",
        "LFO",
        "LL Cool J",
        "M/A/R/R/S",
        "MC5",
        "Mclusky",  // this one to correct the standard convention: McLusky
        "MF Doom",
        "MGMT",
        "M.J. Cole",// included for standardisation
        "mu-Ziq",
        "N*E*R*D",// included for standardisation
        "*NSYNC",
        "N2Deep",
        "N2U",
        "NoFX",
        "OBK",
        "ODB",
        "of Montreal",
        "OMD",
        "OutKast",
        "OP8",
        "NLT",
        "NoMeansNo",
        "N.W.A", // included for standardisation, gramatically-speaking, period SHOULD be ommitted
        "Plain White T's",// included for standardisation
        "P.M. Dawn",// included for standardisation
        "PD Syndicate",
        "PJ Harvey",
        "RBL Posse",
        "RBX",
        "REO Speedwagon",
        "R.E.M.",// included for standardisation
        "Run D.M.C.",// included for standardisation
        "S'Express",// included for standardisation
        "Shy FX",
        "SR-71",
        "stellastarr*",
        "The stiX",
        "Supreme NTM",
        "SWV",
        "t.A.T.u.",
        "Terence Trent D’Arby",
        "TJ Cases",
        "TRU",
        "TLC",
        "TNT",
        "TSOL",
        "TQ",
        "tUnE-yArDs",
        "TV on the Radio",
        "UB40",
        "UFO",
        "VHS Or Beta",
        "VNV Nation",
        "VS",
        "WigWam",
        "will.i.am",
        "XTC",
        "X-CNN",
        "The xx",
        "XXL",
        "Youssou N'Dour",
        "ZZ Top"
    )
};
