var nap_artist = {
	execute: function() {
		window.onload = function() { nap_artist.view() };
//		window.onload = function() { nap_artist.msg('<span style="color:#F00;">メンテナンス中のため、現在ご利用いただけません</span>'); };
	},
	sanitize: function( str ) {
		return str.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;');
	},
	notfound: function() {
		var box = '';
		box += '<div class="sectionDataB"><div class="innerBlockC"><div class="innerBlockD"><div class="noresults">';
		box += '<p class="message">お客様の検索された音楽が見つかりませんでした。</p>';
		box += '<p>Napsterでは、新譜・旧譜／ジャンル／アーティストの国籍を問わず、毎日たくさんの楽曲を追加しています。<br />最新の追加楽曲は、新着アルバム情報でご確認いただけます。</p>';
		box += '<ul class="link"><li><a href="/music/update">新着アルバム情報</a></li></ul><!--//link -->';
		box += '</div></div></div></div>';
		$('results').innerHTML = box;
	},
	msg: function( str ) {
		var box = '';
		box += '<div class="sectionDataB"><div class="innerBlockC"><div class="innerBlockD"><div class="noresults">';
		box += '<p class="message">'+str+'</p>';
		box += '</div></div></div></div>';
		$('results').innerHTML = box;
	},
	init: function() {
		var temp = location.href.split('/');
		if ( ! temp[temp.length-1].match(/^(\d+)/) ) {
			this.notfound();
			return false;
		}
		this.id = Number( RegExp.$1 );
		if ( isNaN( this.id ) ) {
			this.notfound();
			return false;
		}
		return true;
	},
	view: function() {
		if ( ! this.init() ) return;
		this.msg('検索中...');
		var url = this.search_url + this.id;
		new Ajax.Request( '/music/lookupXML/artist/'+this.id, { method: 'get', onComplete: function( r ) {
			var xml = r.responseXML.getElementsByTagName('result');
			var temp   = new Array;
			var exists = new Array;
			for ( var i = 0; i < xml.length; i ++ ) {
				if ( exists[xml[i].getAttribute('album_id')] ) continue;
				exists[xml[i].getAttribute('album_id')] = 1;
				temp.push( xml[i] );
			}
			if ( temp.length <= 0 ) return;
			nap_artist.result = temp;
			nap_artist.update();
		} } );
	},
	update: function() {
		this.result.sort( function( a, b ) {
			var at = a.getAttribute('album_release_year');
			var bt = b.getAttribute('album_release_year');
			if ( at == bt ) return 0;
			return at < bt ? 1 : -1;
		} );

		document.title = 'アーティスト: '+this.sanitize(this.result[0].getAttribute('artist_name'))+' | '+document.title;

		$('path_title').innerHTML = 'アーティスト: ' + this.sanitize(this.result[0].getAttribute('artist_name'));

		var delimiter = this.browser == 'ie' && this.version == 7 ? ' +' : ':';

		var box = '';
		box += '<div id="uniqueTitleBlock">';
		box += '<h1 class="self">'+this.sanitize(this.result[0].getAttribute('artist_name'))+'</h1>';

		// 申し込みバナー
		var banner_href = appeal_href ? appeal_href : '/start/';
		var banner_src = appeal_src_searchtop ? appeal_src_searchtop : '/shared/images/bnr_download_284_37.jpg';
		var banner_alt = appeal_alt ? appeal_alt : '申し込み | 聴き放題サービス入会特典初めの7日間無料!!'; 
		box += '<p class="appealingBlockA"><a href="' + banner_href + '" target="_blank">';
		box += '<img src="' + banner_src + '" alt="' + banner_alt + '" width="284" height="37" class="btn searchtop" /></a></p>';

		box += '</div><div class="sectionA"><h2 class="headingA">ディスコグラフィー</h2><div class="sectionDataB"><div class="innerBlockC">';
		box += '<p class="example"><span class="napsterlink-usage"><img src="/music/images/icon_napsterlink.gif" alt="[Napsterで聴く] : " height="22" width="22" />Napsterで聴く<span id="napsterlink-usage" style="visibility: hidden;"><img src="/music/images/baloon01.png" alt="ナップスターアプリをお持ちの方は、ボタンをクリックするとアルバム／トラックを聴くことができます。" height="48" width="272" /></span></span>';
		//box += '<li><a target="_blank" href="http://tower.jp/item/jan/'+this.result[i].getAttribute('album_id')+'?a='+escape(this.result[i].getAttribute('artist_name'))+'&t='+escape(this.result[i].getAttribute('album'))+'&kid=pnap"><img src="/music/images/btn_tower01.gif" alt="[タワレコで商品を探す]" height="39" width="39" /></a></li>';
		box += '</p>';
		box += '<div class="innerBlockE"><table class="rankingTable"><thead><tr>';
		box += '<th scope="col" class="category"><img src="/music/images/text_chart01.gif" width="66" height="13" alt="配信カテゴリ" /></th>';
		box += '<th scope="col" class="album"><img src="/music/images/text_chart02.gif" width="47" height="13" alt="アルバム" /></th>';
		box += '<th scope="col" class="related"></th></tr></thead><tbody>';

		for ( var i = 0; i < this.result.length; i ++ ) {
			box += '<tr class="'+(i%2?'even':'odd')+(i==this.result.length-1?' last':'')+'">';
			box += '<td class="category">';
			if ( this.result[i].getAttribute('streamable') == 1 ) {
				box += '<img src="/music/images/icon_infinity.gif" width="82" height="25" class="streamable" alt="聴き放題" />'
			} else {
				box += '<img src="/music/images/icon_infinity_d.gif" width="82" height="25" class="streamable" alt="" />'
			}
			if ( this.result[i].getAttribute('can_purchase') == 1 ) {
				box += '<img src="/music/images/icon_payment.gif" width="82" height="19" class="purchase" alt="有料楽曲購入" />';
			} else {
				box += '<img src="/music/images/icon_payment_d.gif" width="82" height="19" class="purchase" alt="" />';
			}
			box += '</td><td class="album"><dl class="album">';
			box += '<dt><a href="/music/album/'+this.result[i].getAttribute('album_id')+'">'+this.sanitize(this.result[i].getAttribute('album'))+'</a></dt>';
			box += '<dd class="artist">'+this.sanitize(this.result[i].getAttribute('artist_name'))+'</dd>';
			box += '<dd class="release">リリース: '+this.sanitize(this.result[i].getAttribute('album_release_year').replace(/-/g,'/'))+'</dd>';
			box += '</dl></td><td class="related"><ul class="related">';
			box += '<li><a target="_blank" href="http://sms.jp.napster.com/duet/general/handle_napster_link.html?opcode=switch&tab=browseartists&artistid='+this.result[i].getAttribute('artist_id')+'&albumid='+this.result[i].getAttribute('album_id')+'&op=play_album&ids='+this.result[i].getAttribute('album_id')+(this.result[i].getAttribute('streamable')==1?'&skip_tsc=0':'')+'&class=album&artist_id='+this.result[i].getAttribute('artist_id')+'&album_id='+this.result[i].getAttribute('album_id')+'&p=Deeplink&plc=JPTool&c=NapsterLink&t=TextLink"><img src="/music/images/btn_napster02.gif" width="39" height="39" alt="[Napsterで聴く]" /></a></li>';
			// box += '<li><a target="_blank" href="http://r.tower.jp/n2t/:'+encodeURIComponent(this.result[i].getAttribute('artist_name'))+':'+encodeURIComponent(this.result[i].getAttribute('album'))+'/nap22"><img src="/music/images/btn_tower01.gif" alt="[タワレコで商品を探す]" height="39" width="39" /></a></li>';
			// New URL Link Test -- Kanazawa
			box += '<a target="_blank" href="http://tower.jp/item/jan/?a='+encodeURIComponent(this.result[i].getAttribute('artist_name'))+'&amp;t='+encodeURIComponent(this.result[i].getAttribute('album'))+'&amp;kid=pnap"><img src="/music/images/btn_tower01.gif" alt="[タワレコで商品を探す]" height="39" width="39" /></a>';
			
			box += '</ul></td></tr>';
		}

		box += '</tbody></table></div></div></div></div>';

		s.pageName = 'アーティスト: ' + this.result[0].getAttribute('artist_name');
		var s_code = s.t();
		if ( s_code ) box += s_code;

		$('results').innerHTML = box;

		RN_preloadImages();
	}
};

nap_artist.execute();

