// get variable from url
function varPull( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
where = varPull("where");
// this array defines all the sites by name and url
// the first n_mainlinks are used in the mainbar,
// and the rest are put in the scroller thing
// feel free to modfiy these..
sites = [
  { "name": "3 News", "url": "http://www.3news.co.nz/?ref=un"},
  { "name": "TV 3", "url":  "http://www.tv3.co.nz/?ref=un"},
  { "name": "C4", "url": "http://www.c4tv.co.nz/?ref=un"},
  { "name": "MaiFM", "url": "http://www.maifm.co.nz/?ref=un"},
  { "name": "MoreFM", "url": "http://www.morefm.co.nz/?ref=un"},
  { "name": "The Edge", "url": "http://www.theedge.co.nz/?ref=un"},
  { "name": "The Rock", "url": "http://www.therock.net.nz/?ref=un"},
  { "name": "RadioLIVE", "url": "http://www.radiolive.co.nz/?ref=un"},
  { "name": "NZSport", "url": "http://www.nzsport.co.nz/?ref=un"},
  { "name": "BSport", "url": "http://www.bsport.co.nz/?ref=un"},
  { "name": "Vouchermate", "url": "http://www.vouchermate.co.nz"},
  { "name": "The Breeze", "url": "http://www.thebreeze.co.nz/?ref=un"},
  { "name": "3Sport", "url": "http://3sport.co.nz/?ref=un"},
  { "name": "My Mobizone", "url": "http://www.mymobizone.co.nz/?ref=un"},
  { "name": "Solid Gold", "url": "http://www.solidgoldfm.co.nz/?ref=un"},
  { "name": "Adsearch", "url": "http://www.adsearch.co.nz/?ref=un"},
  { "name": "Kiwi FM", "url": "http://www.kiwifm.co.nz/?ref=un"},
  { "name": "MediaWorks", "url": "http://www.mediaworks.co.nz/?ref=un"}
];

// number of links to show in mainbar, and position to start the scroller
var scroller_i = n_mainlinks = 9;

// create DOM nodes for the A's and insert them
headlist = document.getElementById('mw_headlist');
headlist.innerHTML = '';

for(i = 0; i < n_mainlinks; i++){
  a_elt = document.createElement('A');
  a_elt.setAttribute('href', sites[i].url);
    a_elt.setAttribute('target', '_blank');
  name_elt = document.createTextNode(sites[i].name);
  a_elt.appendChild(name_elt);
  li_elt = document.createElement('LI');
  li_elt.appendChild(a_elt);
  headlist.appendChild(li_elt);

  // autodetect the parent url so we dont need to pass name in the query
  //if (parent.location.href.match(sites[i].url))
if (where.match(sites[i].url))
	
	a_elt.className = "activse";
}

function setScrollerSite(i){
  scroller = document.getElementById('mw_headscroll_link');
  scroller.setAttribute('href', sites[i].url);
  scroller.childNodes[0].nodeValue = sites[i].name;
}
function incrementScroller(){
  if (++scroller_i >= sites.length) scroller_i = 0;
  setScrollerSite(scroller_i);
}
function decrementScroller(){
  if (--scroller_i < 0) scroller_i = sites.length - 1;
  setScrollerSite(scroller_i);
}
// populate the scroller thing
setScrollerSite(scroller_i);

// javascript-enabled browsers: make it appear
document.getElementById('mw_headstrip').style.display = 'block';