var content = new Array( 'face', 'room', 'habit', 'cadillacs', 'adath' ) ;

var remedy = '<div>' +
	'Order online from:<br\/>' +
	'<a href="http://www.remedyrecords.com" target="_blank"><img src="/images/remedylogo.jpg" alt="Remedy Records" width="93" height="92" border="0"\/></a>' +
	'<\/div>' ;

var bluerose = '<div>' +
	'In Europe order from:<br\/>' +
	'<a href="http://www.bluerose-records.de/main.asp?mode=artist&id=3626" target="_blank"><img src="/images/br_logo.gif" alt="Blue Rose" width="145" height="60" border="0"\/></a>' +
	'<\/div>' ;

loadContent = function()
{
	setContent() ;
	var preloaded = new Array() ;

	for( var i = 1; i < content.length; i++ )
	{
		preloaded[ i ] = document.createElement( 'img' ) ;
		preloaded[ i ].setAttribute( 'src', '/images/' + content[ i ].img ) ;
	}

	var subnav = new Array() ;

	for( var i = 0; i < content.length; i++ )
		subnav.push( '<div><span id="r' + i + '" onmouseover="getContent( ' + i + ' ) ;"><img id="img' + i + '" src="/images/spacer.gif" alt="" width="11" height="11" border="0" class="square"\/>' + content[ i ].title + '<\/span><\/div>' ) ;

	subnav.push( '<div id="order"><\/div>' ) ;
	document.getElementById( 'subnav' ).innerHTML = subnav.join( '' ) ;
	document.getElementById( 'order' ).innerHTML = remedy + bluerose ;
	document.getElementById( 'img0' ).src = '/images/square006o.gif' ;
	var html = '<img src="/images/' + content[ 0 ].img + '" alt="" width="240" height="236" border="0"\/>' + content[ 0 ].tracks ;
	document.getElementById( 'content' ).style.minHeight = '304px' ;
	document.getElementById( 'content' ).innerHTML = html ;
}

getContent = function( id )
{
	for( var i = 0; i < content.length; i++ )
		document.getElementById( 'img' + i ).src = '/images/' + ( ( i == id ) ? 'square006o.gif' : 'spacer.gif' ) ;

	if( id < 2 )
	{
		document.getElementById( 'order' ).style.marginTop = 0 ;
		document.getElementById( 'order' ).innerHTML = remedy + bluerose ;
	}
	else if( id == 2 )
	{
		document.getElementById( 'order' ).style.marginTop = '52px' ;
		document.getElementById( 'order' ).innerHTML = bluerose ;
	}
	else
	{
		document.getElementById( 'order' ).style.marginTop = 0 ;
		document.getElementById( 'order' ).innerHTML = remedy ;
	}

	var html = '<img src="/images/' + content[ id ].img + '" alt="" width="240" height="236" border="0"\/>' + content[ id ].tracks ;
	document.getElementById( 'content' ).innerHTML = html ;
}

function loadXMLDoc( url )
{
	// Load xml document if not using Safari browser
	if( !/safari/i.test( navigator.userAgent ) )
	{
		var xmldoc ;

		// Branch for W3C standard version
		if( document.implementation && document.implementation.createDocument )
			xmldoc = document.implementation.createDocument( '', '', null ) ;
		else
			xmldoc = new ActiveXObject( 'MSXML2.DOMDocument' ) ;

		xmldoc.async = false ;
		xmldoc.load( url ) ;
		return xmldoc ;
	}
	// XMLHttpRequest() if Safari
	else
	{
		req = new XMLHttpRequest() ;
		req.onreadystatechange = function()
		{
			// only if req shows "loaded"
			if( ( req.readyState == 4 ) && ( req.status != 200 ) )
				return false ;
		} ;

		req.open( 'GET', url, false ) ;
		req.send( null ) ;
		return req.responseXML ;
	}
}

function setContent()
{
	for( var i = 0; i < content.length; i++ )
	{
		var cd = content[ i ] ;
		var doc = loadXMLDoc( '/mp3/' + cd + '/songlist.xml' ) ;

		// Delete album and continue if xml document empty
		if( doc == undefined || doc.documentElement == null )
		{
			content.splice( i, 1 ) ;
			--i ;
			continue ;
		}

		var songs = doc.getElementsByTagName( 'song' ) ;
		var html = '<div class="tracks"><a href="javascript:void window.open( \'/mp3/mp3player.htm?dir=' + cd + '\', \'player\', \'width=302,height=206,resizable=0\' ) ;" title="Play cd tracks.">Tracks</a>:<br\/><ol>' ;

		for( var j = 0; j < songs.length; j++ )
			html += '<li>' + songs[ j ].getAttribute( 'title' ).replace( "'", '&rsquo;' ) + '<\/li>' ;

		content[ i ] = {
			title : doc.documentElement.getAttribute( 'cdtitle' ),
			img : cd + '.jpg',
			tracks : html + '<\/ol><\/div>'
		} ;
	}
}

window.onload = function() { loadContent() ; }

