// JavaScript Document
//REQUIRES JTOOLSJS
//REQUIRES PROTOTYPEJS
//REQUIRES EFFECTSJS
//BUILDS A TOGGLE CONTROLED TOP TWENTY ARTIST ON DEMAND LIST
var GreatestGainer = Class.create();
GreatestGainer.prototype = {
	initialize:function(con, gif){
		this.loader = gif;
		this.container = con;
		this.width = con.getWidth();
		if(this.width > 300){
			this.width = 300;	
		}
		var agent = navigator.userAgent.toLowerCase();
		//include correct stylesheet
		if(agent.match(/msie/) && !agent.match(/msie 7/)){
			JTools.include('/cc-common/js/widget_css/GreatestGainer/ie_6_'+this.width+'.css', true);
		}else{
			JTools.include('/cc-common/js/widget_css/GreatestGainer/normal_'+this.width+'.css', true);
		}
		this.get_list();
	},
	get_list:function(){
		new Ajax.Request(
			'/cc-common/js/ajax_services/top_twenty_greatest_gainer.php',
			{
				method:'get',
				parameters:{},
				on200:this.returned_list.bind(this)
			}
		);	
	},
	returned_list: function(transport){
		eval(transport.responseText);
		if(o.greatest_gainer){
			//create teh wrapping container
			this.topTwenty_div = JTools._createDOMElement('div','topTwenty',[{name:'id', value:'topTwenty_div'}]);
			//HEADER//
			//create the header container
			this.topTwentyHeader_div = JTools._createDOMElement('div','topTwentyHeader',[{name:'id', value:'topTwentyHeader_div'}]);
			//append the header to the top twenty wrapping container
			this.topTwenty_div.appendChild(this.topTwentyHeader_div);
			//END HEADER//
			//GG BOX//
			//create the greatest gainer box div
			this.topTwentyGreatestGainerBox_div = JTools._createDOMElement('div','topTwentyGreatestGainerBox',[{name:'id', value:'topTwentyGreatestGainerBox_div'}]);
			
			//create the greatest gainer photo div
			this.topTwentyGreatestGainerPhoto_div = JTools._createDOMElement('div','topTwentyGreatestGainerPhoto',[{name:'id', value:'topTwentyGreatestGainerPhoto_div'}]);
			
			//create the greatestGainerPhotoimage
			this.topTwentyGreatestGainerPhoto_img = JTools._createDOMElement('img',false,[{name:'src', value:'/cc-common/templates/thumbnail2.php?wid=60&hei=59&convert_img=http://content.clearchannel.com'+o.greatest_gainer.greatest_gainer_image+'&wmax=60&hmax=59&quality=90'}]);
			//observe the onclick for the img
			if(o.greatest_gainer.od_apid != ''){
				var greatest_gainer_url = '/cc-common/ondemand/player.html?apid='+o.greatest_gainer.od_apid;
				(o.greatest_gainer.od_video_mid != '')?greatest_gainer_url=greatest_gainer_url+'&mid='+o.greatest_gainer.od_video_mid:greatest_gainer_url=greatest_gainer_url+'&mid='+o.greatest_gainer.od_audio_mid;
				Event.observe(this.topTwentyGreatestGainerPhoto_img, 'click', function(){PlayerPopups.openPlayer(greatest_gainer_url);});	
			}else if(o.greatest_gainer.vod_video_id != ''){
				Event.observe(this.topTwentyGreatestGainerPhoto_img, 'click', function(){var url = '/cc-common/ondemand/player.html?program=vod&track_id='+o.greatest_gainer.vod_video_id;PlayerPopups.openPlayer(url);});
			}
			//append the topTwentyGreatestGainerPhoto_img t0 the topTwentyGreatestGainerPhoto_div
			this.topTwentyGreatestGainerPhoto_div.appendChild(this.topTwentyGreatestGainerPhoto_img);
			//append the topTwentyGreatestGainerPhoto_div to the topTwentyGreatestGainerBox_div
			this.topTwentyGreatestGainerBox_div.appendChild(this.topTwentyGreatestGainerPhoto_div);
			
			
			//create the topTwentyGreatestGainerContent_div
			this.topTwentyGreatestGainerContent_div = JTools._createDOMElement('div','topTwentyGreatestGainerContent',[{name:'id', value:'topTwentyGreatestGainerContent_div'}]);
			
			//create the topTwentyGreatestGainerTitle_div
			//check to see if this is the liveearth page and set the greatest gainer title appropriately
			if(document.location.toString().match(/liveearth/)){
					var greatest_gainer_title = 'Live Earth Performers';
			}else{
				var greatest_gainer_title='GREATEST GAINER';
			}
			
			this.topTwentyGreatestGainerTitle_div = JTools._createDOMElement('div','topTwentyGreatestGainerTitle',[{name:'id', value:'topTwentyGreatestGainerTitle_div'}], greatest_gainer_title);
			
			//append the topTwentyGreatestGainerTitle_div to the topTwentyGreatestGainerContent_div
			this.topTwentyGreatestGainerContent_div.appendChild(this.topTwentyGreatestGainerTitle_div);			
			
			//create the topTwentyGreatestGainerArtist_div
			this.topTwentyGreatestGainerArtist_div = JTools._createDOMElement('div','topTwentyGreatestGainerArtist',[{name:'id', value:'topTwentyGreatestGainerArtist_div'}]);
			//create the topTwentyGreatestGainerArtist_div_anchor div
			this.topTwentyGreatestGainerArtist_div_anchor = JTools._createDOMElement('a',false,[{name:'href', value:'javascript:void(0);'}], o.greatest_gainer.artist);
			//observe the onclick for the anchor
			if(o.greatest_gainer.od_apid != ''){
				var greatest_gainer_url = '/cc-common/ondemand/player.html?apid='+o.greatest_gainer.od_apid;
				(o.greatest_gainer.od_video_mid != '')?greatest_gainer_url=greatest_gainer_url+'&mid='+o.greatest_gainer.od_video_mid:greatest_gainer_url=greatest_gainer_url+'&mid='+o.greatest_gainer.od_audio_mid;
				Event.observe(this.topTwentyGreatestGainerArtist_div_anchor, 'click', function(){PlayerPopups.openPlayer(greatest_gainer_url);});	
			}else if(o.greatest_gainer.vod_video_id != ''){
				Event.observe(this.topTwentyGreatestGainerArtist_div_anchor, 'click', function(){var url = '/cc-common/ondemand/player.html?program=vod&track_id='+o.greatest_gainer.vod_video_id;PlayerPopups.openPlayer(url);});
			}
			//append the topTwentyGreatestGainerArtist_div_anchor to the topTwentyGreatestGainerArtist_div
			this.topTwentyGreatestGainerArtist_div.appendChild(this.topTwentyGreatestGainerArtist_div_anchor);
			
			//append the topTwentyGreatestGainerArtist_div to the topTwentyGreatestGainerContent_div
			this.topTwentyGreatestGainerContent_div.appendChild(this.topTwentyGreatestGainerArtist_div);
			
			//create the topTwentyGreatestGainerSong_div
			this.topTwentyGreatestGainerSong_div = JTools._createDOMElement('div','topTwentyGreatestGainerSong',[{name:'id', value:'topTwentyGreatestGainerSong_div'}]);
			//create the topTwentyGreatestGainerSong_div_anchor
			this.topTwentyGreatestGainerSong_div_anchor = JTools._createDOMElement('a',false,[{name:'href', value:'javascript:void(0);'}], o.greatest_gainer.song);
			//observe the onclick for the anchor
			if(o.greatest_gainer.od_apid != ''){
				var greatest_gainer_url = '/cc-common/ondemand/player.html?apid='+o.greatest_gainer.od_apid;
				(o.greatest_gainer.od_video_mid != '')?greatest_gainer_url=greatest_gainer_url+'&mid='+o.greatest_gainer.od_video_mid:greatest_gainer_url=greatest_gainer_url+'&mid='+o.greatest_gainer.od_audio_mid;
				Event.observe(this.topTwentyGreatestGainerSong_div_anchor, 'click', function(){PlayerPopups.openPlayer(greatest_gainer_url);});	
			}else if(o.greatest_gainer.vod_video_id != ''){
				Event.observe(this.topTwentyGreatestGainerSong_div_anchor, 'click', function(){var url = '/cc-common/ondemand/player.html?program=vod&track_id='+o.greatest_gainer.vod_video_id;PlayerPopups.openPlayer(url);});
			}
			//append the topTwentyGreatestGainerSong_div_anchor to the topTwentyGreatestGainerSong_div
			this.topTwentyGreatestGainerSong_div.appendChild(this.topTwentyGreatestGainerSong_div_anchor);
			//append the topTwentyGreatestGainerSong_div to the topTwentyGreatestGainerContent_div
			this.topTwentyGreatestGainerContent_div.appendChild(this.topTwentyGreatestGainerSong_div);
			
			//create teh topTwentyGreatestGainerIcons_div
			this.topTwentyGreatestGainerIcons_div = JTools._createDOMElement('div','topTwentyGreatestGainerIcons',[{name:'id', value:'topTwentyGreatestGainerIcons_div'}]);
			//if there is a greatest gainer video
			
			
			if(o.greatest_gainer.od_audio_mid !=''){
				//create teh topTwentyGreatestGainerIcons_video_div
				this.topTwentyGreatestGainerIcons_audio_div = JTools._createDOMElement('div','topTwentyIcon',[{name:'id', value:'topTwentyGreatestGainerIcons_audio_div'}]);
				//create the topTwentyGreatestGainerIcons_audio_div_img
				this.topTwentyGreatestGainerIcons_audio_div_img = JTools._createDOMElement('img',false,[{name:'src', value:'/cc-common/templates/00guide/icons/white/speaker.gif'}]);
				//observe the onclick for the image
				var greatest_gainer_url = '/cc-common/ondemand/player.html?apid='+o.greatest_gainer.od_apid+'&mid='+o.greatest_gainer.od_audio_mid;
				Event.observe(this.topTwentyGreatestGainerIcons_audio_div_img, 'click', function(){PlayerPopups.openPlayer(greatest_gainer_url);});	
				//append the topTwentyGreatestGainerIcons_video_div_img to the topTwentyGreatestGainerIcons_video_div
				this.topTwentyGreatestGainerIcons_audio_div.appendChild(this.topTwentyGreatestGainerIcons_audio_div_img);
				//append the topTwentyGreatestGainerIcons_audio_div to the topTwentyGreatestGainerIcons_div
				this.topTwentyGreatestGainerIcons_div.appendChild(this.topTwentyGreatestGainerIcons_audio_div);
			}else{
				//create teh topTwentyGreatestGainerIcons_video_div
				this.topTwentyGreatestGainerIcons_audio_div = JTools._createDOMElement('div','topTwentyIcon',[{name:'id', value:'topTwentyGreatestGainerIcons_audio_div'}]);
				//append the topTwentyGreatestGainerIcons_audio_div to the topTwentyGreatestGainerIcons_div
				this.topTwentyGreatestGainerIcons_div.appendChild(this.topTwentyGreatestGainerIcons_audio_div);
			}
			if(o.greatest_gainer.gallery_id != ''){
				//create teh topTwentyGreatestGainerIcons_video_div
				this.topTwentyGreatestGainerIcons_gallery_div = JTools._createDOMElement('div','topTwentyIcon',[{name:'id', value:'topTwentyGreatestGainerIcons_gallery_div'}]);
				//create the topTwentyGreatestGainerIcons_gallery_div_img
				this.topTwentyGreatestGainerIcons_gallery_div_img = JTools._createDOMElement('img',false,[{name:'src', value:'/cc-common/templates/00guide/icons/white/camera.gif'}]);
				//observe the onclick for the image
				Event.observe(this.topTwentyGreatestGainerIcons_gallery_div_img, 'click', function(){window.open('/cc-common/gallery/display.html?album_id='+o.greatest_gainer.gallery_id,'_blank','width=728,height=600,,resizable=no,scrollbars=no,menu=no,status=no');});	
				//append the topTwentyGreatestGainerIcons_video_div_img to the topTwentyGreatestGainerIcons_video_div
				this.topTwentyGreatestGainerIcons_gallery_div.appendChild(this.topTwentyGreatestGainerIcons_gallery_div_img);
				//append the topTwentyGreatestGainerIcons_gallery_div to the topTwentyGreatestGainerIcons_div
				this.topTwentyGreatestGainerIcons_div.appendChild(this.topTwentyGreatestGainerIcons_gallery_div);
			}else{
				//create teh topTwentyGreatestGainerIcons_video_div
				this.topTwentyGreatestGainerIcons_gallery_div = JTools._createDOMElement('div','topTwentyIcon',[{name:'id', value:'topTwentyGreatestGainerIcons_gallery_div'}]);
				//append the topTwentyGreatestGainerIcons_gallery_div to the topTwentyGreatestGainerIcons_div
				this.topTwentyGreatestGainerIcons_div.appendChild(this.topTwentyGreatestGainerIcons_gallery_div);
			}
			if(o.greatest_gainer.od_video_mid != '' || o.greatest_gainer.vod_video_id != ''){
				//create teh topTwentyGreatestGainerIcons_video_div
				this.topTwentyGreatestGainerIcons_video_div = JTools._createDOMElement('div','topTwentyIcon',[{name:'id', value:'topTwentyGreatestGainerIcons_video_div'}]);
				//create the topTwentyGreatestGainerIcons_video_div_img
				this.topTwentyGreatestGainerIcons_video_div_img = JTools._createDOMElement('img',false,[{name:'src', value:'/cc-common/templates/00guide/icons/white/videocamera.gif'}]);
				//observe the onclick for the image
				if(o.greatest_gainer.od_video_mid != ''){
					var greatest_gainer_url = '/cc-common/ondemand/player.html?apid='+o.greatest_gainer.od_apid+'&mid='+o.greatest_gainer.od_video_mid;
					Event.observe(this.topTwentyGreatestGainerIcons_video_div_img, 'click', function(){PlayerPopups.openPlayer(greatest_gainer_url);});	
				}else if(o.greatest_gainer.vod_video_id != ''){
					Event.observe(this.topTwentyGreatestGainerIcons_video_div_img, 'click', function(){var url = '/cc-common/ondemand/player.html?program=vod&track_id='+o.greatest_gainer.vod_video_id;PlayerPopups.openPlayer(url);});
				}
				//append the topTwentyGreatestGainerIcons_video_div_img to the topTwentyGreatestGainerIcons_video_div
				this.topTwentyGreatestGainerIcons_video_div.appendChild(this.topTwentyGreatestGainerIcons_video_div_img);
				//append the topTwentyGreatestGainerIcons_video_div to the topTwentyGreatestGainerIcons_div
				this.topTwentyGreatestGainerIcons_div.appendChild(this.topTwentyGreatestGainerIcons_video_div);
			}else{
				//create teh topTwentyGreatestGainerIcons_video_div
				this.topTwentyGreatestGainerIcons_video_div = JTools._createDOMElement('div','topTwentyIcon',[{name:'id', value:'topTwentyGreatestGainerIcons_video_div'}]);
				//append the topTwentyGreatestGainerIcons_video_div to the topTwentyGreatestGainerIcons_div
				this.topTwentyGreatestGainerIcons_div.appendChild(this.topTwentyGreatestGainerIcons_video_div);
			}
			if(o.greatest_gainer.download_link != ''){
				//create teh topTwentyGreatestGainerIcons_video_div
				this.topTwentyGreatestGainerIcons_download_div = JTools._createDOMElement('div','topTwentyIcon',[{name:'id', value:'topTwentyGreatestGainerIcons_download_div'}]);
				//create the topTwentyGreatestGainerIcons_download_div_img
				this.topTwentyGreatestGainerIcons_download_div_img = JTools._createDOMElement('img',false,[{name:'src', value:'/cc-common/templates/00guide/icons/download_bluebg.gif'}]);
				//observe the onclick for the image
				Event.observe(this.topTwentyGreatestGainerIcons_download_div_img, 'click', function(){window.open(o.greatest_gainer.download_link,'download');});	
				//append the topTwentyGreatestGainerIcons_video_div_img to the topTwentyGreatestGainerIcons_video_div
				this.topTwentyGreatestGainerIcons_download_div.appendChild(this.topTwentyGreatestGainerIcons_download_div_img);
				//append the topTwentyGreatestGainerIcons_video_div to the topTwentyGreatestGainerIcons_div
				this.topTwentyGreatestGainerIcons_div.appendChild(this.topTwentyGreatestGainerIcons_download_div);
			}else{
				//create teh topTwentyGreatestGainerIcons_video_div
				this.topTwentyGreatestGainerIcons_download_div = JTools._createDOMElement('div','topTwentyIcon',[{name:'id', value:'topTwentyGreatestGainerIcons_download_div'}]);
				//append the topTwentyGreatestGainerIcons_download_div to the topTwentyGreatestGainerIcons_div
				this.topTwentyGreatestGainerIcons_div.appendChild(this.topTwentyGreatestGainerIcons_download_div);
			}
			//append the topTwentyGreatestGainerIcons_div to the topTwentyGreatestGainerContent_div
			this.topTwentyGreatestGainerContent_div.appendChild(this.topTwentyGreatestGainerIcons_div);
			//append the topTwentyGreatestGainerContent_div to the topTwentyGreatestGainerBox_div
			this.topTwentyGreatestGainerBox_div.appendChild(this.topTwentyGreatestGainerContent_div);
			//append the topTwentyGreatestGainerBox_div to the top twenty div
			this.topTwenty_div.appendChild(this.topTwentyGreatestGainerBox_div);
			//END GG BOX//
			
			//GG MIDDLE//
			//create the top twenty middle div
			this.topTwentyMiddle_div = JTools._createDOMElement('div','topTwentyMiddle',[{name:'id', value:'topTwentyMiddle_div'}]);
			
			//create the topTwentyPosDisplay_div
			this.topTwentyPosDisplay_div = JTools._createDOMElement('div','topTwentyPosDisplay',[{name:'id', value:'topTwentyPosDisplay_div'}], '1 - 10 of 20');
			//append the topTwentyPosDisplay_div to the topTwentyMiddle_div
			this.topTwentyMiddle_div.appendChild(this.topTwentyPosDisplay_div);
			//create the topTwentyUp_div
			this.topTwentyUp_div = JTools._createDOMElement('div','topTwentyUpContainer',[{name:'id', value:'topTwentyUp'}, {name:'style', value:'cursor: pointer;'}]);
			//append the topTwentyUp_div to the topTwentyMiddle_div
			this.topTwentyMiddle_div.appendChild(this.topTwentyUp_div);
			//assign bindings for events
			this.mouseover_binding = this.highlight.bind(this);
			this.mouseout_binding = this.lowlight.bind(this);
			this.up_click_binding = this._up.bind(this);
			//observe events for the topTwentyMiddle_div
			Event.observe(this.topTwentyUp_div, 'mouseover', this.mouseover_binding);
			Event.observe(this.topTwentyUp_div, 'mouseout', this.mouseout_binding);
			//create the topTwentyDown_div
			this.topTwentyDown_div = JTools._createDOMElement('div','topTwentyDownContainer',[{name:'id', value:'topTwentyDown'}, {name:'style', value:'cursor: pointer;'}]);
			//append the topTwentyUp_div to the topTwentyMiddle_div
			this.topTwentyMiddle_div.appendChild(this.topTwentyDown_div);
			this.down_click_binding = this._down.bind(this);
			//observe events for the topTwentyMiddle_div
			Event.observe(this.topTwentyDown_div, 'mouseover', this.mouseover_binding);
			Event.observe(this.topTwentyDown_div, 'mouseout', this.mouseout_binding);
			
			
			
			//append the to topTwentyMiddle_div the this.topTwenty_div
			this.topTwenty_div.appendChild(this.topTwentyMiddle_div);
			//END MIDDLE//
			//DISPLAY//
			this.topTwentyItems_div = JTools._createDOMElement('div','topTwentyItems',[{name:'id', value:'topTwentyItems_div'}]);
			
			//create the topTen_div
			this.topTen_div = JTools._createDOMElement('div','topTwentyTop',[{name:'id', value:'topTen_div'}]);
			this.link_array=[];
			//loop through the first ten artists
			for(var j = 0; j<10; j++){
				this.build_artist_item(o, j);
			}
			//append the topTen_div to the topTwentyItems_div
			this.topTwentyItems_div.appendChild(this.topTen_div);
			//create the bottomTen_div
			this.bottomTen_div = JTools._createDOMElement('div','topTwentyBottom',[{name:'id', value:'bottomTen_div'}]);

			//loop through the first ten artists
			for(var k = 10; k<20; k++){
				this.build_artist_item(o, k);
			}
			//append the topTen_div to the topTwentyItems_div
			this.topTwentyItems_div.appendChild(this.bottomTen_div);
			
			//append the topTwentyItems_div to the topTwenty_div
			this.topTwenty_div.appendChild(this.topTwentyItems_div);
			//END DISPLAY//
			this.loader.style.display='none';
			//display the container
			this.container.appendChild(this.topTwenty_div);
			
			this.calculate_heights(this);
		}
	},
	build_artist_item:function(obj, num){
		if(num%2 != 0){
							var c_name = 'topTwentyOddItem';
						}else{
							var c_name = 'topTwentyEvenItem';
						}
						var item_div = JTools._createDOMElement('div',c_name,[{name:'id', value:'item_div_'+num}]);
						
						//create the topTwentyInformation_div
						var topTwentyInformation_div = JTools._createDOMElement('div','topTwentyInformation',[{name:'id', value:'topTwentyInformation_'+num}]);
						
						//create the topTwentyItemArtistInfo_div
						var topTwentyItemArtistInfo_div = JTools._createDOMElement('div','topTwentyItemArtistInfo',[{name:'id', value:'topTwentyItemArtistInfo_'+num}]);
						
						//create the topTwentyItemNumberSong_div
						var topTwentyItemNumberSong_div = JTools._createDOMElement('div','topTwentyItemNumberSong',[{name:'id', value:'topTwentyItemNumberSong_'+num}]);
						
						//create the topTwentyItemNumber_div
						var topTwentyItemNumber_div = JTools._createDOMElement('div','topTwentyItemNumber',[{name:'id', value:'topTwentyItemNumber_'+num}]);
						//create the topTwentyItemNumber_div_anchor
						var topTwentyItemNumber_div_anchor = JTools._createDOMElement('a',false,[{name:'href', value:'javascript:void(0);'}], obj['artist_'+num].position);
						//observe the appropriate action
						//observe the onclick for the img
						if(obj['artist_'+num].od_apid != ''){
							if(obj['artist_'+num].od_video_mid != ''){
								Event.observe(topTwentyItemNumber_div_anchor, 'click', function(){var url = '/cc-common/ondemand/player.html?apid='+obj['artist_'+num].od_apid+'&mid='+obj['artist_'+num].od_video_mid;PlayerPopups.openPlayer(url);});
							}else{
								Event.observe(topTwentyItemNumber_div_anchor, 'click', function(){var url = '/cc-common/ondemand/player.html?apid='+obj['artist_'+num].od_apid+'&mid='+obj['artist_'+num].od_audio_mid;PlayerPopups.openPlayer(url);});
							}
						}else if(obj['artist_'+num].vod_video_id != ''){
							Event.observe(topTwentyItemNumber_div_anchor, 'click', function(){var url = '/cc-common/ondemand/player.html?program=vod&track_id='+obj['artist_'+num].vod_video_id;PlayerPopups.openPlayer(url);});
						}
						//append topTwentyItemNumber_div_anchor to the topTwentyItemNumber_div
						topTwentyItemNumber_div.appendChild(topTwentyItemNumber_div_anchor);
						//create the topTwentyItemSong_div
						var topTwentyItemSong_div = JTools._createDOMElement('div','topTwentyItemSong',[{name:'id', value:'topTwentyItemSong_'+num}]);
						//create the topTwentyItemNumber_div_anchor
						var topTwentyItemSong_div_anchor = JTools._createDOMElement('a',false,[{name:'href', value:'javascript:void(0);'}], obj['artist_'+num].song);
						//observe the appropriate action
						//observe the onclick for the img
						if(obj['artist_'+num].od_apid != ''){
							var artist_url = '/cc-common/ondemand/player.html?apid='+obj['artist_'+num].od_apid;
							(obj['artist_'+num].od_video_mid != '')?artist_url=artist_url+'&mid='+obj['artist_'+num].od_video_mid:artist_url=artist_url+'&mid='+obj['artist_'+num].od_audio_mid;
							Event.observe(topTwentyItemSong_div_anchor, 'click', function(){PlayerPopups.openPlayer(artist_url);});	
						}else if(obj['artist_'+num].vod_video_id != ''){
							Event.observe(topTwentyItemSong_div_anchor, 'click', function(){var url = '/cc-common/ondemand/player.html?program=vod&track_id='+obj['artist_'+num].vod_video_id;PlayerPopups.openPlayer(url);});
						}
						//append topTwentyItemNumber_div_anchor to the topTwentyItemNumber_div
						topTwentyItemSong_div.appendChild(topTwentyItemSong_div_anchor);
						//append the topTwentyItemNumber_div to the topTwentyItemNumberSong_div
						topTwentyItemNumberSong_div.appendChild(topTwentyItemNumber_div);
						//append the topTwentyItemSong_div to the topTwentyItemNumberSong_div
						topTwentyItemNumberSong_div.appendChild(topTwentyItemSong_div);
						//append the topTwentyItemNumberSong_div to the topTwentyItemArtistInfo_div
						topTwentyItemArtistInfo_div.appendChild(topTwentyItemNumberSong_div);
						//create the topTwentyItemArtist_div
						var topTwentyItemArtist_div = JTools._createDOMElement('div','topTwentyItemArtist',[{name:'id', value:'topTwentyItemArtist_'+num}]);
						//create the topTwentyItemArtist_div_anchor
						var topTwentyItemArtist_div_anchor = JTools._createDOMElement('a',false,[{name:'href', value:'javascript:void(0);'}], obj['artist_'+num].artist);
						//observe the appropriate action
						//observe the onclick for the img
						if(obj['artist_'+num].od_apid != ''){
							var artist_url = '/cc-common/ondemand/player.html?apid='+obj['artist_'+num].od_apid;
							(obj['artist_'+num].od_video_mid != '')?artist_url=artist_url+'&mid='+obj['artist_'+num].od_video_mid:artist_url=artist_url+'&mid='+obj['artist_'+num].od_audio_mid;
							Event.observe(topTwentyItemArtist_div_anchor, 'click', function(){PlayerPopups.openPlayer(artist_url);});	
						}else if(obj['artist_'+num].vod_video_id != ''){
							Event.observe(topTwentyItemArtist_div_anchor, 'click', function(){var url = '/cc-common/ondemand/player.html?program=vod&track_id='+obj['artist_'+num].vod_video_id;PlayerPopups.openPlayer(url);});
						}
						//append the topTwentyItemArtist_div_anchor to the topTwentyItemArtist_div
						topTwentyItemArtist_div.appendChild(topTwentyItemArtist_div_anchor);
						//append the topTwentyItemArtist_div to the topTwentyItemArtistInfo_div
						topTwentyItemArtistInfo_div.appendChild(topTwentyItemArtist_div);
						
						//append the topTwentyItemArtistInfo_div to the topTwentyInformation_div
						topTwentyInformation_div.appendChild(topTwentyItemArtistInfo_div);
		
						
						//create the topTwentyItemIcons_div
						var topTwentyItemIcons_div = JTools._createDOMElement('div','topTwentyItemIcons',[{name:'id', value:'topTwentyItemIcons_'+num}]);
						//if there is a artist
						
						if(obj['artist_'+num].od_audio_mid !=''){
							//create teh topTwentyGreatestGainerIcons_video_div
							var topTwentyItemIcons_audio_div = JTools._createDOMElement('div','topTwentyIcon',[{name:'id', value:'topTwentyItemIcons_audio_'+num}]);
							//create the topTwentyGreatestGainerIcons_audio_div_img
							var topTwentyItemIcons_audio_div_img = JTools._createDOMElement('img',false,[{name:'src', value:'/cc-common/templates/00guide/icons/grey/speaker.gif'}]);
							//observe the onclick for the image
							var artist_url = '/cc-common/ondemand/player.html?apid='+obj['artist_'+num].od_apid+'&mid='+obj['artist_'+num].od_audio_mid;
							Event.observe(topTwentyItemIcons_audio_div_img, 'click', function(){PlayerPopups.openPlayer(artist_url);});	
							//append the topTwentyItemIcons_audio_div_img to the topTwentyItemIcons_audio_div
							topTwentyItemIcons_audio_div.appendChild(topTwentyItemIcons_audio_div_img);
							//append the topTwentyItemIcons_audio_div to the topTwentyItemIcons_div
							topTwentyItemIcons_audio_div_img.appendChild(topTwentyItemIcons_audio_div);
						}else{
							//create teh topTwentyGreatestGainerIcons_video_div
							var topTwentyItemIcons_audio_div = JTools._createDOMElement('div','topTwentyIcon',[{name:'id', value:'topTwentyItemIcons_audio_'+num}]);
							//append the topTwentyItemIcons_audio_div to the topTwentyItemIcons_div
							topTwentyItemIcons_div.appendChild(topTwentyItemIcons_audio_div);
						}
						if(obj['artist_'+num].gallery_id != ''){
							//create teh topTwentyGreatestGainerIcons_video_div
							var topTwentyItemIcons_gallery_div = JTools._createDOMElement('div','topTwentyIcon',[{name:'id', value:'topTwentyItemIcons_gallery_div'}]);
							//create the topTwentyItemIcons_gallery_div_img
							var topTwentyItemIcons_gallery_div_img = JTools._createDOMElement('img',false,[{name:'src', value:'/cc-common/templates/00guide/icons/grey/camera.gif'}]);
							//observe the onclick for the image
							Event.observe(this.topTwentyItemIcons_gallery_div_img, 'click', function(){window.open('/cc-common/gallery/display.html?album_id='+obj['artist_'+num].gallery_id,'_blank','width=728,height=600,,resizable=no,scrollbars=no,menu=no,status=no');});	
							//append the topTwentyItemIcons_video_div_img to the topTwentyItemIcons_video_div
							topTwentyItemIcons_gallery_div.appendChild(topTwentyItemIcons_gallery_div_img);
							//append the topTwentyItemIcons_gallery_div to the topTwentyItemIcons_div
							topTwentyItemIcons_div.appendChild(topTwentyItemIcons_gallery_div);
						}else{
							//create teh topTwentyItemIcons_video_div
							var topTwentyItemIcons_gallery_div = JTools._createDOMElement('div','topTwentyIcon',[{name:'id', value:'topTwentyItemIcons_gallery_div'}]);
							//append the topTwentyItemIcons_gallery_div to the topTwentyItemIcons_div
							topTwentyItemIcons_div.appendChild(topTwentyItemIcons_gallery_div);
						}
						if(obj['artist_'+num].od_video_mid != '' || obj['artist_'+num].vod_video_id != ''){
							//create teh topTwentyGreatestGainerIcons_video_div
							var topTwentyItemIcons_video_div = JTools._createDOMElement('div','topTwentyIcon',[{name:'id', value:'topTwentyItemIcons_video_'+num}]);
							//create the topTwentyGreatestGainerIcons_video_div_img
							topTwentyItemIcons_video_div_img = JTools._createDOMElement('img',false,[{name:'src', value:'/cc-common/templates/00guide/icons/grey/videocamera.gif'}]);
							//observe the onclick for the image
							if(obj['artist_'+num].od_video_mid != ''){
								var artist_url = '/cc-common/ondemand/player.html?apid='+obj['artist_'+num].od_apid+'&mid='+obj['artist_'+num].od_video_mid;
								Event.observe(topTwentyItemIcons_video_div_img, 'click', function(){PlayerPopups.openPlayer(artist_url);});	
							}else if(obj['artist_'+num].vod_video_id != ''){
								Event.observe(topTwentyItemIcons_video_div_img, 'click', function(){var url = '/cc-common/ondemand/player.html?program=vod&track_id='+obj['artist_'+num].vod_video_id;PlayerPopups.openPlayer(url);});
							}
							//append the topTwentyItemIcons_video_div_img to the topTwentyItemIcons_video_div
							topTwentyItemIcons_video_div.appendChild(topTwentyItemIcons_video_div_img);
							//append the topTwentyGreatestGainerIcons_video_div to the topTwentyGreatestGainerIcons_div
							topTwentyItemIcons_div.appendChild(topTwentyItemIcons_video_div);
						}else{
							//create teh topTwentyGreatestGainerIcons_video_div
							var topTwentyItemIcons_video_div = JTools._createDOMElement('div','topTwentyIcon',[{name:'id', value:'topTwentyItemIcons_video_'+num}]);
							//append the topTwentyItemIcons_video_div to the topTwentyItemIcons_div
							topTwentyItemIcons_div.appendChild(topTwentyItemIcons_video_div);
						}
						if(obj['artist_'+num].download_link != ''){
							//create teh topTwentyItemIcons_video_div
							var topTwentyItemIcons_download_div = JTools._createDOMElement('div','topTwentyIcon',[{name:'id', value:'topTwentyItemIcons_download_div'}]);
							//create the topTwentyItemIcons_download_div_img
							var topTwentyItemIcons_download_div_img = JTools._createDOMElement('img',false,[{name:'src', value:'/cc-common/templates/00guide/icons/download_ltgraybg.gif'}]);
							//observe the onclick for the image
							Event.observe(topTwentyItemIcons_download_div_img, 'click', function(){window.open(obj['artist_'+num].download_link,'download');});	
							//append the topTwentyItemIcons_video_div_img to the topTwentyItemIcons_video_div
							topTwentyItemIcons_download_div.appendChild(topTwentyItemIcons_download_div_img);
							//append the topTwentyItemIcons_video_div to the topTwentyItemIcons_div
							topTwentyItemIcons_div.appendChild(topTwentyItemIcons_download_div);
						}else{
							//create teh topTwentyItemIcons_video_div
							var topTwentyItemIcons_download_div = JTools._createDOMElement('div','topTwentyIcon',[{name:'id', value:'topTwentyItemIcons_download_div'}]);
							//append the topTwentyItemIcons_download_div to the topTwentyItemIcons_div
							topTwentyItemIcons_div.appendChild(topTwentyItemIcons_download_div);
						}
						//append the topTwentyItemIcons_div to the topTwentyItemArtistInfo_div
						topTwentyInformation_div.appendChild(topTwentyItemIcons_div);
						
						//append the topTwentyInformation_div to the item_div
						item_div.appendChild(topTwentyInformation_div);
						if(num < 10){
						//append the item div to the topTen_div
						this.topTen_div.appendChild(item_div);
						}else{
							this.bottomTen_div.appendChild(item_div);
						}
	},
	calculate_heights:function(obj){
		if(obj.topTen_div.up().getStyle('background-color').toString() == 'transparent'){
			setTimeout(function(){obj.calculate_heights(obj);}, 1000);
		}else{
			var upHeight = 0;
			//obj.topTen_div.immediateDescendants().each(function(_obj){upHeight += _obj.getHeight();});
			obj.up_height = obj.topTen_div.getHeight();
			var downHeight = 0;
			//obj.bottomTen_div.immediateDescendants().each(function(_obj){downHeight += _obj.getHeight();});
			obj.down_height = obj.bottomTen_div.getHeight();
			//alert(obj.down_height);
			obj.topTwentyItems_div.setStyle({
				height: obj.up_height+'px'
			});
			//observe events for up button
			obj.up_click_register();
		}
	},
	highlight:function(event){
		var element = $(Event.element(event));
		element.className = element.className + 'On';
	},
	lowlight:function(event){
		var element = $(Event.element(event));
		element.className = element.className.replace(/On/, '');
	},
	_up:function(event){
		Event.stopObserving(this.topTwentyDown_div, 'click', this.up_click_binding);
		this.topTwentyPosDisplay_div.update('10-20 of 20');
		new Effect.Parallel([new Effect.Move(this.topTen_div, {sync:true, x:0,y:-this.up_height,mode:'relative'}),new Effect.Move(this.bottomTen_div,{sync:true,x:0,y:-this.up_height,mode:'relative'}),new Effect.Morph(this.topTwentyItems_div,{style:{height:this.down_height+'px'}})],{duration:3.0,queue:{scope:'topTwenty',position:'end'}, afterFinish:this.down_click_register.bind(this)});
	},
	_down:function(event){
		Event.stopObserving(this.topTwentyUp_div, 'click', this.down_click_binding);
		this.topTwentyPosDisplay_div.update('1-20 of 20');
		new Effect.Parallel([new Effect.Move(this.topTen_div, {sync:true, x:0, y:this.up_height, mode:'relative'}),new Effect.Move(this.bottomTen_div,{sync:true, x:0, y:this.up_height, mode:'relative'}),new Effect.Morph(this.topTwentyItems_div,{style:{height:this.up_height+'px'}})],{duration:3.0,queue:{scope:'topTwenty', position:'end'}, afterFinish:this.up_click_register.bind(this)});
	},
	down_click_register:function(event){
		Event.observe(this.topTwentyUp_div, 'click', this.down_click_binding);
	},
	up_click_register:function(event){
		Event.observe(this.topTwentyDown_div, 'click', this.up_click_binding);
	}
}

