var artistID = 0;

preloadImg(["/images/artist/btn_add_favorite_ok.gif","/images/common/btn_add_ok.gif","/images/common/icon_loader.gif"]);

function openLyric(arg1){
	url = "/song/lyric/" + arg1 + "/";
	window.open(url, "lyric", "width=540, height=460, scrollbars=yes, toolbar=no, menubar=no, location=no, resizable=yes");
}
function openArtistPhoto(photoUrl){
	photoHtml = '<p><img src="' + photoUrl + '" /></p>';

	photoHtml += '<div id="artistPhotoMenu"><span class="cRed">&raquo;&nbsp;</span><a href="javascript:changeTab(\'ArtistPhoto\',' + artistID + ');">PHOTO一覧へ戻る</a></div>';
	document.getElementById("artistPhoto").innerHTML = photoHtml;
}
function changeList(showID,id,offset){

	artistID = id;

	var listMenu = new Array('Friends','Fans');
	for(var i in listMenu){
		document.getElementById('menu' + listMenu[i]).style.backgroundPosition = "left top";
	}
	document.getElementById('menu' + showID).style.backgroundPosition = "left -32px";
		
	document.getElementById('thumbListContainer').innerHTML = '<div class="loaderIcon"><img src="/images/common/icon_loader.gif" /></div>';
	
	var action = '/apis/api_artist/'
	if(showID == 'Friends'){
		action += 'get_friends/' + artistID + '/' + offset + '/';
		sendRequest(showList,'','GET',action,true,true);
	}
	else if(showID == 'Fans'){
		action += 'get_fans/' + artistID + '/' + offset + '/';
		sendRequest(showList,'','GET',action,true,true);
	}
}
function showList(returnObj){
	if(returnObj.responseText){
		document.getElementById('thumbListContainer').innerHTML = returnObj.responseText;
	}
	else{
		var html = '<div class="thumbListMenu"><p>- NA -</p></div>';	
		document.getElementById('thumbListContainer').innerHTML = html;
	}
}

//change main contents
function changeTab(showID,id,offset){

	artistID = id;

	//change menu
	var artistMenu = new Array('ArtistHome','ArtistMusic','ArtistPhoto','ArtistBio','ArtistBlog','ArtistLive','ArtistContact');
	for(var i in artistMenu){
		document.getElementById('menu' + artistMenu[i]).style.backgroundPosition = "left top";
	}
	document.getElementById('menu' + showID).style.backgroundPosition = "left -27px";

	//show loader
	document.getElementById('contentsBody').innerHTML = '<div class="loaderIcon"><img src="/images/common/icon_loader.gif" /></div>';

	//change contents
	var action = '/apis/api_artist/'
	if(showID == 'ArtistHome'){
		action += 'get_home/' + artistID + '/';
		sendRequest(showHtml,'','GET',action,true,true);
	}
	else if(showID == 'ArtistMusic'){
		action += 'get_music/' + artistID + '/';
		sendRequest(showHtml,'','GET',action,true,true);
	}
	else if(showID == 'ArtistPhoto'){
		action += 'get_photo/' + artistID + '/';
		sendRequest(showHtml,'','GET',action,true,true);
	}
	else if(showID == 'ArtistBio'){
		action += 'get_bio/' + artistID + '/';
		sendRequest(showHtml,'','GET',action,true,true);
	}
	else if(showID == 'ArtistLive'){
		action += 'get_live/' + artistID + '/';
		sendRequest(showHtml,'','GET',action,true,true);
	}
	else if(showID == 'ArtistBlog'){
		action += 'get_blog/' + artistID + '/' + offset + '/';
		sendRequest(showHtml,'','GET',action,true,true);
	}
	else if(showID == 'ArtistContact'){
		action += 'get_contact/' + artistID + '/';
		sendRequest(showHtml,'','GET',action,true,true);
	}

}
function showHtml(returnObj){
	if(returnObj.responseText){
		document.getElementById('contentsBody').innerHTML = returnObj.responseText;
	}
	else{
		var html = '<div class="noData">- NA -</div>';
		document.getElementById('contentsBody').innerHTML = html;
	}
}

//add favorite for listener
function addFavorite(id){

	artistID = id;

	document.getElementById('btnAddFavorite').innerHTML = '処理中・・・';

	var action = '/apis/api_artist/'
	action += 'add_favorite/' + artistID + '/';
	sendRequest(showAddFavorite,'','GET',action,true,true);
}
function showAddFavorite(returnObj){
	//coversion json to array
	if(returnObj.responseText){
		var html = '<img src="/images/artist/btn_add_favorite_ok.gif" width="120" height="40" alt="追加しました" />';	
	}
	else{
		var html = '追加されています';	
	}
	document.getElementById('btnAddFavorite').innerHTML = html;
}

//add cart for listener
function addCart(id){

	var target = 'btnAddCart' + id;
	document.getElementById(target).innerHTML = '・・・';

	var action = '/apis/api_order/'
	action += 'add_song/' + id + '/';
	sendRequest(showAddCart,'','GET',action,true,true);
}
function showAddCart(returnObj){
	//coversion json to array
	if(returnObj.responseText){
		var returnData = eval("("+returnObj.responseText+")");
		var target = 'btnAddCart' + returnData['song_id'];
		var html = '<img src="/images/common/btn_add_ok.gif" width="34" height="17" alt="追加しました" />';	
	}
	else{
		var html = 'error';	
	}
	document.getElementById(target).innerHTML = html;
}

//change relatedInfo
function changeRelated(relatedID,id){

	artistID = id;

	for (i = 1; i <= 3; i++) {
		if(i==relatedID){
			document.getElementById('related_' + i).className = "onFocus";
		}
		else{
			document.getElementById('related_' + i).className = "nonFocus";
		}
	}

	document.getElementById('relatedInfoBody').innerHTML = '<div class="loaderIcon"><img src="/images/common/icon_loader.gif" /></div>';
 
	var action = '/apis/api_artist/'
	if(relatedID == 1){
		action += 'get_related_playlist/' + artistID + '/';
		sendRequest(showRelated,'','GET',action,true,true);
	}
	else if(relatedID == 2){
		action += 'get_related_genre/' + artistID + '/';
		sendRequest(showRelated,'','GET',action,true,true);
	}
	else if(relatedID == 3){
		action += 'get_related_pref/' + artistID + '/';
		sendRequest(showRelated,'','GET',action,true,true);
	}
}
function showRelated(returnObj){
	if(returnObj.responseText){
		document.getElementById('relatedInfoBody').innerHTML = returnObj.responseText;
	}
	else{
		var html = '<p>- NA -</p>';	
		document.getElementById('relatedInfoBody').innerHTML = html;
	}
}
