function loadArtistPane()
{
	document.getElementById('overlay').onclick =  function () { closeSecondary(); };
	
	html = '<table width="100%" cellspacing="0" cellpadding="0" style="padding: 0px 0px 0px 5px; border-bottom: 1px solid #333333"><tr valign="top" align="left"><td><span id="header28">ARTIST NEWS</span><td><tr></table>';
	getElement('secondary_1').style.width = "415px";
	getElement('secondary_2').style.width = "500px";


	for(var article in artistObj[0].news)
	{
		news = artistObj[0].news[article];
		
		html += '<table width="100%" cellspacing="0" cellpadding="5" style="padding: 5px 0px 0px 0px; border-bottom: 1px solid #333333"><tr valign="top" align="left"><td width="155"><a href="' + news.itemLink + '" target="_blank"><img src="'+ news.artistImage +'" style="border: 1px solid #ffffff" width="150" height="83" /></a></td><td width="390"><!-- <span id="artistHeadlineText"><a href="href="' + news.itemLink + '" target="_blank">'+ news.itemDate +' - ' + news.artistName +'</a></span><br/> --><span id="artistHeadlineText"><a href="' + news.itemLink + '" target="_blank">'+ news.itemTitle +'</a></span></td></tr></table>';
	}		
	document.getElementById('secondary_1').innerHTML = html;
	

	html = '<table width="100%" cellspacing="0" cellpadding="0"><tr valign="top" align="left"><td style="padding: 0px 0px 0px 5px; border-bottom: 1px solid #333333"><span id="header28">ARTISTS BY GENRE</span></td></tr>';
	html += '<tr><td height="5" /></tr>';
	html += '<tr valign="top" align="left"><td><div id="genreDiv">';
	

	
	html += '</div></td></tr></table>';
	
	html += '<div id="genreaz"><table width="100%" cellspacing="0" cellpadding="0"><tr valign="top" align="left"><td style="padding: 0px 0px 0px 5px; border-bottom: 1px solid #333333"><span id="header28">ARTISTS A-Z</span> <span id="genreListing"><A href="javascript:void(0);" onclick="loadArtistListing();">Click here for the master list</a></span><td><tr></table></div>';  	
	
	document.getElementById('secondary_2').innerHTML = html;
	
	loadGenres();
	
	document.getElementById('secondary_2').style.display = "block";
	jQuery("#secondaryContainer").fadeIn(500, function(){ document.getElementById('overlay').onclick =  function () { closeSecondary(); }; });

}

function loadGenre(genreNum)
{
	var genre = artistObj[1].genres[genreNum];
	
	html = '<table width="100%" cellspacing="0" cellpadding="0"><tr valign="top" align="left"><td style="padding: 0px 0px 0px 5px;"><span id="header24">'+ genre.genre.toUpperCase() +'</span><div style="position: absolute; top: 50px; left:864px;"><a href="javascript:void(0);" onclick="jQuery(\'#genreDiv\').fadeOut(500, function() { loadGenres(); });"><img src="images/genre_back.jpg" border="0" width="96" height="16" /></a></div></td></tr>';
	html += '<tr valign="top" align="left"><td>';
	html += '<table width="100%" cellspacing="0" cellpadding="0"><tr valign="top" align="left"><td><table width="100%" cellspacing="0" cellpadding="0"><tr valign="top" align="left"><td><table cellspacing="0" cellpadding="2">';
		
	
	for(var art in genre.artists)
	{
		
		html += '<tr valign="top" align="left"><td><span id="genreListing"><a href="Javascript:void(0);" onclick="jQuery(\'#secondaryContainer\').fadeOut(500, function(){loadArtistListing('+ genre.artists[art].id +', '+ genreNum +'); });">' + genre.artists[art].artistName +'</a></span></td></tr>';
		
		if(art > 0 && (art % 9 == 0)) html += '</table></td><td><table width="100%" cellspacing="0" cellpadding="2"><tr valign="top" align="left">';
	}
	
	html += '</table></td></tr></table></td></tr></table></td></tr></table>';
	
	document.getElementById('genreDiv').innerHTML = html;
	
	jQuery('#genreDiv').fadeIn(500);
	
}

function loadGenres()
{
	var html = '<table width="100%" cellspacing="0" cellpadding="0"><tr valign="top" align="left"><td width="30%"><table cellspacing="0" cellpadding="2">';
	
	var it = 0;
	
	dividend = Math.ceil(artistObj[1].genres.length / 3);
	
	for(var gn in artistObj[1].genres)
	{
		var genre = artistObj[1].genres[gn].genre;
		
		html += '<tr valign="top" align="left"><td><span id="genreListing"><a href="Javascript:void(0);" onclick="loadArtistListing(null, '+ gn +');">' + genre +'</a></span></td></tr>';
		
		if(it > 0 && ((it + 1) % dividend == 0)) html += '</table></td><td width="5%"><img src="images/hr.jpg" width="1" height="187" /></td><td width="30%"><table width="100%" cellspacing="0" cellpadding="2"><tr valign="top" align="left">';
		
		it++;
	}
	
	html += '</table></td></tr></table>';
	
	document.getElementById('genreDiv').innerHTML = html;
	
	document.getElementById('genreDiv').style.height = "auto";
	jQuery('#genreDiv').fadeIn(500);
	
}

function reloadGenres()
{
	html = '<table width="100%" cellspacing="0" cellpadding="0"><tr valign="top" align="left"><td style="padding: 0px 0px 0px 5px; border-bottom: 1px solid #333333"><span id="header28">ARTISTS BY GENRE</span></td></tr>';
	html += '<tr><td height="5" /></tr>';
	html += '<tr valign="top" align="left"><td><div id="genreDiv">';
	

	
	html += '</div></td></tr></table>';
	
	html += '<div id="genreaz"><table width="100%" cellspacing="0" cellpadding="0"><tr valign="top" align="left"><td style="padding: 0px 0px 0px 5px; border-bottom: 1px solid #333333"><span id="header28">ARTISTS A-Z</span> <span id="genreListing"><A href="javascript:void(0);" onclick="jQuery(\'#secondary_2\').fadeOut(500, function() { loadAllArtists(); })">Click here for the master list</a></span><td><tr></table></div>';  	
	
	document.getElementById('secondary_2').innerHTML = html;
	
	loadGenres();
	
	jQuery('#secondary_2').fadeIn(500);
}

function loadAllArtists()
{


	html = '<table width="100%" cellspacing="0" cellpadding="0"><tr valign="top" align="left"><td style="padding: 0px 0px 0px 5px; border-bottom: 1px solid #333333"><span id="header28">ARTISTS A-Z</span><div style="position: absolute; top:20px; left:865px;"><a href="javascript:void(0);" onclick="jQuery(\'#genreDiv\').fadeOut(500, function() { reloadGenres(); });"><img src="images/genre_back.jpg" border="0" width="96" height="16" /></a></div></td></tr>';
	html += '<tr><td height="5" /></tr>';
	html += '<tr valign="top" align="left"><td><div id="genreDiv">';
	

	
	html += '</div></td></tr></table>';
		
	document.getElementById('secondary_2').innerHTML = html;
	
	loadArtists();
	
	document.getElementById('secondary_2').style.display = "block";
	jQuery("#secondary_2").fadeIn(500, function(){});

}

function loadArtists()
{
	var html = '<table width="480" cellspacing="0" cellpadding="0"><tr valign="top" align="left"><td><table cellspacing="0" cellpadding="2">';
	
	var it = 0;
	
	for(var a in artistObj[2].artists)
	{
		var artist = artistObj[2].artists[a];
		
		html += '<tr valign="top" align="left"><td><span id="genreListing"><a href="Javascript:void(0);" onclick="loadArtistListing('+ artist.id +', '+ a +');">' + artist.artistName +'</a></span></td></tr>';
		
		if(it > 0 && ((it + 1) % 20 == 0)) html += '</table></td><td><table width="100%" cellspacing="0" cellpadding="2"><tr valign="top" align="left">';
		
		it++;
	}
	
	html += '</table></td></tr></table>';
	
	document.getElementById('genreDiv').innerHTML = html;
	
	document.getElementById('genreDiv').style.height = "340px";
	
	jQuery('#genreDiv').fadeIn(500);
	
}

function loadArtist(artist)
{

	var isThere = false;
	
	document.title = "Columbia Records | Artists";
	
	artist = artist.toLowerCase();
	 var artistNames = "";
	for(var thisArtist in artistObj[2].artists)
	{
		thisArtistName1 = artistObj[2].artists[thisArtist].artistName.toLowerCase();
		thisArtistName = thisArtistName1.replace(/ /g,'');
		
		switch(artist)
		{
			case "beyoncé":
			case "beyonc%E9":
				thisArtistName = "beyonce";
				break;
				
			case "celinédion":
			case "celin%E9dion":
				thisArtistName = "celinedoin";
				break;
				
		}
		
		if(thisArtistName == artist)
		{
			artistId = artistObj[2].artists[thisArtist].id;
			isThere = true;
			break;
		}
	}
	
	if(isThere == false) 
	{
	 	loadArtistPane();
	} else {
		loadArtistListing(artistId);
	}
	

}

var imageCount = 0;

var imageArray = new Array();

var currentArtistId = 0;

var currentArtistIndex = 0;

var currentArtistGenre = -1;

function loadArtistListing(artistId, thisGenreNum)
{

	loadGenresArtistPage();
	
	currentArtistIndex = 0
	
	currentArtistGenre = -1;
	
	var flowDivHTML  = "";

	flowDivHTML += '<div id="coverFlow" class="ContentFlow">';
	flowDivHTML += '<div class="loadIndicator"><div class="indicator"></div></div>';
	flowDivHTML += '<div id="flowDiv" class="flow"></div>';
	flowDivHTML += '<div class="globalCaption"></div>';
	flowDivHTML += '<div class="scrollbar"><div class="slider"><div class="position"></div></div></div>';
	flowDivHTML += '</div><div class="clearfix"></div>';

	document.getElementById('tertiary_1').innerHTML = flowDivHTML;
		
	imageCount = 0;
	
	currentArtistId = artistId;
	
	//currentArtistIndex = artistIndex;
	
	document.getElementById('itemcontainer').innerHTML = "";
	
	document.getElementById('loadingDiv').style.display = "block";
	
	document.getElementById('flowDiv').innerHTML = '';
	
	document.getElementById('overlay').onclick =  function () { closeTertiary(); };
	
	if(thisGenreNum != undefined)
	{
		currentArtistGenre = thisGenreNum;
		imageArray = artistObj[1].genres[thisGenreNum].artists;

	} else {
		imageArray = artistObj[2].artists;
	}

	loadImagesIntoContainer();
	jQuery("#secondaryContainer").fadeOut(0, function(){});
	jQuery("#tertiaryContainer").fadeIn(500, function(){});
}

function displayProgress(loaded, total)
{
	loaded = loaded + 1;
	var percentLoaded = (loaded /total) * 100;
	
	document.getElementById('progressText').innerHTML = '<span id="contentText">Please wait, loading artist image '+ loaded + ' of '+ total +' images</span>';
	document.getElementById('progressBar').style.width = percentLoaded +"%";
}
	
function loadImagesIntoContainer()
{

	displayProgress(imageCount, imageArray.length);
	
	if(imageCount < imageArray.length)
	{
		
		var artist = imageArray[imageCount];
	
		if(currentArtistId == artist.id) currentArtistIndex = imageCount;
			
		
		if(browserName == "msie")
		{
			flowHTML = '<img class="item" artistId="'+ artist.id +'" src="'+ artist.artistImage +'" title="'+ artist.artistName +'" />';

			document.getElementById('flowDiv').innerHTML += flowHTML;
				
			imageCount++;
		
			loadImagesIntoContainer();
			
		} else {

			var img=document.createElement("img");

			img.src= artist.artistImage;

			img.title= artist.artistName;

			img.setAttribute("class", "item");

			img.setAttribute("artistId", artist.id)
			
			img.setAttribute("onload", "loadImagesIntoContainer();");
			//img.onload=function() {loadImagesIntoContainer() };

			imageCount++;
			
			document.getElementById('flowDiv').appendChild(img);	
		}
		
		
		
	} else {
	
		
		document.getElementById('loadingDiv').style.display = "none";
		
		var flowDiv = document.getElementById('flowDiv');
		
		if(currentArtistId == null) currentArtistId = imageArray[0].id;
		
		//alert(flowDiv.innerHTML);
		
		if(ContentFlowGlobal.Flows.length > 1) ContentFlowGlobal.clear();
		
		var myNewFlow = new ContentFlow('coverFlow', { startItem: currentArtistIndex, reflectionHeight: 0, scaleFactor: 0.85, endOpacity: 0.7, circularFlow: false, flowSpeedFactor: 1.75, flowDragFriction: 0.2, visibleItems: 4} ) ;

		ContentFlowGlobal.onloadInit();
		
	     //	myNewFlow.init();
		
		loadArtistInfo(currentArtistId);
		
		
	}
}

function loadArtistInfo(artistId)
{

	var artist = artistObj[3].artistInfo[artistId]
	
	// BIO
	var tertiary_2 = document.getElementById('tertiary_2');
	
	tertiary_2.innerHTML = "";
	
	var columnHead = '<div style="width: 315px; padding: 0px 10px 5px 0px; float: left">';
	var column1HTML = columnHead;
	var column2HTML = columnHead;
	var column3HTML = '<div style="width: 315px; padding: 0px 10px 5px 0px; float: right">';
	
	var bioHTML = "";
	var videoHTML = "";
	var newsHTML = "";
	var eventsHTML = "";
	var suggestedHTML = "";
	var releaseHTML = "";
	
	// bio
	
	bioHTML = '<div style="width:100%; position: relative; height: 405px; margin:0px 0px 50px 0px"><span id="header24">'+ artist.artistName +'</span><img src="images/hr.jpg" width="100%" height="1" style="margin: 10px 0px 10px 0px"/>';
	
	var website = "";
	var myspace = "";
	var twitter = "";
	var facebook = "";
	
	for(var lk in artist.links)
	{
		switch(artist.links[lk].linkName)
		{
			case "Website":
				website = artist.links[lk].linkUrl;
				break;
				
			case "Myspace":
				myspace = artist.links[lk].linkUrl;
				break;
				
			case "Twitter":
				twitter = artist.links[lk].linkUrl;
				break;

			case "Facebook":
				facebook = artist.links[lk].linkUrl;
				break;
		}
	}
	
	
	var sitesHTML = '<div style="width: 100%; float:left; text-align:left">';
	var likeHTML = "";
	
	if(website != "") sitesHTML += '<a href="'+ website +'" target="_blank"><img src="images/website.jpg" border="0" style="margin: 0px 0px 0px 0px" /></a>';
	if(twitter != "") sitesHTML += '<a href="'+ twitter +'" target="_blank"><img src="images/twitter.jpg" border="0" style="margin: 0px 0px 0px 3px" /></a>';
	if(myspace != "") sitesHTML += '<a href="'+ myspace +'" target="_blank"><img src="images/myspace.jpg" border="0" style="margin: 0px 0px 0px 3px" /></a>';
	if(facebook != "")
	{
		sitesHTML += '<a href="'+ facebook +'" target="_blank"><img src="images/facebook.jpg" border="0" style="margin: 0px 3px 0px 3px" /></a><iframe src="http://www.facebook.com/plugins/like.php?href='+ escape(facebook) +'&amp;layout=button_count&amp;show_faces=true&amp;width=90&amp;action=like&amp;colorscheme=dark&amp;height=23" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:90px; height:23px;" allowTransparency="true"></iframe>';
	}	
	
	bioHTML += sitesHTML + '</div><img src="images/hr.jpg" width="100%" height="1" style="margin: 10px 0px 10px 0px"/>';
	
	bioHTML += '<div style="position: relative; width: 100%; height: 290px; overflow-x: hidden; overflow-y:hidden"><div id="bioTrunc" style="position: absolute; width: 305px; left: 0; top: 0; z-index:1"><span id="contentText">'+ artist.artistBio +'</span></div><div id="bioFull" class="initiallyHidden" style="height: 100%; overflow-x: hidden; overflow-y: hidden"><span id="contentText">'+ artist.artistBio +'</span></div><div id="bioThumb" style="position:absolute; height:50px; width:10px; background-color:#eee; border:1px outset #eee; left:305px; top:0; z-index:2;"></div></div><div style="position: absolute; top: 394px; left:0px; height: 11px; width: 100%;"><img src="images/hr.jpg" width="100%" height="1"/></div></div>';
	
	if(artist.videos.length > 0)
	{
		videoHTML = '<div style="width: 100%; float: left; margin:0px 0px 50px 0px"><span id="header24">Videos</span><br/><img src="images/hr.jpg" width="100%" height="1" style="margin: 10px 0px 10px 0px"/><br/><div id="videoDiv"></div>';
		
		var videoListing = "";
		
		videoTruncHTML = '<div id="videosTrunc" style="height: 70px; overflow-x: hidden; overflow-y:hidden">'; 
		videoFullHTML = '<div id="videosFull" class="initiallyHidden" style="height: 100%; overflow-x: hidden; overflow-y: hidden">';
		

		for(var thisVid in artist.videos)
		{
			var video = artist.videos[thisVid];
			videoListing += '<div style="float:left;';
			
			if((parseInt(thisVid) + 1) % 4 != 0)
			{
				videoListing += 'padding: 0px 11px 11px 0px;';
			} else {
				videoListing += 'padding: 0px 0px 11px 0px;';
			}

			
			videoListing += '"><div id="videoThumbDiv">';

			videoListing += '<a href="javascript:void(0);" onclick="loadArtistVideo('+ video.videoId +');"><img src="php/imagePush.php?img='+ video.videoThumb+'&max=70" style="margin: 0px 0px 0px 0px; border-width: 0px; display: inline" title="'+ video.videoTitle +'"/></a></div></div>';
		}
		

		videoTruncHTML += videoListing + '</div>';
		
		videoHTML += videoTruncHTML;
		
		if(artist.videos.length > 4)
		{
			videoFullHTML += videoListing + "</div>";
			videoHTML += videoFullHTML;
			videoHTML += '<br/><img src="images/hr.jpg" width="100%" height="1" /><br/><div id="videosButton" style="float: right"><a href="javascript:void(0);" onclick="toggleDivs(\'videos\');"><img src="images/moreArtist.jpg" border="0" /></a></div>'
		}
		
		videoHTML  += '</div>';
		
	}
	
	// news
	
	if(artist.feedUrl != "") newsHTML = '<div style="position: relative; width: 100%; height: 405px; margin:0px 0px 50px 0px"><span id="header24">News</span><img src="images/hr.jpg" width="100%" height="1" style="margin: 10px 0px 10px 0px"/><div id="newsDiv" style="position: relative; width: 100%; height: 350px; overflow-x: hidden; overflow-y:hidden"><div style="text-align: center"><img src="images/loading.gif" /></div></div><div style="position: absolute; top: 394px; left:0px; height: 11px; width: 100%;"><img src="images/hr.jpg" width="100%" height="1"/></div></div>';
	
	// releases
	
	if(artist.releases.length > 0)
	{
		releaseHTML = '<div style="width:100%; float: left; margin:0px 0px 50px 0px"><span id="header24">Releases</span><img src="images/hr.jpg" width="100%" height="1" style="margin: 10px 0px 10px 0px"/><div id="clearfix"></div>';

		releaseTruncHTML = '<div style="position: relative; width: 100%; height: 290px; overflow-x: hidden; overflow-y:hidden"><div id="releasesTrunc" style="position: absolute; width: 305px; left: 0; top: 0; z-index:1">'; 
		//releaseFullHTML = '<div id="releasesFull" class="initiallyHidden" style="height: 100%; overflow-x: hidden; overflow-y: hidden">';
		
		var releaseListing = "";
		
		var releaseCount = 0;
		
		for(var thisRel in artist.releases)
		{
			var release = artist.releases[thisRel];
			
			releaseListing += '<div><table width="100% cellspacing="0" cellpadding="0"><tr valign="top"><td width="80"><img src="' + release.covers["COVER100"] +'" width="75" height="75" /></td>';
			releaseListing += '<td><span id="releaseTitle">'+ release.releaseTitle +'</span><br/><br/><span id="radioInfoText">';
			
			for(var linkNum in release.links)
			{
				var thisLink = release.links[linkNum];
				
				releaseListing += '<a href="' + thisLink.linkUrl +'" target="_blank">'+ thisLink.linkName +'</a>  ';
			}
			
			releaseListing += '</span></td></tr></table></div>';
			
			if(thisRel < (artist.releases.length - 1)) releaseListing += '<img src="images/hr.jpg" width="100%" height="1" style="margin: 10px 0px 10px 0px"/>';
		}
		
		releaseTruncHTML += releaseListing +'</div>';
		
		/*
		if(artist.releases.length > 3)
		{
			releaseFullHTML += releaseListing + "</div>";
			releaseHTML += releaseFullHTML;
			releaseHTML += '<br/><div id="releasesButton" style="float: right"><a href="javascript:void(0);" onclick="toggleDivs(\'releases\');"><img src="images/moreArtist.jpg" border="0" /></a></div>'
		}
		*/
		releaseTruncHTML += '<div id="relThumb" style="position:absolute; height:50px; width:10px; background-color:#eee; border:1px outset #eee; left:305px; top:0; z-index:2;"></div></div>';
		
		releaseHTML += releaseTruncHTML;
		
		releaseHTML += "</div>";
	}
	
	// events
	
	if(artist.events.length > 0)
	{
	
		eventsHTML = '<div style="width: 100%; float: left; height: 355px; margin:0px 0px 50px 0px"><span id="header24">Upcoming Events</span><img src="images/hr.jpg" width="100%" height="1" style="margin: 10px 0px 10px 0px"/>';
		eventsHTML += '<div style="position: relative; width: 100%; height: 290px; overflow-x: hidden; overflow-y:hidden"><div id="eventTrunc" style="position: absolute; width: 305px; left: 0; top: 0; z-index:1">';
		
		for(evt in artist.events)
		{
			var event = artist.events[evt];
			
			var html = "";
			
			html += '<span id="tourListing"><b>'+ event.eventDate + '</b>  ';
			
			if(event.tickets != "")
			{
				if(event.tickets == "sold out" || event.tickets == "SOLD OUT")
				{
					html += '<img src="images/soldout.jpg" width="60" height="16" border="0" /><br/>';	
				} else {
					html += '<a href="' + event.tickets +'" target="_blank"><img src="images/buy_tickets.jpg" width="60" height="16" border="0" /></a><br/>';
				}
			}
			
			html += '<span id="tourListing">'+event.venue +'<br/></span><span id="tourListingSub">';

			var venueLocation = "";
			if(event.city != "") venueLocation += event.city;

			if(event.state != "")
			{
				if(event.city != "")
				{
					venueLocation += ', '+ event.state;
				} else {
					venueLocation += event.state;
				}
			}

			if(event.country !="")
			{
				venueLocation += ', '+ event.country;
				if(event.city != "" || event.state != "")
				{
					venueLocation += ', '+ event.country;
				} else {
					venueLocation += event.country;
				}		
			}

			html += venueLocation + '<br/>';

			if(event.infoLink != "")
			{
				html += '<a href="' + event.infoLink +'" target="_blank">More Info</a><br/>';	
			}
			html += '</span><img src="images/hr.jpg" width="100%" height="1" style="margin: 10px 0px 10px 0px"/>';
			
			eventsHTML += html;
			
			if(evt > 5) break;
		}
		
		eventsHTML += '</div><div id="eventThumb" style="position:absolute; height:50px; width:10px; background-color:#eee; border:1px outset #eee; left:305px; top:0; z-index:2;"></div></div><div class="clearfix"></div><div style="float: right"><a href="javascript:void(0);" onclick="jQuery(\'#tertiaryContainer\').fadeOut(200, function() { trackPage(\'/events\', \'Events Page\', \'events\'); getContent(\'events\', '+ artistId +'); });"><img src="images/moreArtist.jpg" border="0" /></a></div></div>';
	}

	// related artists
	
	var relatedArtists = new Array;
	
	if(artist.genres.length > 1)
	{
		for(var gn1 in artist.genres)
		{

			for(var gn2 in artistObj[1].genres)
			{
				if(artist.genres[gn1] == artistObj[1].genres[gn2].genre)
				{
					for(var art1 in artistObj[1].genres[gn2].artists)
					{
						if(!checkForId(relatedArtists, artistObj[1].genres[gn2].artists[art1].id) && artistObj[1].genres[gn2].artists[art1].id != artistId) relatedArtists.push(artistObj[1].genres[gn2].artists[art1]);
					}
				}
			}
			if(gn1 == 1) break;
			
		}
	} else {
		
		for(var gn2 in artistObj[1].genres)
		{
			if(artist.genres[0] == artistObj[1].genres[gn2].genre)
			{
				for(var art1 in artistObj[1].genres[gn2].artists)
				{
					if(!checkForId(relatedArtists, artistObj[1].genres[gn2].artists[art1].id) && artistObj[1].genres[gn2].artists[art1].id != artistId) relatedArtists.push(artistObj[1].genres[gn2].artists[art1]);
				}
			}
		}
	}
	
	var tempRand = 0;
	
	var relatedHTML = "";

	if(relatedArtists.length > 0)
	{
		relatedHTML = '<div style="width: 100%; float: left; height: 355px; margin:0px 0px 50px 0px"><span id="header24">Suggested Artists</span><img src="images/hr.jpg" width="100%" height="1" style="margin: 10px 0px 10px 0px"/>';
		
		switch(relatedArtists.length)
		{
			case "1":
			case "2":
			
				for(x = 0; x < relatedArtists.length; x++)
				{
					relatedHTML += '<div style="position: relative; width: 315px; height:173px; overflow: hidden; border: 1px solid #333333; margin: 0px 0px 10px 0px">';
					relatedHTML += '<div style="position: absolute; z-index:0; width: 315px; height:173; top: 0px; left: 0px"><a href="Javascript:void(0);" onclick="jQuery(\'#tertiary_2\').fadeOut(200, function() { loadSuggestedArtist('+ relatedArtists[randomnumber].id +') });"><img src="'+ relatedArtists[x].artistImage +'" width="315" height="173" border="0" /></a></div>';
					relatedHTML += '<div style="position: absolute; z-index:1; width: 315px; height:17;top: 157px; left: 0px; background-image: url(images/overlay.png);"><span id="suggestedText"><a href="Javascript:void(0);" onclick="jQuery(\'#tertiary_2\').fadeOut(200, function() { loadSuggestedArtist('+ relatedArtists[x].id +') });">'+ relatedArtists[x].artistName +'</a></span></div>';
					relatedHTML += '</div>';
				}
				break;
			
			default:
	
				var randomnumber = Math.floor(Math.random()*relatedArtists.length);
				for(x = 0; x < 2; x++)
				{
					if(randomnumber != tempRand)
					{
						tempRand = randomnumber;
						relatedHTML += '<div style="position:relative; width: 315px; height:173px; overflow: hidden; border: 1px solid #333333; margin: 0px 0px 10px 0px">';
						relatedHTML += '<div style="position: absolute; z-index:0; width: 315px; height:173; top: 0px; left: 0px"><a href="Javascript:void(0);" onclick="jQuery(\'#tertiary_2\').fadeOut(200, function() { loadSuggestedArtist('+ relatedArtists[randomnumber].id +') });"><img src="'+ relatedArtists[randomnumber].artistImage +'" width="315" height="173" border="0" /></a></div>';
						relatedHTML += '<div style="position: absolute; z-index:1; width: 315px; height:17;top: 157px; left: 0px; background-image: url(images/overlay.png);"><span id="suggestedText"><a href="Javascript:void(0);" onclick="jQuery(\'#tertiary_2\').fadeOut(200, function() { loadSuggestedArtist('+ relatedArtists[randomnumber].id +') });">'+ relatedArtists[randomnumber].artistName +'</a></span></div>';
						relatedHTML += '</div>';
					} else {
						x--;
					}
					randomnumber = Math.floor(Math.random()*relatedArtists.length);
				
				}
				break;
		}
		relatedHTML += '</div>';
	}
	
	var pageArray = new Array;
	
	pageArray.push(bioHTML);
	
	if(newsHTML != "") pageArray.push(newsHTML);
	if(videoHTML != "") pageArray.push(videoHTML);
	if(relatedHTML != "") pageArray.push(relatedHTML);
	if(releaseHTML != "") pageArray.push(releaseHTML);
	if(eventsHTML != "") pageArray.push(eventsHTML);
	

	for(var nd in pageArray)
	{
		switch(nd)
		{
			case "0":
			case "3":
			case "6":
				column1HTML += pageArray[nd];
				break;
				
			case "1":
			case "4":
			case "7":
				column2HTML += pageArray[nd];
				break;
				
			case "2":
			case "5":
			case "8":
				column3HTML += pageArray[nd];
				break;
		}
	}
	
	column1HTML += "</div>";  column2HTML += "</div>";  column3HTML += "</div>";
	
	tertiary_2.innerHTML += column1HTML + column2HTML + column3HTML;

	if(artist.feedUrl != "") printArtistNews(artist.feedUrl, artist.feedType);
	
	if(artist.videos.length > 0) loadArtistVideo(artist.videos[0].videoId);
	
	jQuery('#tertiary_2').fadeIn(300, function() { setScrollBars() });
}

function setScrollBars()
{

	var divMaskHeight = 290;
	
	if(document.getElementById("releasesTrunc") != null)
	{
		var relThumb = document.getElementById("relThumb");
		var relDiv = document.getElementById("releasesTrunc");
		var relOffsetHeight = relDiv.offsetHeight;

		if(relOffsetHeight > divMaskHeight)
		{
			Drag.init(relThumb, null, 305, 305, 0, (divMaskHeight - 50));
				relThumb.onDrag = function(x, y) {
				var dragPercent = (y / (divMaskHeight - 50));
				var scrollDif = relOffsetHeight - divMaskHeight;
				relDiv.style.top= "-"+scrollDif * dragPercent +"px";
			}
		} else {
			relThumb.style.display = "none";
		}
	}
	
	if(document.getElementById("bioTrunc") != null)
	{
		var bioThumb = document.getElementById("bioThumb");
		var bioDiv =document.getElementById("bioTrunc");
		var bioOffsetHeight = bioDiv.offsetHeight;
		//alert(bioOffsetHeight);
		if(bioOffsetHeight > divMaskHeight)
		{
			Drag.init(bioThumb, null, 305, 305, 0, (divMaskHeight - 50));
				bioThumb.onDrag = function(x, y) {
				var dragPercent = (y / (divMaskHeight - 50));
				var scrollDif = bioOffsetHeight - divMaskHeight;
				bioDiv.style.top= "-"+scrollDif * dragPercent +"px";
			}
		} else {
			bioThumb.style.display = "none";
		}
	}
	
	if(document.getElementById("eventTrunc") != null)
	{
		var eventThumb = document.getElementById("eventThumb");
		var eventDiv = document.getElementById("eventTrunc");
		var eventOffsetHeight = eventDiv.offsetHeight;

		if(eventOffsetHeight > divMaskHeight)
		{
			Drag.init(eventThumb, null, 305, 305, 0, (divMaskHeight - 50));
				eventThumb.onDrag = function(x, y) {
				var dragPercent = (y / (divMaskHeight - 50));
				var scrollDif = eventOffsetHeight - divMaskHeight;
				eventDiv.style.top= "-"+scrollDif * dragPercent +"px";
			}
		} else {
			eventThumb.style.display = "none";
		}
	}
}

function setScrollBarsNews()
{

	var divMaskHeight = 350;
	
	var newsThumb = document.getElementById("newsThumb");
	var newsDiv =document.getElementById("newsTrunc");
	var newsOffsetHeight = newsDiv.offsetHeight;
	
	if(newsOffsetHeight > divMaskHeight)
	{
		Drag.init(newsThumb, null, 305, 305, 0, (divMaskHeight - 50));
			newsThumb.onDrag = function(x, y) {
			var dragPercent = (y / (divMaskHeight - 50));
			var scrollDif = newsOffsetHeight - divMaskHeight;
			newsDiv.style.top= "-"+scrollDif * dragPercent +"px";
		}
	} else {
		newsThumb.style.display = "none";
	}
	
}

function loadSuggestedArtist(id)
{

	var caught = false;
	var thisIndex = 0;
	
	for(var sug in ContentFlowGlobal.Flows[0].items)
	{
		if(id == ContentFlowGlobal.Flows[0].items[sug].content.getAttribute('artistId'))
		{
			caught = true;
			thisIndex = sug;
		}
	}
	
	if(caught == true)
	{
		ContentFlowGlobal.Flows[0].moveToIndex(thisIndex);
	} else {
		loadArtistListing(id);
	}
}

function checkForId(array, id)
{
	for(var check in array)
	{
		if(id == array[check].id) return true;
	}
	
	return false;
}
		
function loadGenresArtistPage()
{
	var html = '<table width="100%" cellspacing="0" cellpadding="0"><tr valign="top" align="left"><td width="50%"><table cellspacing="0" cellpadding="2">';
	
	var it = 0;
	
	var dividend = Math.ceil(artistObj[1].genres.length / 2);
	
	for(var gn in artistObj[1].genres)
	{
		var genre = artistObj[1].genres[gn].genre;
		
		html += '<tr valign="top" align="left"><td><span id="genreListing"><a href="Javascript:void(0);" onclick="showGenrePane(); jQuery(\'#tertiary_2\').fadeOut(200, function() { loadArtistListing(null, '+ gn +'); });">' + genre +'</a></span></td></tr>';
		
		if(it > 0 && ((it + 1) % dividend == 0)) html += '</table></td><td width="50%"><table width="100%" cellspacing="0" cellpadding="2"><tr valign="top" align="left">';
		
		it++;
	}
	
	html += '</table></td></tr><tr><td style="padding: 10px 0px 0px 0px"><span id="genreListing"><a href="Javascript:void(0);" onclick="showGenrePane(); jQuery(\'#tertiary_2\').fadeOut(200, function() { loadArtistListing(); });">Full Artist Listing (A - Z)</a></span></td></tr></table>';
	
	html += '<br/><div id="closeButton" style="float:right"><a href="Javascript:void(0);" onclick="showGenrePane();"><img src="images/close_button_s.png" border="0"></a></div>';
	document.getElementById('tertiaryGenreListing').innerHTML = html;
	
	document.getElementById('tertiaryGenreListing').style.height = "auto";
	jQuery('#tertiaryGenreDiv').fadeIn(500);
	
}

function loadArtistVideo(videoId)
{

	document.getElementById('videoDiv').innerHTML = '<embed src="http://c.brightcove.com/services/viewer/federated_f9/557970707001?isVid=1&isUI=1" bgcolor="#FFFFFF" flashVars="@videoPlayer='+videoId+'&playerID=557970707001&&domain=embed&dynamicStreaming=true" base="http://admin.brightcove.com" name="flashObj" width="320" height="240" seamlesstabbing="false" type="application/x-shockwave-flash" allowFullScreen="true" allowScriptAccess="always" swLiveConnect="true" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed>';
}

// ArtistNews feed

var oXMLHttpArtistNews;

function GetArtistNewsXMLHttpObject()
{
     oXMLHttpArtistNews = null;

      try
      {
            oXMLHttpArtistNews = new ActiveXObject("MSXML2.XMLHTTP");
      }
      catch (E)
      {
            try
            {
                  oXMLHttpArtistNews = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (E)
            {
              oXMLHttpArtistNews = null;
            }
    }

      if ((oXMLHttpArtistNews == null) && (typeof(XMLHttpRequest) != 'undefined'))
      {
            oXMLHttpArtistNews = new XMLHttpRequest();
      }

      return oXMLHttpArtistNews;
}


var newsObj = new Object;

function printArtistNews(url, feedType)
{

	if(oXMLHttpArtistNews)
	{
		oXMLHttpArtistNews.abort();
	}

	oXMLHttpArtistNews = GetArtistNewsXMLHttpObject();

	var url = "php/getArtistNews.php?url="+ url+"&feedType="+  feedType;

	oXMLHttpArtistNews.open("POST", url, true);

	oXMLHttpArtistNews.onreadystatechange = function()
	    {
		  if (oXMLHttpArtistNews.readyState == 4)
		  {
			var JSONObject = new Object;

			var response = oXMLHttpArtistNews.responseText;

			//alert(response);
			JSONObject = JSON.parse(response);

			newsObj = JSONObject.News;

			var thisHTML = '<div id="newsTrunc" style="position: absolute; width: 305px; left: 0; top: 0; z-index:1">';
			
			for(var newsArt in newsObj)
			{
			
				var news = newsObj[newsArt];
				
				thisHTML += '<div><span id="artistHeadlineText"><a href="' + news.itemLink + '" target="_blank">'+ news.itemDate +'</a></span><br/><span id="artistHeadlineTitle"><a href="' + news.itemLink + '" target="_blank">'+ news.itemTitle +'</a></span></div>';
				
				if(newsArt < (newsObj.length - 1) && newsArt < 4) thisHTML += '</span><br/><img src="images/hr.jpg" width="100%" height="1" /><br/>';
				
				if(newsArt == 4) break;
			}
		
			thisHTML += '</div><div id="newsThumb" style="position:absolute; height:50px; width:10px; background-color:#eee; border:1px outset #eee; left:305px; top:0; z-index:2;"></div>';
			document.getElementById('newsDiv').innerHTML = thisHTML;
			setScrollBarsNews();
		  }
	    }

	oXMLHttpArtistNews.send(null);

}


function toggleDivs(id)
{

	var buttonDiv = id+"Button";
	
	var button = document.getElementById(buttonDiv).getElementsByTagName('img')[0];
	
	switch(id)
	{
		case "bio":
			var trunc = document.getElementById('bioTrunc');
			var full = document.getElementById('bioFull');
			break;

		case "releases":
			var trunc = document.getElementById('releasesTrunc');
			var full = document.getElementById('releasesFull');
			break;
			
		case "videos":
			var trunc = document.getElementById('videosTrunc');
			var full = document.getElementById('videosFull');
			break;
			
	}
	
	if(trunc.style.display == "none")
	{
		trunc.style.display = "block";
		full.style.display = "none";
		button.src = "images/moreArtist.jpg";
		
	} else {
		trunc.style.display = "none";
		full.style.display = "block";
		button.src = "images/lessArtist.jpg";
	}
}

function showGenrePane()
{
	var tertDiv = document.getElementById('tertiaryGenreListing');
	if(tertDiv.style.display == "block")
	{
		jQuery("#tertiaryGenreListing").slideUp();
		document.getElementById('closeGenreButton').getElementsByTagName('img')[0].src = 'images/genre_open.jpg';

	} else {
		
		jQuery("#tertiaryGenreListing").slideDown();
		document.getElementById('closeGenreButton').getElementsByTagName('img')[0].src = 'images/genre_close.jpg';
	}
}

function addPictures(){
        var ic = document.getElementById('itemcontainer');
        var is = ic.getElementsByTagName('img');
        for (var i=0; i< is.length; i++) {
            myNewFlow.addItem(is[i], 'last');
        }
}
