function renderOurPicsFlash_promo(pageNo) { 
   var startingId = 0;
   pageNo=pageNo+'';
   for(var x=startingId;x<=startingId+3;x++) {
	   var ourPickPlayer = new SWFObject("/bandit/flash/artist/ourPickArtist.swf", "featuredArtistImg"+pageNo+"_"+x+"SWF", "200", "133", "9", "#ffffff");
	   
	   if(document.getElementById("featuredArtistImg"+pageNo+"_"+x)) {
			var currentArtistInfo = document.getElementById("featuredArtistImg"+pageNo+"_"+x).firstChild;
			if(currentArtistInfo) {
				ourPickPlayer.addVariable("artistImage",currentArtistInfo.src);
				ourPickPlayer.addVariable("artistName",escape(currentArtistInfo.getAttribute('alt')));
				ourPickPlayer.addVariable("artistURL",escape(currentArtistInfo.getAttribute('rel')));
			}
			ourPickPlayer.addParam("wmode","transparent");
			ourPickPlayer.addParam("menu","false");
			
			var currentURL = window.location + '';
			if(currentURL.indexOf('dev.bandit')>=0) ourPickPlayer.addVariable("enviro","dev");
			else if(currentURL.indexOf('biz.bandit')>=0) ourPickPlayer.addVariable("enviro","biz");
			else ourPickPlayer.addVariable("enviro","www");
			
			var newOurPicksFlash = document.createElement("div");
			var replacementNodes = new Array;
			xString=x+'';
			var imageParent = document.getElementById(pageNo+x+"parent");
			imageParent.removeChild(document.getElementById("featuredArtistImg"+pageNo+"_"+xString));		
			//newOurPicksFlash.setAttribute("id","featuredArtistImg"+pageNo+"_"+x);		
			//ourPickPlayer.write(pageNo+xString+"parent");
			addSingleColourAndRender("barColour","keyColour",ourPickPlayer,pageNo+xString+"parent");
		}
   }
}

function addOurPicksArtistsEvent() {
	var widgetResponseDiv = document.getElementById('slider_ourPicksPromo');
	if (widgetResponseDiv.addEventListener) { // Firefox & Safari
		widgetResponseDiv.addEventListener('datafound', function() { 
			initHozScroller('ourPicksPromo');													 
			renderOurPicsFlash_promo(1);
			widgetResponseDiv.removeEventListener('datafound',arguments.callee,true);
		} ,true);
	}
	else if (widgetResponseDiv.attachEvent) {	 // IE
		  widgetResponseDiv.attachEvent('onclick', function() { 
		  initHozScroller('ourPicksPromo');													
		  renderOurPicsFlash_promo(1); 
		  widgetResponseDiv.detachEvent('onclick',arguments.callee,false);
		} );
	}
}

function renderJustAddedFlash(pageNo) { 
   var startingId = 0;
   pageNo=pageNo+'';
   for(var x=startingId;x<=startingId+3;x++) {
	   var ourPickPlayer = new SWFObject("/bandit/flash/artist/ourPickArtist.swf", "justAddedFeaturedArtistImg"+pageNo+"_"+x+"SWF", "200", "133", "9", "#ffffff");
	   
	   if(document.getElementById("justAddedFeaturedArtistImg"+pageNo+"_"+x)) {
			var currentArtistInfo = document.getElementById("justAddedFeaturedArtistImg"+pageNo+"_"+x).firstChild;
			if(currentArtistInfo) {
				ourPickPlayer.addVariable("artistImage",currentArtistInfo.src);
				ourPickPlayer.addVariable("artistName",escape(currentArtistInfo.getAttribute('alt')));
				ourPickPlayer.addVariable("artistURL",escape(currentArtistInfo.getAttribute('rel')));
			}
			ourPickPlayer.addParam("wmode","transparent");
			ourPickPlayer.addParam("menu","false");
			
			var currentURL = window.location + '';
			if(currentURL.indexOf('dev.bandit')>=0) ourPickPlayer.addVariable("enviro","dev");
			else if(currentURL.indexOf('biz.bandit')>=0) ourPickPlayer.addVariable("enviro","biz");
			else ourPickPlayer.addVariable("enviro","www");
			
			var newOurPicksFlash = document.createElement("div");
			var replacementNodes = new Array;
			xString=x+'';
			var imageParent = document.getElementById(pageNo+x+"parentJustAdded");

			imageParent.removeChild(document.getElementById("justAddedFeaturedArtistImg"+pageNo+"_"+xString));		

			addSingleColourAndRender("barColour","keyColour",ourPickPlayer,pageNo+xString+"parentJustAdded");
		}
   }
}

function addJustAddedArtistsEvent() {
	var widgetResponseDiv = document.getElementById('slider_justAdded');
	if (widgetResponseDiv.addEventListener) { // Firefox & Safari
		widgetResponseDiv.addEventListener('datafound', function() { 
			initHozScroller('justAdded');													 
			renderJustAddedFlash(1);
			widgetResponseDiv.removeEventListener('datafound',arguments.callee,true);
		} ,true);
	}
	else if (widgetResponseDiv.attachEvent) {	 // IE
		  widgetResponseDiv.attachEvent('onclick', function() { 
		  initHozScroller('justAdded');													
		  renderJustAddedFlash(1); 
		  widgetResponseDiv.detachEvent('onclick',arguments.callee,false);
		} );
	}
}

function getSliderPageLimit(sliderSection) {
	sliderPageLimit[sliderSection] = (document.getElementById('widgetResponse_'+sliderSection+'_pageCount').innerHTML)*1;
	}
	
function showFlashIndicators(sliderSection) {
	if(sliderPageLimit[sliderSection]) findSWF('sectionHeaderSWF_'+sliderSection).showIndicators(sliderPageLimit[sliderSection]);
}	


function addTodaysChartEvent(delayLoadingScroller) {
	var widgetResponseDiv = document.getElementById('slider_todaysChart');
	if (widgetResponseDiv.addEventListener) { // Firefox & Safari
		widgetResponseDiv.addEventListener('datafound', function() { 
			getSliderPageLimit('todaysChart');
			initChartScroller(delayLoadingScroller);
			widgetResponseDiv.removeEventListener('datafound',arguments.callee,true);
		} ,true);
	}
	else if (widgetResponseDiv.attachEvent) {	 // IE
		  widgetResponseDiv.attachEvent('onclick', function() { 
		  getSliderPageLimit('todaysChart');
		  initChartScroller(delayLoadingScroller);
		  widgetResponseDiv.detachEvent('onclick',arguments.callee,false);
		} );
	}
}

function initChartScroller(delayLoadingScroller) {	
	if(!delayLoadingScroller) {
		currentPageNo['todaysChart'] = 1;
		if(document.getElementById('prev_todaysChart')) new prevScrollButton('prev_todaysChart');
		if(document.getElementById('next_todaysChart')) new nextScrollButton('next_todaysChart');
	}
}


function fadeTodaysChart(target, countryId) {
	// init buttons if not initated already
	if(!document.getElementById('prev_todaysChartSWF')) initChartScroller();
	
	var targetTab = 'todaysChartTab' + target;
	if((document.getElementById(targetTab).parentNode.className!='selected')&&(document.getElementById(targetTab).parentNode.className!='first selected')) { // don't do if already selected
		
		findSWF('sectionHeaderSWF_todaysChart').resetIndicators();
		var colNo = 4;
		var visibleCol = (currentPageNo['todaysChart']-1)*colNo;
		
		currentPageNo['todaysChart'] = 1;
		
		var swfLoaderLocation = '/bandit/flash/common/loader_large.swf';
		
		// revert tab that was previously active
		var liTabArray = document.getElementById('innerTitleTab').getElementsByTagName('li');
		for(var x=0;x<liTabArray.length;x++) {
			if (liTabArray[x].className) {
				switch(liTabArray[x].className) {
					case 'selected':		liTabArray[x].className=''; break;
					case 'first selected':	liTabArray[x].className='first'; break;
				}
			}
		}
		
		var targetTabClass = document.getElementById(targetTab).parentNode.className;
		targetTabClass=='first' ? document.getElementById(targetTab).parentNode.className += ' selected' : document.getElementById(targetTab).parentNode.className = 'selected';
		
		
		var downloadsContainer = document.getElementById('slider_todaysChart');
		var loaderDiv = document.createElement("div");
		loaderDiv.setAttribute('id','downloadsLoader');
		var loaderplayer = new SWFObject(swfLoaderLocation, "TopDownloadsLoaderSWF", "24", "24", "7", "#FFFFFF");
		loaderplayer.addParam("wmode", "transparent");
		
		fadeChartCols(visibleCol,'out');		
		setTimeout(function() { 
							wipeSliderClean(downloadsContainer);
							downloadsContainer.appendChild(loaderDiv);	
							loaderplayer.write('downloadsLoader'); 
							},340);	
		sliderBaseURL['todaysChart'] = tabBaseURL[target];
		setTimeout(function() { getWidget(sliderBaseURL['todaysChart']+'&clicked=true&countryId='+countryId,'slider_todaysChart'); },800);
		
		var widgetResponseDiv = document.getElementById('slider_todaysChart');
		if (widgetResponseDiv.addEventListener) { // Firefox & Safari
			widgetResponseDiv.addEventListener('datafound', displayTodaysChart,true);
			widgetResponseDiv.addEventListener('datafound', function() {
					getNewPageLimit();												 
					widgetResponseDiv.removeEventListener('datafound',arguments.callee,true);	
					 },true);
			
		}
		else if (widgetResponseDiv.attachEvent) {	 // IE
			widgetResponseDiv.attachEvent('onclick', displayTodaysChart);
			widgetResponseDiv.attachEvent('onclick', function() {
					 getNewPageLimit();												 
					 widgetResponseDiv.detachEvent('onclick',arguments.callee,false);
					 });
		}
	}
}

function wipeSliderClean(sliderContainer) {
	sliderContainer.innerHTML = '';
	sliderContainer.style.left='0px'; 
}

function fadeChartCols(colStartNo, direction) {
	if(document.getElementById('topDownloadsCol'+(colStartNo)))
	fadeObject(document.getElementById('topDownloadsCol'+colStartNo),direction);
	if(document.getElementById('topDownloadsCol'+(colStartNo+1)))
	setTimeout(function() { fadeObject(document.getElementById('topDownloadsCol'+(colStartNo+1)),direction); },80);
	if(document.getElementById('topDownloadsCol'+(colStartNo+2)))
	setTimeout(function() { fadeObject(document.getElementById('topDownloadsCol'+(colStartNo+2)),direction); },160);
	if(document.getElementById('topDownloadsCol'+(colStartNo+3)))
	setTimeout(function() { fadeObject(document.getElementById('topDownloadsCol'+(colStartNo+3)),direction); },240);
}

function getNewPageLimit() {
	// find limit
	var newPageLimit = (document.getElementById('widgetResponse_todaysChart_pageCount').innerHTML)*1;
	sliderPageLimit['todaysChart'] = newPageLimit;
	// update page indicators
	findSWF('sectionHeaderSWF_todaysChart').showIndicators(newPageLimit);
	// update prev/next buttons
	findSWF('prev_todaysChartSWF').disabler(0);
	findSWF('next_todaysChartSWF').disabler(1);
	var chartNextButton = document.getElementById('next_todaysChart');
	var chartPrevButton = document.getElementById('prev_todaysChart');
	// clear existing events associated with buttons
	if(chartNextButton.removeEventListener) {
		chartNextButton.removeEventListener('click',shiftLeft,true); 
		chartPrevButton.removeEventListener('click',shiftRight,true);
	}
	else if(chartNextButton.detachEvent) {
		chartNextButton.detachEvent('onclick',shiftLeft);
		chartPrevButton.detachEvent('onclick',shiftRight);
	}
	
	if(newPageLimit>0) {
		chartNextButton.style.visibility=chartPrevButton.style.visibility='visible';
		// new event for next button
		if (chartNextButton.addEventListener) chartNextButton.addEventListener('click',shiftLeft,true);
		else if(chartNextButton.attachEvent)  chartNextButton.attachEvent('onclick', shiftLeft);
	} else chartNextButton.style.visibility=chartPrevButton.style.visibility='hidden';
}

function displayTodaysChart(e) {
	if (!e) e = window.event;
	if (e.target) e = e.target; // 'parentNode' is due to Flash element
	else if (e.srcElement) e = e.srcElement;
	if (e.nodeType == 3) // defeat Safari bug
		e = targ.parentNode;	
	
	var downloadsContainer = document.getElementById('slider_todaysChart');
	if(downloadsContainer.lastChild.innerHTML) {
		if(downloadsContainer.lastChild.getAttribute('id')=='downloadsLoader')
			downloadsContainer.removeChild(downloadsContainer.lastChild);
	}
	
	if(e.getAttribute('id')) fadeChartCols(0,'in'); // fix IE bug not removing event	
}