var cols = {
  red: [
    { el: '#nav',            bgcolor: '#c90c12', color: '#ffffff' },
    { el: '#nav li a',       bgcolor: '#791418', color: '#ffffff', hoverbgcolor: '#cd4a4a', hovercolor: '#ffffff' },
    { el: '.primaryBgCol',   bgcolor: '#c90c12', color: '#ffffff' },
    { el: '.secondaryBgCol', bgcolor: '#af9a9a', color: '#ffffff' },
    { el: '.footerBgCol',    bgcolor: '#791418' },
    { el: '.footerTextCol',  color:   '#ffffff' },
    { el: '.borderCol',      border:  '#c90c12' },
		{ el: '#logo',           src:     'images/logo_red.gif'},
    { el: '.colourbox',      border:  '#fff' },
    { el: '#cbred',          border:  '#000' }
  ],
  orange: [
    { el: '#nav',            bgcolor: '#ff8c10', color: '#ffffff' },
    { el: '#nav li a',       bgcolor: '#d63b18', color: '#ffffff', hoverbgcolor: '#fc6827', hovercolor: '#ffffff' },
    { el: '.primaryBgCol',   bgcolor: '#ff8c10', color: '#ffffff' },
    { el: '.secondaryBgCol', bgcolor: '#f8a955', color: '#ffffff' },
    { el: '.footerBgCol',    bgcolor: '#f2441c' },
    { el: '.footerTextCol',  color:   '#ffffff' },
    { el: '.borderCol',      border:  '#ff8c10' },
		{ el: '#logo',           src:     'images/logo_orange.gif'},
    { el: '.colourbox',      border:  '#fff' },
    { el: '#cborange',       border:  '#000' }
  ],
  yellow: [
    { el: '#nav',            bgcolor: '#fff200', color: '#555555' },
    { el: '#nav li a',       bgcolor: '#ffbc06', color: '#555555', hoverbgcolor: '#898988', hovercolor: '#ffffff' },
    { el: '.primaryBgCol',   bgcolor: '#fff200', color: '#555555' },
    { el: '.secondaryBgCol', bgcolor: '#ffd906', color: '#555555' },
    { el: '.footerBgCol',    bgcolor: '#898988' },
    { el: '.footerTextCol',  color:   '#ffffff' },
    { el: '.borderCol',      border:  '#fff200' },
		{ el: '#logo',           src:     'images/logo_yellow.gif'},
    { el: '.colourbox',      border:  '#fff' },
    { el: '#cbyellow',       border:  '#000' }
  ],
  green: [
    { el: '#nav',            bgcolor: '#34a63c', color: '#555555' },
    { el: '#nav li a',       bgcolor: '#1c6b21', color: '#ffffff', hoverbgcolor: '#59b73C', hovercolor: '#ffffff' },
    { el: '.primaryBgCol',   bgcolor: '#34a63c', color: '#555555' },
    { el: '.secondaryBgCol', bgcolor: '#c9d0c9', color: '#555555' },
    { el: '.footerBgCol',    bgcolor: '#1c6b21' },
    { el: '.footerTextCol',  color:   '#ffffff' },
    { el: '.borderCol',      border:  '#34a63c' },
		{ el: '#logo',           src:     'images/logo_green.gif'},
    { el: '.colourbox',      border:  '#fff' },
    { el: '#cbgreen',        border:  '#000' }
  ],
  lightblue: [
    { el: '#nav',            bgcolor: '#96c9f4', color: '#555555' },
    { el: '#nav li a',       bgcolor: '#557896', color: '#ffffff', hoverbgcolor: '#bbdbf6', hovercolor: '#555555' },
    { el: '.primaryBgCol',   bgcolor: '#96c9f4', color: '#555555' },
    { el: '.secondaryBgCol', bgcolor: '#b8cee1', color: '#555555' },
    { el: '.footerBgCol',    bgcolor: '#557896' },
    { el: '.footerTextCol',  color:   '#ffffff' },
    { el: '.borderCol',      border:  '#96c9f4' },
		{ el: '#logo',           src:     'images/logo_lblue.gif'},
    { el: '.colourbox',      border:  '#fff' },
    { el: '#cblightblue',    border:  '#000' }
  ],
  blue: [
    { el: '#nav',            bgcolor: '#235aad', color: '#ffffff' },
    { el: '#nav li a',       bgcolor: '#173564', color: '#ffffff', hoverbgcolor: '#85a8dC', hovercolor: '#ffffff' },
    { el: '.primaryBgCol',   bgcolor: '#235aad', color: '#ffffff' },
    { el: '.secondaryBgCol', bgcolor: '#a4adbc', color: '#ffffff' },
    { el: '.footerBgCol',    bgcolor: '#173564' },
    { el: '.footerTextCol',  color:   '#ffffff' },
    { el: '.borderCol',      border:  '#235aad' },
		{ el: '#logo',           src:     'images/logo_blue.gif'},
    { el: '.colourbox',      border:  '#fff' },
    { el: '#cbblue',         border:  '#000' }
  ],
  purple: [
    { el: '#nav',            bgcolor: '#5e2459', color: '#fff' },
    { el: '#nav li a',       bgcolor: '#280f26', color: '#fff', hoverbgcolor: '#8a7388', hovercolor: '#fff' },
    { el: '.primaryBgCol',   bgcolor: '#5e2459', color: '#fff' },
    { el: '.secondaryBgCol', bgcolor: '#938492', color: '#fff' },
    { el: '.footerBgCol',    bgcolor: '#777575' },
    { el: '.footerTextCol',  color:   '#fff' },
    { el: '.borderCol',      border:  '#5e2459' },
		{ el: '#logo',           src:     'images/logo_purple.gif'},
    { el: '.colourbox',      border:  '#fff' },
    { el: '#cbpurple',       border:  '#000' }
  ],
  grey: [
    { el: '#nav',            bgcolor: '#686868', color: '#ffffff' },
    { el: '#nav li a',       bgcolor: '#292828', color: '#ffffff', hoverbgcolor: '#a2a2a2', hovercolor: '#ffffff' },
    { el: '.primaryBgCol',   bgcolor: '#686868', color: '#ffffff' },
    { el: '.secondaryBgCol', bgcolor: '#adadad', color: '#ffffff' },
    { el: '.footerBgCol',    bgcolor: '#424141' },
    { el: '.footerTextCol',  color:   '#ffffff' },
    { el: '.borderCol',      border:  '#686868' },
		{ el: '#logo',           src:     'images/logo_grey.gif'},
    { el: '.colourbox',      border:  '#fff' },
    { el: '#cbgrey',         border:  '#000' }
  ],
  black: [
    { el: '#nav',            bgcolor: '#000000', color: '#ffffff' },
    { el: '#nav li a',       bgcolor: '#616161', color: '#ffffff', hoverbgcolor: '#a2a2a2', hovercolor: '#ffffff' },
    { el: '.primaryBgCol',   bgcolor: '#000000', color: '#ffffff' },
    { el: '.secondaryBgCol', bgcolor: '#4b4b4b', color: '#ffffff' },
    { el: '.footerBgCol',    bgcolor: '#535353' },
    { el: '.footerTextCol',  color:   '#ffffff' },
    { el: '.borderCol',      border:  '#000000' },
		{ el: '#logo',           src:     'images/logo_grey.gif'},
    { el: '.colourbox',      border:  '#fff' },
    { el: '#cbblack',        border:  '#000' }
  ]
};

function changeColour(col) {
  $A(cols[col]).each(function(i) {
    $$(i.el).each(function(j) {
      if (i.bgcolor)
        j.setStyle({ backgroundColor: i.bgcolor });
      
      if (i.color)
        j.setStyle({ color: i.color });
      
      if (i.border)
        j.setStyle({ borderColor: i.border });
      
      if (i.src)
        j.writeAttribute('src', i.src);
      
      // hover colours
      if (i.hovercolor || i.hoverbgcolor) {
        j.onmouseover = function() { this.setStyle({ backgroundColor: i.hoverbgcolor, color: i.hovercolor }); };
        j.onmouseout   = function() { this.setStyle({ backgroundColor: i.bgcolor, color: i.color }); };
      }
    });
  });
}

function changeLayout(layout) {
	var href = window.location.href;
	
	//href = "http://domain.tld/whatever/x/blah.html";
	
	// work out where the page name starts
	var pageidx = href.lastIndexOf('/');
	var pagepath = href.substring(pageidx + 1);
	
	// now get the directory
	var basepath = href.substring(0, pageidx);  // get the rest
	var basepath = basepath.substring(0, basepath.lastIndexOf('/')); // cut one more / off
	
	window.location.href = basepath + "/" + layout + "/" + pagepath;
	
	return true;
}
