var xmlhttp

function loadXMLDoc(url,region)
{
xmlhttp=null
// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest()
  }
// code for IE
else if (window.ActiveXObject)
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  }
if (xmlhttp!=null)
  {
  switch (region) {
	  case 'au'    		: xmlhttp.onreadystatechange=state_Change; break;
	  case 'inter' 		: xmlhttp.onreadystatechange=state_ChangeInter; break;
	  case 'pop'   		: xmlhttp.onreadystatechange=state_ChangePop; break;
	  case 'rock'   	: xmlhttp.onreadystatechange=state_ChangeRock; break;
	  case 'alt'   		: xmlhttp.onreadystatechange=state_ChangeAlt; break;
	  case 'urban'   	: xmlhttp.onreadystatechange=state_ChangeUrban; break;
	  case 'dance'   	: xmlhttp.onreadystatechange=state_ChangeDance; break;
	  case 'classics'   : xmlhttp.onreadystatechange=state_ChangeClassics; break;
  }
  xmlhttp.open("GET",url,true)
  xmlhttp.send(null)
  }
else
  {
  alert("Your browser does not support XMLHTTP.")
  }
}

function state_Change()
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
  {
  // if "OK"
  if (xmlhttp.status==200)
  {
  myXML=xmlhttp.responseXML
	var allChannels = myXML.getElementsByTagName('title');
	var allURLs = myXML.getElementsByTagName('link');
	var channelList = "<ul class='twoCol'>";
	for (i=1;i<allChannels.length;i++) {
		currentChannelName = allChannels[i].childNodes[0].nodeValue;
		currentURL = allURLs[i].childNodes[0].nodeValue;
		channelList = channelList + "<li><a href='"+currentURL+"'>"+currentChannelName+"</a></li>";
		 }
	channelList = channelList + "</ul><div class='cssClear'></div>";	
	if(document.getElementById('channelList')) {
		document.getElementById('channelList').innerHTML = channelList;	 
		loadXMLDoc('/au/flash/musicbox/channels_inter.xml', 'inter');
	}
  }
  else
  {
  alert("Problem retrieving XML data:" + xmlhttp.statusText)
  }
  }
}


function state_ChangeInter()
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
  {
  // if "OK"
  if (xmlhttp.status==200)
  {
  myXML=xmlhttp.responseXML
	var allChannels = myXML.getElementsByTagName('title');
	var allURLs = myXML.getElementsByTagName('link');
	var channelList = "<ul class='twoCol'>";
	for (i=1;i<allChannels.length;i++) {
		currentChannelName = allChannels[i].childNodes[0].nodeValue;
		currentURL = allURLs[i].childNodes[0].nodeValue;
		channelList = channelList + "<li><a href='"+currentURL+"'>"+currentChannelName+"</a></li>";
		 }
	channelList = channelList + "</ul><div class='cssClear'></div>";
	if(document.getElementById('channelListInter')) {
		document.getElementById('channelListInter').innerHTML = channelList;
		loadXMLDoc('/au/mirrored/brightcove/brightcoveLineupPop.xml', 'pop');
	}
  }
  else
  {
  alert("Problem retrieving XML data:" + xmlhttp.statusText)
  }
  }
}

function loadXMLs() {
	loadXMLDoc('/au/flash/musicbox/channels.xml', 'au');
}

function interpretGenreXML(panelNo) {
	var allTitles = myXML.getElementsByTagName('title');
	var allURLs = myXML.getElementsByTagName('link');
	var titleList;
	
	if(allTitles[0]) {
		if (panelNo==2||panelNo==5) {
			titleList = "<ul class='altBg'>";
		} else titleList = "<ul>"
		
		for (i=1;i<6;i++) {
			currentTitle = allTitles[i].childNodes[0].nodeValue;
			currentTitleArray = currentTitle.split('"');
			currentArtist = currentTitleArray[0];
			currentTitle = currentTitleArray[1];
			currentURL = allURLs[i].childNodes[0].nodeValue;
			var ifLast = '';
			if (i==5) { 
				ifLast = " class='lastClip'"; 
			}
			titleList = titleList + "<li><a"+ifLast+" href='"+currentURL+"'><div class='vidArtist'>"+currentArtist+"</div><div class='vidTitle'>"+currentTitle+"</div></a></li>";
			 }
		titleList = titleList + "</ul>";
		return titleList;
	} else return "<ul></ul>";
}


function state_ChangePop() {
	// if xmlhttp shows "loaded"
	if (xmlhttp.readyState==4) {
	  // if "OK"
	  if (xmlhttp.status==200) {
		myXML=xmlhttp.responseXML
		titleList = interpretGenreXML(1);
		titleList = titleList + "<a class='moreClips' href='../home/genre.do?bclid=70421620'>MORE &#187;</a>"
		document.getElementById('genrePopList').innerHTML = titleList;
		loadXMLDoc('/au/mirrored/brightcove/brightcoveLineupRock.xml', 'rock');
	  } else {
		alert("Problem retrieving XML data:" + xmlhttp.statusText)
		}
	  }
}
		
function state_ChangeRock() {
	// if xmlhttp shows "loaded"
	if (xmlhttp.readyState==4) {
	  // if "OK"
	  if (xmlhttp.status==200) {
		myXML=xmlhttp.responseXML
		titleList = interpretGenreXML(2);
		titleList = titleList + "<a class='moreClips' href='../home/genre.do?bclid=70421587'>MORE &#187;</a>"
		document.getElementById('genreRockList').innerHTML = titleList;
		loadXMLDoc('/au/mirrored/brightcove/brightcoveLineupAlternative.xml', 'alt');
	  } else {
		alert("Problem retrieving XML data:" + xmlhttp.statusText)
		}
	  }
}

function state_ChangeAlt() {
	// if xmlhttp shows "loaded"
	if (xmlhttp.readyState==4) {
	  // if "OK"
	  if (xmlhttp.status==200) {
		myXML=xmlhttp.responseXML
		titleList = interpretGenreXML(3);
		titleList = titleList + "<a class='moreClips' href='../home/genre.do?bclid=140847706'>MORE &#187;</a>"
		document.getElementById('genreAltList').innerHTML = titleList;
		loadXMLDoc('/au/mirrored/brightcove/brightcoveLineupUrban.xml', 'urban');
	  } else {
		alert("Problem retrieving XML data:" + xmlhttp.statusText)
		}
	  }
}

function state_ChangeUrban() {
	// if xmlhttp shows "loaded"
	if (xmlhttp.readyState==4) {
	  // if "OK"
	  if (xmlhttp.status==200) {
		myXML=xmlhttp.responseXML
		titleList = interpretGenreXML(4);
		titleList = titleList + "<a class='moreClips' href='../home/genre.do?bclid=70762812'>MORE &#187;</a>"
		document.getElementById('genreUrbanList').innerHTML = titleList;
		loadXMLDoc('/au/mirrored/brightcove/brightcoveLineupDance.xml', 'dance');
	  } else {
		alert("Problem retrieving XML data:" + xmlhttp.statusText)
		}
	  }
}

function state_ChangeDance() {
	// if xmlhttp shows "loaded"
	if (xmlhttp.readyState==4) {
	  // if "OK"
	  if (xmlhttp.status==200) {
		myXML=xmlhttp.responseXML
		titleList = interpretGenreXML(5);
		titleList = titleList + "<a class='moreClips' href='../home/genre.do?bclid=141065629'>MORE &#187;</a>"
		document.getElementById('genreDanceList').innerHTML = titleList;
		loadXMLDoc('/au/mirrored/brightcove/brightcoveLineupClassics.xml', 'classics');
	  } else {
		alert("Problem retrieving XML data:" + xmlhttp.statusText)
		}
	  }
}

function state_ChangeClassics() {
	// if xmlhttp shows "loaded"
	if (xmlhttp.readyState==4) {
	  // if "OK"
	  if (xmlhttp.status==200) {
		myXML=xmlhttp.responseXML
		titleList = interpretGenreXML(6);
		titleList = titleList + "<a class='moreClips' href='../home/genre.do?bclid=824006267'>MORE &#187;</a>"
		document.getElementById('genreClassicsList').innerHTML = titleList;
		//loadXMLDoc('/au/mirrored/brightcove/brightcoveLineupRock.xml', 'rock');
	  } else {
		alert("Problem retrieving XML data:" + xmlhttp.statusText)
		}
	  }
}


