/**
 * @author myself
 */



;
date = new Date();
timestamp = date.getTime();
count=0;
MovieConut=0;
playFlag=0;
shuffleFlag=0;
nowMusicFlag=0;

timeWait=Array();
TimerID=Array();
gettag=Array();
waitTime= Array();
artistName = Array();
songName= Array();
cover160= Array();
amazonURL= Array();
embed_src= Array();

TimerIDtmp="";

var ExceptionNum=Array();



function loadObj(readXml){
	GetUrl =readXml+'?'+timestamp;
		new Ajax(GetUrl, {
			method: 'get',
			onRequest:function(){
				showVideo.innerHTML = '';
			},
			onSuccess:function(resTxt, resXml){
				var video= resXml.getElementsByTagName('item');
					MovieConut=video.length;
					for(i=0; i<MovieConut; i++){
					var timer= video[i].getElementsByTagName("length_seconds")[0].firstChild.nodeValue;
					timeWait[i] =parseInt(timer)*1010;
					var embed_src= video[i].getElementsByTagName('embed_src')[0].firstChild.nodeValue + "&autoplay=1";
					waitTime[i]= video[i].getElementsByTagName('length_seconds')[0].firstChild.nodeValue;
					artistName[i] = video[i].getElementsByTagName('artistName')[0].firstChild.nodeValue;
					songName[i] = video[i].getElementsByTagName('songName')[0].firstChild.nodeValue;
					cover160[i] = video[i].getElementsByTagName('cover160')[0].firstChild.nodeValue;
					amazonURL[i] = video[i].getElementsByTagName('amazonURL')[0].firstChild.nodeValue;
//gettag[i]='<object width="425" height="355"><param name="movie" value="'+embed_src+'"></param><param name="wmode" value="transparent"></param><embed src="'+embed_src+'" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>';
gettag[i]='<embed src="'+embed_src+'" type="application/x-shockwave-flash" wmode="transparent" width="455" height="380"></embed>';

}

			},
			onFailure:function(){
				//showVideo.innerHTML = "データの取得に失敗しました";
			}
		}).request();

}


function checkDeleteList31(count){
var flag=0;
alert(count);
	while (flag == 0) {
		flag=1;
		for (i = 0; i < ExceptionNum.length; i++) {
			if (count == ExceptionNum[i]) {
				flag = 0;
			}
		}
		if (flag == 0) {
			count++;
		}
	}
alert(count);
return count;
}


function checkDeleteList2(count){
var flag=0;
//alert(count);
  while (flag == 0) {
      flag=1;
      for (i = 0; i < ExceptionNum.length; i++) {
        if (count == ExceptionNum[i]) {
              flag = 0;
           }
       }
    if (flag == 0) {
          count++;
        }
  }
//alert(count);
return count;
}


function checkDeleteList(count){
var flag=0;
var songList=$$(".songList");
	while(count==MovieConut||flag==0){
		if (songList[count].style.display == "none"){
			count++;
			if(count==MovieConut){count=0}
		}
		else{
			flag=1;
		}
	}

return count;
}



function changeObj(){

//if(bi.ieMVersion==6){
//blowserAlert();
//	return false;
//}
playFlag=1;
if(ExceptionNum.length>0){
count=	checkDeleteList(count);
}

setNowPlaying(count);
nowMusicCount=count;
TimerIDtmp=setTimeout("changeObj()",timeWait[count]);
//次の準備
if(shuffleFlag ==1){
count=Math.floor( Math.random() * MovieConut);
}
else{
count=count+1;
}
if(count==MovieConut){
	count=0;
	}
}


function setNowPlaying(count){
	var nowPlaying =$("musicTitle");
	var showVideo = $('showVideo');
	var showTitle = $('showTitle');
	var showSong = $('showSong');
	
	//var pasteBlog= $('pasteAmeba');
	
	//var playingSign = $('playingSign');
	var cdJacket = $('cdJacket');
	var pasteBlogImage= $('pasteBlogImage');
	var pasteBlogArtistName= $('pasteBlogArtistName');
	var pasteBlogSongName= $('pasteBlogSongName');
	var pasteBlogAmazon=  $('pasteBlogAmazon');

var gettag='<embed src="'+embed_src[count]+'&autoplay=1" type="application/x-shockwave-flash" wmode="transparent" width="455" height="380"></embed>';	

showVideo.innerHTML=gettag;
//showVideo.innerHTML=gettag[count];
showTitle.innerHTML=artistName[count];
showSong.innerHTML=songName[count];
pasteBlogArtistName.innerHTML=artistName[count];
pasteBlogSongName.innerHTML=songName[count];
pasteBlogAmazon.href=amazonURL[count];

//playingSign.innerHTML='<img src="/img/loader.gif" /><span> Now Playing</span>';
if (cover160[count]) {
	cdJacket.innerHTML = '<a href="'+amazonURL[count]+'" title="amazonで購入"　target="_blank" ><img src="' + cover160[count] + '" height="100" width="100" /></a>';
	pasteBlogImage.innerHTML = '<img width="120" src="' + cover160[count] + '" />';
	//pasteBlogImage.href=amazonURL[count];
}

	var songDetail =$$(".songDetail");
	var coverImg =$$(".coverImg");
	for (var i = 0; i < songDetail.length; i++) {
		songDetail[i].parentNode.id="";
		//coverImg[i].style.height="32px";
		//coverImg[i].style.width="32px";
	}
	songDetail[count].parentNode.id="nowPlaying";
	//coverImg[count].style.height="50px";
	//coverImg[count].style.width="50px";
popUpIntroRewrite();
}


function nextMovie(){
//if(bi.ieMVersion==6){
//stopMovie();
//blowserAlert();
//return false;
//}
	
	if(count!=MovieConut){
		if (playFlag==1) {
			clearTimeout(TimerIDtmp);
		}
		changeObj();
	}
playFlag==1
}

function beforeMovie(){

	if (playFlag==1) {
		clearTimeout(TimerIDtmp);
		}
	if(count==1){
		count=MovieConut-1;
		changeObj();
	}
	else if (count == 0&&checkObj[0]) {
		count = MovieConut-2;
		changeObj();
	}
	else if (count == 0&&!checkObj[0]) {
		count = MovieConut-1;
		changeObj();
	}
	else if (count != 1) {
		count = count - 2;
		changeObj();
	}
	playFlag=1;
}

function startMovie(){
	if (playFlag==0) {
	changeObj();
	}
playFlag=1;
}

function stopMovie(){
	
	if(count==1){
		count=0;
	}
	else if (count == 0) {
		count = MovieConut-1;
	}
	else if (count != 1) {
		count = count - 1;
	}
	var checkObj=$("showVideo").getElementsByTagName("object")
	if (playFlag==1) {
		clearTimeout(TimerIDtmp);
	}
	$("showVideo").innerHTML="";
	playFlag=0;
	adRotation();
}

function skipMovie(num){
	if (playFlag==1) {
			clearTimeout(TimerIDtmp);
	}
	count=num;
	playFlag=1;
	changeObj();

}


function shuffleMovie(el){
	if (shuffleFlag == 0) {
		el.className="random_on";
		shuffleFlag = 1;
		count=Math.floor( Math.random() * MovieConut);
	}
	else{
		el.className="random";
		shuffleFlag = 0;
		count=nowMusicFlag+1;
	}
}

function deleteSong(el){


	if(restCount==1){
		alert("can`t remove anymore!!");
		return false;
	}
restCount=restCount-1;

var deletObj=el.parentNode.parentNode.parentNode;
var deteltSongNum=deletObj.dir;
deletObj.style.display="none";
//deletObj.style.background="#FF0000";
ExceptionNum.push(deteltSongNum);

}


function adRotation(){
var movieAds = new Array(
'<a href="http://click.linksynergy.com/fs-bin/click?id=UDNuzqKGkHE&offerid=186556.10000011&type=4&subid=0"><IMG alt="TSUTAYA online" border="0" src="http://www.tsutaya.co.jp/affiliate/bnr/dvd01_480_60.gif"></a><IMG border="0" width="1" height="1" src="http://ad.linksynergy.com/fs-bin/show?id=UDNuzqKGkHE&bids=186556.10000011&type=4&subid=0"><div><img src="http://www.tsutaya.co.jp/affiliate/image/search_h234.gif" alt="Shop.TOL" width="234" height="55" border="0"></div><form action="http://click.linksynergy.com/fs-bin/statform" method="get" style="margin:0;"><input type=hidden name=id value=UDNuzqKGkHE><input type=hidden name=offerid value=186556><input type=hidden name=bnid value=1078><input type=hidden name="subid" value=""><table width="234" border="0" cellpadding="0" cellspacing="0" bgcolor="#F7F1D7" style="border-left:solid 1px #CDCDCD;border-right:solid 1px #CDCDCD;"><tr align="left"><td width="105" align="right" style="padding-left:7px;padding-top:8px;padding-bottom:8px;"><input type="hidden" name="encode" value="utf8"><input type="text" name="TXT_SEARCH" value="" maxlength="80" style="width:160px;"><input type="hidden" name="RBT_SELECT" value="0,0"><input type="hidden" name="VIEW_PAGE" value="1"><input type="hidden" name="REF" value="71"></td><td width="150" align="left" style="padding:8px 0px;"><input name="Submit"  type="image" src="http://www.tsutaya.co.jp/affiliate/image/search_sbmt.gif" alt="検索" value="検索" style="margin-left:5px;"></td></tr></table></form><div><img src="http://www.tsutaya.co.jp/affiliate/image/search_line1.gif" alt="" width="232" height="4" style="border-left:solid 1px #CDCDCD;border-right:solid 1px #CDCDCD;"></div><div><img src="http://www.tsutaya.co.jp/affiliate/image/search_b234.gif" alt="by TSUTAYA online" width="234" height="16" border="0"></div><IMG width=1 height=1 border=0 src="http://ad.linksynergy.com/fs-bin/show?id=UDNuzqKGkHE&bids=186556&type=5"><a href="http://click.linksynergy.com/fs-bin/click?id=UDNuzqKGkHE&offerid=94348.10001834&type=4&subid=0"><IMG alt=" iTunes Store（Japan）" border="0" src="http://ad.linkshare.ne.jp/13894/feature/iTunes-Rewind-2009_125x125.jpg"></a><IMG border="0" width="1" height="1" src="http://ad.linksynergy.com/fs-bin/show?id=UDNuzqKGkHE&bids=94348.10001834&type=4&subid=0">',
'<a href="http://click.linksynergy.com/fs-bin/click?id=UDNuzqKGkHE&offerid=138700.10000025&type=4&subid=0"><IMG alt="ユナイテッド・シネマ映画チケット＆会員登録アフィリエイト" border="0" src="http://www.unitedcinemas.jp/affiliate/image/banner/250-250banner_uc.gif"></a><IMG border="0" width="1" height="1" src="http://ad.linksynergy.com/fs-bin/show?id=UDNuzqKGkHE&bids=138700.10000025&type=4&subid=0">',
'<a href="http://click.linksynergy.com/fs-bin/click?id=UDNuzqKGkHE&offerid=138700.10000023&type=4&subid=0"><IMG alt="ユナイテッド・シネマ映画チケット＆会員登録アフィリエイト" border="0" src="http://www.unitedcinemas.jp/affiliate/image/banner/300-80.jpg"></a><IMG border="0" width="1" height="1" src="http://ad.linksynergy.com/fs-bin/show?id=UDNuzqKGkHE&bids=138700.10000023&type=4&subid=0">'
);
var rand = Math.floor( Math.random() * movieAds.length);

var showVideo=$("showVideo");
var movieAdBnr=document.createElement("div");
movieAdBnr.id="movieAdBnr";
movieAdBnr.innerHTML=movieAds[rand];
showVideo.appendChild(movieAdBnr);
}

function jumpArtistPage(){
	var pageURL=$("pickUp").value;
	if(pageURL!="NG"){
	location.href = pageURL;
	}
}
 
 
function moveArtistPage(){
	var artistSearch=$("artistSearch");
	if(artistSearch.value!=""){
		var jumpURL="/music/artist.php?artist="+encodeURI(artistSearch.value);
		location.href = jumpURL;
	}
	
}




function loadingImg(){
	var loadingTxt =$("loadingTxt");
	loadingTxt.style.display="block";
}


function popUpIntroRewrite(){
	var introAmeba=$("introAmeba");
	var pasteBlogSrc=$("pasteBlogSrc");
	introAmeba.href="http://blog.ameba.jp/ucs/entry/srventryinsertinput.do?entry_text="+encodeURI(pasteBlogSrc.innerHTML);
	var otherSrc=$("otherSrc");
	otherSrc.value=pasteBlogSrc.innerHTML;
}

function popUpIntro(){
	var introAmeba=$("introAmeba");
	var pasteBlogSrc=$("pasteBlogSrc");
	var otherSrc=$("otherSrc");
	otherSrc.value=pasteBlogSrc.innerHTML;
	
	introAmeba.href="http://blog.ameba.jp/ucs/entry/srventryinsertinput.do?entry_text="+encodeURI(pasteBlogSrc.innerHTML);

	var pos=$("showPopUpForPaste").getPosition();
	var popUpBlogSrc=$("popUpBlogSrc");
	
	popUpBlogSrc.setStyles({
    display: 'block',
    position: 'absolute',
    top:pos.y+20,
	left:pos.x
});
}
function closePopUpIntro(el){
		var popUpBlogSrc=$("popUpBlogSrc");
	
	popUpBlogSrc.setStyles({
    display: 'none'

});
}


function otherBlog(){
	var otherSrc=$("otherSrc");
otherSrc.setStyles({
	display: 'block',
width:'300px',
fontSize:'0.8em',
height:'100px'
});
	setClipboard('otherSrc');
	
}


