/// sidebar

function writeSidebar() {
	var topLinks = new String();
	var cds = new String();
	var bottomLinks = new String();
	topLinks = getTopLinks();
	cds = getCDs();
	bottomLinks = getBottomLinks();
	var finalHTML = topLinks + cds + bottomLinks;
document.write(finalHTML);
}
writeSidebar();

///////// GENERAL ARRAY RANDOMISER

function getRandomArrayItem(arrayName) {
	var arraySize = arrayName.length;
	var randomNum = Math.floor((Math.random() * arraySize));
	var thisItem = arrayName[randomNum];
return thisItem;
}

///////// TOP LINKS

function getTopLinks() {
	var indexLinks = getIndexLinks();
	var moreAlbums = getMoreAlbums();
	var moreTunes = getMoreTunes();
	var finalHTML = indexLinks + moreAlbums + moreTunes;
return finalHTML;
}

///////// INDEX LINKS

function getIndexLinks() {
	var header = '<div class="sideTitle">Main Menu:</div>';
	var home = '<div class="sideItem" title="The Basics">&#x00A4; <strong><a href="' + semita + 'index.html">Project Homepage</a></strong></div>';
	var music = '<div class="sideItem" title="Albums &#x0026; Tunes">&#x00A4; <strong><a href="' + semita + 'music/index.html">Music Index</a></strong></div>';
	var texts = '<div class="sideItem" title="Books &#x0026; Essays">&#x00A4; <strong><a href="' + semita + 'texts/index.html">Texts Index</a></strong></div>';
	var finalHTML = header + home + music + texts;
return finalHTML;
}

///////// MORE ALBUMS / TUNES CONTEXT

function getContext() {
	var context = "Try Some";
	if (ipse.match("/music/") && !ipse.match("/music/index")) {
		context = "More";
	}
return context;
}

///////// MORE ALBUMS

function getMoreAlbums() {
	var numberOfAlbums = 3;
	var albumsArray = getMoreAlbumsArray();
	var firstItem = getRandomArrayItem(albumsArray);
	var itemsList = new Array();
	itemsList.push(firstItem);
	while (itemsList.length < numberOfAlbums) {
		var nextItem = getRandomArrayItem(albumsArray);
		var itemAdded = false;
		for (x = 0; x < itemsList.length; x++) {
			xItem = itemsList[x];
			if (nextItem == xItem) {
				itemAdded = true;
			}
		}
		if (itemAdded == false) {
			itemsList.push(nextItem);
		}
	}
	var header = '<div class="sideTitle">' + getContext() + ' Albums:</div>';
	var opener = '<div class="sideItem"><a href="' + semita + 'music/';
	var path2alt = '/000.html" title="';
	var alt2name = '">';
	var closer = '</a></div>';
	var htmlString = new String();
	while (itemsList.length > 0) {
		var theItem = itemsList.shift();
		var itemPath = theItem.path;
		var itemAlt = theItem.alt;
		var itemName = theItem.name;
		var itemString = opener + itemPath + path2alt + itemAlt + alt2name + itemName + closer ;
		var htmlString = htmlString + itemString;
	}
	var finalHTML = header + htmlString;
return finalHTML;
}

function getMoreAlbumsArray() {
	var moreAlbumsArray = new Array(
		skeneGFG = new anAlbum("skene-manuscript/gfg", "The Jewel in Lothian's Renaissance Crown (c.1620)", "The Skene Manuscript"),
		playford1700 = new anAlbum("playfords-scotch-tunes", "The 1st Major Scottish Fiddle Collection (1700)", "Playford's Scotch-Tunes"),
		orpheus1725 = new anAlbum("orpheus-caledonius/1725", "The 1st Major Collection of &#x0022;Scotch Songs&#x0022; (1725)", "Orpheus Caledonius"),
		bremnerGuitar = new anAlbum("bremner/guitar-collection", "Scots Baroque Guitar for Beginners (1758)", "Bremner's Guitar Collection"),
		gow1784 = new anAlbum("gow/collection-of-strathspey-reels", "The Legendary Gow 1st Edition (1784)", "Gow's Strathspey Reels"),
		gow1804 = new anAlbum("gow/niel-gows-recovery", "Gows Fiddle the Ballroom (1804)", "Niel Gow's Recovery"),
		scott1827 = new anAlbum("scott/abbotsford-collection-of-border-ballads", "Sophia Scott-Lockhart's Harp Minstrelsy (c.1827)", "Abbotsford Border Ballads")
	);
return moreAlbumsArray;
}

function anAlbum(path, alt, name) {
	this.path = path;
	this.alt = alt;
	this.name = name;
}

///////// MORE TUNES

function getMoreTunes() {
	var numberOfTunes = 10;
	var moreTunesArray = new Array();
	moreTunesArray = moreTunesArray.concat(
		getSkeneTunesArray(),
		getPlayfordScotchTunesArray(),
		getOrpheusCaledoniusTunesArray(),
		getBremnerGuitarTunesArray(),
		getCollection1TunesArray(),
		getGowRecoveryTunesArray(),
		getScottBalladsTunesArray()
	);
	var itemsList = new Array();
	var firstItem = getRandomArrayItem(moreTunesArray);
	itemsList.push(firstItem);
	while (itemsList.length < numberOfTunes) {
		var nextItem = getRandomArrayItem(moreTunesArray);
		var itemAdded = false;
		for (x = 0; x < itemsList.length; x++) {
			xItem = itemsList[x];
			if (nextItem == xItem) {
				itemAdded = true;
			}
		}
		if (itemAdded == false) {
			itemsList.push(nextItem);
		}
	}
	var header = '<div class="sideTitle">' + getContext() + ' Tunes:</div>';
	var linkOpen = '<div class="sideItem"><a href="' + semita + 'music/';
	var tuneString1 = '<strong>';
	var tuneString2 = ':</strong> ';
	var linkClose = '</a></div>';
	var htmlString = new String();
	while (itemsList.length > 0) {
		var theItem = itemsList.shift();
		var itemCollection = theItem.coll;
		var itemNumber = theItem.no;
		var itemAlbum = "Album: " + theItem.album;
		var itemTitle = theItem.tit;
		var tuneNum = ((itemsList.length-(numberOfTunes-1)) * -1) + 1;
		var itemString = linkOpen + itemCollection + itemNumber + '.html"' + 'title="' + itemAlbum + '">' + tuneString1+tuneNum+tuneString2 + itemTitle + linkClose;
		var htmlString = htmlString + itemString;
	}
	var finalHTML = header + htmlString;
return finalHTML;
}

function aTune(coll, no, album, tit) {
	this.coll = coll;
	this.no = no;
	this.album = album;
	this.tit = tit;
}

///
/// START MORE TUNES ARRAYS
///

function getSkeneTunesArray() {
	var coll = "skene-manuscript/gfg/";
	var album = "The Skene Manuscript (c.1620)";
	var skeneTunesArray = new Array(
		n003 = new aTune(coll, "003", album, "To dance about the bailzeis dubb"),
		n007 = new aTune(coll, "007", album, "Johne Andersonne my jo"),
		n013 = new aTune(coll, "013", album, "The flowres of the forrest"),
		n016 = new aTune(coll, "016", album, "Good night and God be with you"),
		n018 = new aTune(coll, "018", album, "Jennet drinks no water"),
		n019 = new aTune(coll, "019", album, "Remember me at eveninge"),
		n024 = new aTune(coll, "024", album, "Adew Dundee"),
		n032 = new aTune(coll, "032", album, "Port Ballangowne"),
		n033 = new aTune(coll, "033", album, "My mistres blush is bonie"),
		n035 = new aTune(coll, "035", album, "Leslies Lilt"),
		n040 = new aTune(coll, "040", album, "Doun in yon banke"),
		n057 = new aTune(coll, "057", album, "Ane Alman Moreiss"),
		n060 = new aTune(coll, "060", album, "Joy to the personne"),
		n080 = new aTune(coll, "080", album, "Canaries")
	);
return skeneTunesArray;
}

function getPlayfordScotchTunesArray() {
	var coll = "playfords-scotch-tunes/";
	var album = "Playford's Scotch-Tunes (1700)";
	var playfordsScotchTunesTunesArray = new Array(
		n003 = new aTune(coll, "003", album, "I love my Love in seacreit"),
		n009 = new aTune(coll, "009", album, "The Lord of Cockpens Scotch-measure"),
		n011 = new aTune(coll, "011", album, "Ginleing Georde"),
		n013 = new aTune(coll, "013", album, "Sir William Hope's Scotch-measure"),
		n014 = new aTune(coll, "014", album, "Stir her up and hold her ganging"),
		n026 = new aTune(coll, "026", album, "For old long Gine my Joe")
	);
return playfordsScotchTunesTunesArray;
}

function getOrpheusCaledoniusTunesArray() {
	var coll = "orpheus-caledonius/1725/";
	var album = "Orpheus Caledonius (1725)";
	var orpheusCaledoniusTunesArray = new Array(
		n001 = new aTune(coll, "001", album, "The Lass of Patie's Mill"),
		n002 = new aTune(coll, "002", album, "Bessie Bell"),
		n003 = new aTune(coll, "003", album, "The Bush aboon Traquair"),
		n007 = new aTune(coll, "007", album, "The Yellow-Hair'd Laddie"),
		n018 = new aTune(coll, "018", album, "Bonny Jean"),
		n023 = new aTune(coll, "023", album, "Ann thou were my ain Thing"),
		n024 = new aTune(coll, "024", album, "Polwart on the Green"),
		n027 = new aTune(coll, "027", album, "Fy Gar rub her o'er wi' Strae"),
		n028 = new aTune(coll, "028", album, "Muirland Willie"),
		n030 = new aTune(coll, "030", album, "Auld Rob Moris"),
		n043 = new aTune(coll, "043", album, "The Gaberlunzie-Man"),
		n048 = new aTune(coll, "048", album, "The Lass of Livingstone")
	);
return orpheusCaledoniusTunesArray;
}

function getBremnerGuitarTunesArray() {
	var coll = "bremner/guitar-collection/";
	var album = "Bremner's Guitar Collection (1758)";
	var bremnerGuitarTunesArray = new Array(
		n003 = new aTune(coll, "003", album, "O'er the Hills &#x0026; far away"),
		n006 = new aTune(coll, "006", album, "Johnie Faa"),
		n008 = new aTune(coll, "008", album, "Hooly &#x0026; Fairly"),
		n009 = new aTune(coll, "009", album, "Up we't Eli Eli"),
		n012 = new aTune(coll, "012", album, "Port Patrick"),
		n013 = new aTune(coll, "013", album, "Black Jock"),
		n015 = new aTune(coll, "015", album, "Tweed Side"),
		n021 = new aTune(coll, "021", album, "A Moorish Tune"),
		n022 = new aTune(coll, "022", album, "Lochaber"),
		n023 = new aTune(coll, "023", album, "Minuet"),
		n028 = new aTune(coll, "028", album, "The Bush aboon Traquair"),
		n033 = new aTune(coll, "033", album, "The Conquering Hero"),
		n035 = new aTune(coll, "035", album, "Prelude for the thumb &#x0026; fore finger")
	);
return bremnerGuitarTunesArray;
}

function getCollection1TunesArray() {
	var coll = "gow/collection-of-strathspey-reels/";
	var album = "Niel Gow's Collection of Strathspey Reels (1784)";
	var gowCollection1TunesArray = new Array(
		n001 = new aTune(coll, "001", album, "Dutches of Athole's Strathspey"),
		n002 = new aTune(coll, "002", album, "Gillie Callum da pheitheir"),
		n005 = new aTune(coll, "005", album, "Niel Gows Lamentation for Abercarney"),
		n008 = new aTune(coll, "008", album, "The Flaggon"),
		n018 = new aTune(coll, "018", album, "The Caledonian Hunt, by Sir Alexr. Don. Strathspey"),
		n024 = new aTune(coll, "024", album, "Delven Side"),
		n040 = new aTune(coll, "040", album, "Tulloch Gorum"),
		n045 = new aTune(coll, "045", album, "Dunkeld House"),
		n052 = new aTune(coll, "052", album, "Andrew and his Cuttie Gun"),
		n058 = new aTune(coll, "058", album, "Kilecrankie"),
		n060 = new aTune(coll, "060", album, "The Dutches of Hamilton's Strathspey"),
		n063 = new aTune(coll, "063", album, "Yell yell"),
		n072 = new aTune(coll, "072", album, "Duke of Argyle's Strathspey"),
		n074 = new aTune(coll, "074", album, "The Duke of Atholes Delight"),
		n075 = new aTune(coll, "075", album, "Stumpie Strathspey"),
		n077 = new aTune(coll, "077", album, "Robie donna gorach")
	);
return gowCollection1TunesArray;
}

function getGowRecoveryTunesArray() {
	var coll = "gow/niel-gows-recovery/";
	var album = "Niel Gow's Recovery (1804)";
	var gowRecoveryTunesArray = new Array(
		n001 = new aTune(coll, "001", album, "Niel Gow's Recovery")
	);
return gowRecoveryTunesArray;
}

function getScottBalladsTunesArray() {
	var coll = "scott/abbotsford-collection-of-border-ballads/";
	var album = "Abbotsford Collection of Border Ballads (c.1827)";
	var scottBalladsTunesArray = new Array(
		n002 = new aTune(coll, "002", album, "Johnie Armstrong"),
		n005 = new aTune(coll, "005", album, "The Battle of Bothwell Brigg"),
		n008 = new aTune(coll, "008", album, "The Wife of Usher's Well"),
		n009 = new aTune(coll, "009", album, "True Thomas"),
		n010 = new aTune(coll, "010", album, "Glenfinlas")
	);
return scottBalladsTunesArray;
}

///
/// END MORE TUNES ARRAYS
///

///////// THE TEMPLE OF THE AMAZONS

function getCDs() {
	var numberOfCDs = 3;
	var skms = "/skene-manuscript/";
	var pst = "/playfords-scotch-tunes/";
	var orp = "/orpheus-caledonius/";
	var bremner = "/bremner/";
	var gow = "/gow/";
	var hogg = "/jacobite-relics/";
	var scott = "/scott/";
	var smm = "/scots-musical-museum/";
	var texts = "/texts/";
	var header = '<div class="sideTitle">CD / MP3 Links:</div>';
	var thisArray = new Array();
	if (ipse.match(skms) != null) {
		thisArray = getRenaissanceArray();
	}
	else if (ipse.match(pst) != null) {
		thisArray = getBaroqueArray();
	}
	else if (ipse.match(orp) != null) {
		thisArray = getBaroqueArray();
	}
	else if (ipse.match(bremner) != null) {
		thisArray = getBaroqueArray();
	}
	else if (ipse.match(smm) != null) {
		thisArray = getBaroqueArray();
	}
	else if (ipse.match(gow) != null) {
		thisArray = getBaroqueArray();
	}
	else if (ipse.match(hogg) != null) {
		thisArray = getBaroqueArray();
	}
	else if (ipse.match(scott) != null) {
		thisArray = getRomanticArray();
	}
	else if (ipse.match(texts) != null) {
		thisArray = getTotalArray();
	}
	else {
		thisArray = getModernArray();
	}
	var listHTML = makeList(numberOfCDs, thisArray);
	var finalHTML = header + '<div class="center">' + listHTML + '</div>';
return finalHTML;
}

function azCD(asin, tits, artist) {
	this.asin = asin;
	this.tits = tits;
	this.artist= artist;
}

///
/// START CD ARRAYS
///

function getRenaissanceArray() {
	var skeneArray = new Array(
		bragodKaingk = new azCD("B002I1XWAE", "Kaingk: Early Welsh Music", "Bragod"),
		lindbergScottishFrench = new azCD("B000025UQV", "Lute Music from Scotland &#x0026; France", "Jakob Lindberg"),
		mcfarlaneScottishLute = new azCD("B000001Q8C", "The Scottish Lute", "Ronn McFarlane"),
		mackillopFlowers = new azCD("B000007S3R", "Flowers of the Forest", "Rob MacKillop"),
		mackillopHealing = new azCD("B0000640BC", "The Healing", "Rob MacKillop"),
		baltimoreHelicon = new azCD("B000001Q8M", "On the Banks of Helicon", "The Baltimore Consort"),
		baltimoreDundee = new azCD("B0000CERHY", "Adew Dundee", "The Baltimore Consort"),
		mackillopMontgomerie = new azCD("B00005UO8D", "The Songs of Alexander Montgomerie", "Rendall &#x0026; MacKillop"),
		mackillopGraysteil = new azCD("B000001O9P", "Graysteil", "MacKillop, et al"),
		cappellaMary = new azCD("B0000030OF", "Sacred Music for Mary Queen of Scots", "Cappella Nova"),
		cappellaKinloche = new azCD("B000006LGG", "Kinloche his Fantassie", "Cappella Nova")
	);
return skeneArray;
}

function getBaroqueArray() {
	var burnsArray = new Array(
		concertoClerkLion = new azCD("B000007SZF", "Clerk of Penicuik: Lion of Scotland", "Concerto Caledonia"),
		concertoTam = new azCD("B0007RUT2K", "Fiddler Tam", "Concerto Caledonia"),
		concertoMungrel = new azCD("B00005NIFP", "Mungrel Stuff", "Concerto Caledonia"),
		ledaOswald = new azCD("B000024D44", "James Oswald: Airs for The Seasons", "The Leda Trio"),
		broadsideOswald = new azCD("B000007N7X", "James Oswald: Airs for The Seasons", "The Broadside Band"),
		mackillopOswald = new azCD("B00005COYD", "James Oswald: Twelve Divertimetis for the Guittar", "Rob MacKillop"),
		puirtBach = new azCD("B000003WHK", "Bach Meets Cape Breton", "Puirt a Baroque"),
		puirtKinloch = new azCD("B000003WHY", "Kinloch's Fantasy", "Puirt a Baroque"),
		finchNaked = new azCD("B0007XSVQK", "She's Sweetest When She's Naked", "Mary-Katherine Finch"),
		laNefKillicrankie = new azCD("B000WXR31O", "The Battle of Killicrankie", "La Nef, et al"),
		semcAuldSangs = new azCD("B000000A63", "Auld Scottish Sangs", "The Scottish Early Music Consort"),
		janetbakerFolkSongArrangements = new azCD("B000063WAR", "Scottish Folk Song Arrangements", "Janet Baker, et al")
	);
return burnsArray;
}

function getRomanticArray() {
	var romanticArray = new Array(
		danielchrissFolkSongArrangements = new azCD("B000000T96", "Beethoven Folk Song Arrangements", "Daniel Chriss, et al"),
		sophiaCorriDussekHarp = new azCD("B002K8BJ0U", "Sophia Corri Works For Harp", "Floraleda Sacchi"),
		maccunnOrchestral = new azCD("B000002ZWL", "MacCunn Orchestral Works", "BBC SSO, et al"),
		scottishRomantics = new azCD("B00003ZA57", "Scottish Romantic Piano", "Murray McLachlan"),
		wallaceSymphonic = new azCD("B000002ZXC", "William Wallace Symphonic Poems", "BBC SSO"),
		mackenzieOrchestral = new azCD("B000002ZVD", "MacKenzie Orchestral Works", "BBC SSO"),
		mkfSongsHebrides = new azCD("B000003003", "Land of Heart's Desire", "Marjory Kennedy-Fraser")
	);
return romanticArray;
}

function getModernArray() {
	var miscellaneousArray = new Array(
		gaughanHandful = new azCD("B00002433W", "Handful of Earth", "Dick Gaughan"),
		gaughanEdinburgh = new azCD("B000001BF5", "Live in Edinburgh", "Dick Gaughan"),
		gaughanOutlaws = new azCD("B00005QJWD", "Outlaws &#x0026; Dreamers", "Dick Gaughan"),
		gaughanCathedral = new azCD("B0000252CP", "Redwood Cathedral", "Dick Gaughan"),
		binkiesFling = new azCD("B0000023ZV", "Wanton Fling", "The Whistlebinkies"),
		binkiesTimber = new azCD("B00000IN01", "Timber Timbre", "The Whistlebinkies"),
		binkiesAlbannach = new azCD("B000F3A9NA", "Albannach", "The Whistlebinkies"),
		readerBurns1 = new azCD("B000095IYT", "The Songs of Robert Burns", "Eddie Reader"),
		readerBurns2 = new azCD("B001KVW59W", "The Songs of Robert Burns - Expanded", "Eddie Reader"),
		purserSM = new azCD("B00007GXPV", "Scotland's Music", "Various Artists"),
		bennettMartynBennett = new azCD("B000024L2F", "Martyn Bennett", "Martyn Bennett"),
		bennettBothyCulture = new azCD("B0000009R2", "Bothy Culture", "Martyn Bennett"),
		bennettGlenLyon = new azCD("B0000632K8", "Glen Lyon", "Martyn Bennett"),
		bennettGrit = new azCD("B0000CAPVW", "Grit", "Martyn Bennett")
	);
return miscellaneousArray;
}

function getTotalArray() {
	var totalArray = new Array();
	totalArray = totalArray.concat(getRenaissanceArray(), getBaroqueArray(), getRomanticArray(), getModernArray());
return totalArray;
}

///
/// END ALBUM ARRAYS
///

function openLink(itemASIN) {
	var amazonID = "cyberscotia-21";
	var azString = "<a href=\"http://www.amazon.co.uk/gp/product/" + itemASIN + "?ie=UTF8\u0026tag=" + amazonID + "\u0026linkCode=as2\u0026camp=1634\u0026creative=6738\u0026creativeASIN=" + itemASIN + "\" target=\"_blank\">";
return azString;
}

function makeList(theNumber, theArray) {
	if (theNumber > theArray.length) {
		alert("There aren't that many items in the section array!");
	}
	var itemsList = new Array();
	var firstItem = getRandomArrayItem(theArray);
	itemsList.push(firstItem);
	while (itemsList.length < theNumber) {
		var nextItem = getRandomArrayItem(theArray);
		var itemAdded = false;
		for (x = 0; x < itemsList.length; x++) {
			xItem = itemsList[x];
			if (nextItem == xItem) {
				itemAdded = true;
			}
		}
		if (itemAdded == false) {
			itemsList.push(nextItem);
		}
	}
	var htmlString = new String();
	while (itemsList.length > 0) {
		var theItem = itemsList.shift();
		var itemASIN = theItem.asin;
		var itemTitle = theItem.tits;
		var itemArtist = theItem.artist;
		var itemAlt = itemTitle + ", by " + itemArtist;
		var linkOpen = openLink(itemASIN);
		var itemString = '<div class="amItem">' + linkOpen + '<img src="' + semita + 'p/goods/' + itemASIN + '.jpg" width="100" height="100" alt="' + itemAlt + '" title="' + itemAlt + '"/></a><div class="amDisc">' + linkOpen + itemTitle + '</a></div><div class="amArtist">' + linkOpen + itemArtist + '</a></div></div>';
		var htmlString = htmlString + itemString;
	}
return htmlString;
}

///////// BOTTOM LINKS

function getBottomLinks() {
	var generalInformation = '<div class="sideTitle">More Information:</div>';
	var about = '<div class="sideItem"><a href="' + semita + 'information/index.html"><strong>About ScotMus.com</strong></a></div>';
	var transcriptionPolicy = '<div class="sideItem"><a href="' + semita + 'information/transcription-policy.html"><strong>Transcription Policy</strong></a></div>';
	var midiPolicy = '<div class="sideItem"><a href="' + semita + 'information/midi-policy.html"><strong>MIDI Policy</strong></a></div>';
	var copyrightPolicies = '<div class="sideItem"><a href="' + semita + 'information/copyright.html"><strong>Copyright Policies</strong></a></div>';
	var technicalIssues = '<div class="sideItem"><a href="' + semita + 'information/technical-issues.html"><strong>Technical Issues</strong></a></div>';
	var antispamPolicy = '<div class="sideItem"><a href="' + semita + 'information/anti-spam-policy.html"><strong>Anti-Spam Policy</strong></a></div>';
	var pressAndMedia = '<div class="sideItem"><a href="' + semita + 'information/press-and-media.html"><strong>Press &#x0026; Media Info</strong></a></div>';
	var sst = '<div class="sideItem"><a href="' + semita + 'information/steve-sweeney-turner.html"><strong>Contact Steve</strong></a></div>';
	var finalHTML = generalInformation + about + transcriptionPolicy + midiPolicy + copyrightPolicies + technicalIssues + antispamPolicy + pressAndMedia + sst;
return finalHTML;
}


