                var initialArtist = null;
		var exploreStack = new ExploreStack();

		function checkParams()
                {
                        a = document.getElementById('artist');
			if (a)
			{
				if (a.value)
				{
                                	setInitialArtist();
				}
			}
                }

                function setInitialArtist()
		{
			initialArtist = document.getElementById('artist').value;
			showProcessing();
			findInitialArtist();
		}

		function showProcessing()
		{
			document.getElementById('results').innerHTML = "Processing...";
		}

                function findInitialArtist()
                {
                url = "aj_findArtistInfo.cgi";
                time = (new Date()).getTime();
                p = {artist: initialArtist, time: time};
                ajaxResponse = new Ajax.Request(
                        url,
                        {
                                method: 'get',
                                parameters: p,
                                onSuccess: showInitialResponse,
                                onFailure: showInitialFailure
                        });
                }

function paintZebra()
{
if (document.getElementsByTagName)
        {
        tables = document.getElementsByTagName("table");
        for(j=0; j<tables.length; j++)
                {
                if (tables[j].className.indexOf('zebra') > -1) // if the classname includes 'zebra'
                        {
                        for (k=0; k<tables[j].rows.length; k=k+2)
                                {
                                        tables[j].rows[k].className='even';
                                }
                        }
                }
        }
}


		function showInitialResponse(req)
		{
                        var s = '';
                        var o = eval('(' + req.responseText + ')');
                        var artist = o[0];
                        if (artist.length<1)
                        {
                                s = describeErrors(artist);
                        }
                        else
                        {
				exploreStack = new ExploreStack();
				ah = new ArtistHolder(o);
				exploreStack.addTop(ah);
				s = exploreStack.describe();
                        }
                        document.getElementById('results').innerHTML = s;
                        paintZebra();
		}

		function showInitialFailure()
		{
			alert("failure");
		}
                
                function extendTop(orig, perf, track)
                {
                	th = new TrackHolder(orig, perf, track);
                	exploreStack.addTop(th);
                	document.getElementById('results').innerHTML = exploreStack.describe(1, 0);
                	scroll(0,0);
                	findArtistTop(perf);            	
                }
                
                function extendBottom(orig, perf, track)
                {
                	th = new TrackHolder(orig, perf, track);
                	exploreStack.addBottom(th);
                	document.getElementById('results').innerHTML = exploreStack.describe(0, 1);
                	scroll(0,10000);
                	findArtistBottom(orig);            	
                }                
                
                function goBackTop()
                {
                	document.getElementById('results').innerHTML = exploreStack.shrinkTop();
			paintZebra();
                	scroll(0,0);
                }
                
                function goBackBottom()
                {
                	document.getElementById('results').innerHTML = exploreStack.shrinkBottom();
			paintZebra();
                	scroll(0,10000);
                }                
                
                function findArtistTop(artist)
                {
                url = "aj_findArtistInfo.cgi";
                time = (new Date()).getTime();
                p = {artist: artist, time: time};
                ajaxResponse = new Ajax.Request(
                        url,
                        {
                                method: 'get',
                                parameters: p,
                                onSuccess: showResponseTop,
                                onFailure: showFailureTop
                        });
                }

		function showResponseTop(req)
		{
                        var s = '';
                        var o = eval('(' + req.responseText + ')');
                        var artist = o[0];
                        if (artist.length<1)
                        {
                                s = describeErrors(artist);
                        }
                        else
                        {
				ah = new ArtistHolder(o);
				exploreStack.addTop(ah);
				s = exploreStack.describe();
                        }
                        document.getElementById('results').innerHTML = s;
                        paintZebra();
                        scroll(0,0);
		}

		function showFailureTop()
		{
			alert("failure");
		}       
		
                function findArtistBottom(artist)
                {
                url = "aj_findArtistInfo.cgi";
                time = (new Date()).getTime();
                p = {artist: artist, time: time};
                ajaxResponse = new Ajax.Request(
                        url,
                        {
                                method: 'get',
                                parameters: p,
                                onSuccess: showResponseBottom,
                                onFailure: showFailureBottom
                        });
                }

		function showResponseBottom(req)
		{
                        var s = '';
                        var o = eval('(' + req.responseText + ')');
                        var artist = o[0];
                        if (artist.length<1)
                        {
                                s = describeErrors(artist);
                        }
                        else
                        {
				ah = new ArtistHolder(o);
				exploreStack.addBottom(ah);
				s = exploreStack.describe();
                        }
                        document.getElementById('results').innerHTML = s;
                        paintZebra();
                        scroll(0,10000);
		}

		function showFailureBottom()
		{
			alert("failure");
		} 		

		function resetForm()
		{
			s = '<form onSubmit="setInitialArtist(); return false;"><input id=\'artist\' value=""/>&nbsp; <input type="button" class="btn" value="Set Starting Artist" onclick="setInitialArtist();" onmouseover="this.className=\'btn btnhov\'" onmouseout="this.className=\'btn\'"/></form><hr noshade/>';

			document.getElementById('results').innerHTML = s;
		}

                function describeErrors(artist)
                {
                        if (artist.length<1)
                        {
                                s = 'Couldn\'t find this artist. ';
				s += '<input type="button" class="btn" value="Try again" onclick="resetForm();" onmouseover="this.className=\'btn btnhov\'" onmouseout="this.className=\'btn\'"/>';
                                return s;
                        }
                        else
                        {

                                return 'mystery error<br>';
                        }
                }


