var currentList = "";
var currentNavi = "";

$(function(){
	// searchBox TextArea defaultText
	$("#searchText")
		.focus(function() {
			if ($(this).val()=="検索ワードを入力してください") { $(this).val("") }
		})
		.blur(function() {
			if ($(this).val()=="") { $(this).val("検索ワードを入力してください") }
		});
		
	// globalNavigation rollOver
	$("dt#navi01").mouseover(function(){
		$(this).children("a").css("background","url(/images/common/globalNavigation_naviImages.gif) no-repeat 0 -34px");
	}).mouseout(function(){
		if ( currentNavi != "dt#navi01" ) $(this).children("a").css("background","url(/images/common/globalNavigation_naviImages.gif) no-repeat 0 0");
	});
	$("dt#navi02").mouseover(function(){
		$(this).children("a").css("background","url(/images/common/globalNavigation_naviImages.gif) no-repeat -128px -34px");
	}).mouseout(function(){
		if ( currentNavi != "dt#navi02" ) $(this).children("a").css("background","url(/images/common/globalNavigation_naviImages.gif) no-repeat -128px 0");
	});
	$("dt#navi03").mouseover(function(){
		$(this).children("a").css("background","url(/images/common/globalNavigation_naviImages.gif) no-repeat -256px -34px");
	}).mouseout(function(){
		if ( currentNavi != "dt#navi03" ) $(this).children("a").css("background","url(/images/common/globalNavigation_naviImages.gif) no-repeat -256px 0");
	});
	$("dt#navi04").mouseover(function(){
		$(this).children("a").css("background","url(/images/common/globalNavigation_naviImages.gif) no-repeat -384px -34px");
	}).mouseout(function(){
		if ( currentNavi != "dt#navi04" ) $(this).children("a").css("background","url(/images/common/globalNavigation_naviImages.gif) no-repeat -384px 0");
	});
	$("dt#navi05").mouseover(function(){
		$(this).children("a").css("background","url(/images/common/globalNavigation_naviImages.gif) no-repeat -512px -34px");
	}).mouseout(function(){
		if ( currentNavi != "dt#navi05" ) $(this).children("a").css("background","url(/images/common/globalNavigation_naviImages.gif) no-repeat -512px 0");
	});
	$("dt#navi06").mouseover(function(){
		$(this).children("a").css("background","url(/images/common/globalNavigation_naviImages.gif) no-repeat -640px -34px");
	}).mouseout(function(){
		if ( currentNavi != "dt#navi06" ) $(this).children("a").css("background","url(/images/common/globalNavigation_naviImages.gif) no-repeat -640px 0");
	});
	$("dt#navi07").mouseover(function(){
		$(this).children("a").css("background","url(/images/common/globalNavigation_naviImages.gif) no-repeat -768px -34px");
	}).mouseout(function(){
		if ( currentNavi != "dt#navi07" ) $(this).children("a").css("background","url(/images/common/globalNavigation_naviImages.gif) no-repeat -768px 0");
	});
	$("#globalNavigation dt").mouseover(function(){
		$(this).children("ul").css("display","block");
	}).mouseout(function(){
		$(this).children("ul").css("display","none");
	});
	
	// newReleaseTab
	$("li#newReleaseTab01").click(function() {
		resetNewReleaseTabs();
		$(this).children("a").css("background","url(/images/index/newRelease_btn_tabImages.gif) no-repeat 0 -27px");
		$('#newReleaseData').load("/templates/release/japanese.tmpl");
	});
	$("li#newReleaseTab02").click(function() {
		resetNewReleaseTabs();
		$(this).children("a").css("background","url(/images/index/newRelease_btn_tabImages.gif) no-repeat -151px -27px");
		$('#newReleaseData').load("/templates/release/english.tmpl");
	});
	$("li#newReleaseTab03").click(function() {
		resetNewReleaseTabs();
		$(this).children("a").css("background","url(/images/index/newRelease_btn_tabImages.gif) no-repeat -302px -27px");
		$('#newReleaseData').load("/templates/release/classic.tmpl");
	});
	$("li#newReleaseTab04").click(function() {
		resetNewReleaseTabs();
		$(this).children("a").css("background","url(/images/index/newRelease_btn_tabImages.gif) no-repeat -453px -27px");
		$('#newReleaseData').load("/templates/release/jazz.tmpl");
	});
	$("li#newReleaseTab05").click(function() {
		resetNewReleaseTabs();
		$(this).children("a").css("background","url(/images/index/newRelease_btn_tabImages.gif) no-repeat -604px -27px");
		$('#newReleaseData').load("/templates/release/compi.tmpl");
	});
	$("li#newReleaseTab06").click(function() {
		resetNewReleaseTabs();
		$(this).children("a").css("background","url(/images/index/newRelease_btn_tabImages.gif) no-repeat -755px -27px");
		$('#newReleaseData').load("/templates/release/etc.tmpl");
	});
	
	// latestVideoTabs
	$("li#latestVideoTab01").click(function() {
		resetLatestVideoTabs();
		$(this).children("a").css("background","url(/images/index/latestVideo_btn_tabImages.gif) no-repeat 0 -27px");
		$('#latestVideoData').load("/templates/movie/feature.tmpl");
	});
	$("li#latestVideoTab02").click(function() {
		resetLatestVideoTabs();
		$(this).children("a").css("background","url(/images/index/latestVideo_btn_tabImages.gif) no-repeat -99px -27px");
		$('#latestVideoData').load("/templates/movie/japanese.tmpl");
	});
	$("li#latestVideoTab03").click(function() {
		resetLatestVideoTabs();
		$(this).children("a").css("background","url(/images/index/latestVideo_btn_tabImages.gif) no-repeat -198px -27px");
		$('#latestVideoData').load("/templates/movie/english.tmpl");
	});
	$("li#latestVideoTab04").click(function() {
		resetLatestVideoTabs();
		$(this).children("a").css("background","url(/images/index/latestVideo_btn_tabImages.gif) no-repeat -297px -27px");
		$('#latestVideoData').load("/templates/movie/classic.tmpl");
	});
	$("li#latestVideoTab05").click(function() {
		resetLatestVideoTabs();
		$(this).children("a").css("background","url(/images/index/latestVideo_btn_tabImages.gif) no-repeat -396px -27px");
		$('#latestVideoData').load("/templates/movie/jazz.tmpl");
	});
	$("li#latestVideoTab06").click(function() {
		resetLatestVideoTabs();
		$(this).children("a").css("background","url(/images/index/latestVideo_btn_tabImages.gif) no-repeat -495px -27px");
		$('#latestVideoData').load("/templates/movie/etc.tmpl");
	});
	
	// listenButton
	$("img.listen").click(function() {
		// hidden watchListBox
		$("div#watchListBox").css("display", "none");
		// reset listenButton,watchButton
		resetButtons();
		// set thisButton Active
		$(this).attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"));
		//
		var listLocationX = Math.round($(this).offset().left);
		var listLocationY = Math.round($(this).offset().top);
		currentList = "div#listenListBox";
		// visible listenListBox
		$("div#listenListBox").css("display", "block");
		$("table#listenTable").html(listen_ids[$(this).attr("id")]);
		//
		setListPosition(listLocationX, listLocationY);
	});
	
	// watchButton
	$("img.watch").click(function() {
		// hidden listenListBox
		$("div#listenListBox").css("display", "none");
		// reset listenButton,watchButton
		resetButtons();
		// set thisButton Active
		$(this).attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"));
		//
		var listLocationX = Math.round($(this).offset().left);
		var listLocationY = Math.round($(this).offset().top);
		listLocationX -= 55;
		currentList = "div#watchListBox";
		// visible watchListBox
		$("div#watchListBox").css("display", "block");
		$("table#watchTable").html(listen_ids[$(this).attr("id")]);
		//
		setListPosition(listLocationX, listLocationY);
	});
	
	// workListCloseButton
	$("p.closeBtn").click(function() {
		$("div#listenListBox").css("display", "none");
		$("div#watchListBox").css("display", "none");
		try { $("img.listen").attr("src",$("img.listen").attr("src").replace(/^(.+)_on(\.[a-z]+)$/, "$1$2")); } catch(e){}
		try { $("img.watch").attr("src",$("img.watch").attr("src").replace(/^(.+)_on(\.[a-z]+)$/, "$1$2")); } catch(e){}
	});
	
	// atFirst
//	$("li#newReleaseTab01").children("a").css("background","url(/images/index/newRelease_btn_tabImages.gif) no-repeat 0 -27px");
//	$("li#latestVideoTab01").children("a").css("background","url(/images/index/latestVideo_btn_tabImages.gif) no-repeat 0 -27px");
})

// linksOutline
function disable_links_outline() {
　　var blur = function () { this.blur() };
　　for (var i = 0; i < document.links.length; i++) {
　　　　document.links[i].onfocus = blur;
	}
}

// setListPosition
function setListPosition(listLocationX, listLocationY) {
	var value = (($(window).width() - $("div#container").width())/2);
	if (0 < value) {
		listLocationX = listLocationX - (($(window).width() - $("div#container").width())/2);
	} else {
		listLocationX;
	}
	listLocationY = listLocationY + 17;
	$(currentList).css("left",listLocationX);
	$(currentList).css("top",listLocationY);
}

// reset newReleaseTab
function resetNewReleaseTabs() {
	resetMusicList();
	$("li#newReleaseTab01").children("a").css("background","url(/images/index/newRelease_btn_tabImages.gif) no-repeat 0 0");
	$("li#newReleaseTab02").children("a").css("background","url(/images/index/newRelease_btn_tabImages.gif) no-repeat -151px 0");
	$("li#newReleaseTab03").children("a").css("background","url(/images/index/newRelease_btn_tabImages.gif) no-repeat -302px 0");
	$("li#newReleaseTab04").children("a").css("background","url(/images/index/newRelease_btn_tabImages.gif) no-repeat -453px 0");
	$("li#newReleaseTab05").children("a").css("background","url(/images/index/newRelease_btn_tabImages.gif) no-repeat -604px 0");
	$("li#newReleaseTab06").children("a").css("background","url(/images/index/newRelease_btn_tabImages.gif) no-repeat -755px 0");
}

// reset latestVideoTabs
function resetLatestVideoTabs() {
	$("li#latestVideoTab01").children("a").css("background","url(/images/index/latestVideo_btn_tabImages.gif) no-repeat 0 0");
	$("li#latestVideoTab02").children("a").css("background","url(/images/index/latestVideo_btn_tabImages.gif) no-repeat -99px 0");
	$("li#latestVideoTab03").children("a").css("background","url(/images/index/latestVideo_btn_tabImages.gif) no-repeat -198px 0");
	$("li#latestVideoTab04").children("a").css("background","url(/images/index/latestVideo_btn_tabImages.gif) no-repeat -297px 0");
	$("li#latestVideoTab05").children("a").css("background","url(/images/index/latestVideo_btn_tabImages.gif) no-repeat -396px 0");
	$("li#latestVideoTab06").children("a").css("background","url(/images/index/latestVideo_btn_tabImages.gif) no-repeat -495px 0");
}

// reset listenButton,watchButton
function resetButtons() {
	try { $("img.listen").attr("src",$("img.listen").attr("src").replace(/^(.+)_on(\.[a-z]+)$/, "$1$2")); }catch(e){}
	try { $("img.watch").attr("src",$("img.watch").attr("src").replace(/^(.+)_on(\.[a-z]+)$/, "$1$2")); }catch(e){}
}

function resetMusicList() {
	$("div#watchListBox").css("display", "none");
	$("div#listenListBox").css("display", "none");
}

function initRandTopTabs(w,id,w2,id2) {
	$("li#"+id).children("a").css("background","url(/images/index/newRelease_btn_tabImages.gif) no-repeat " + w + "px -27px");
	$("li#"+id2).children("a").css("background","url(/images/index/latestVideo_btn_tabImages.gif) no-repeat " + w2 + "px -27px");
}

function setCurrentNavi( navi ) {
	currentNavi = navi;
	$(navi).children("a").addClass("current");
}

function winOpen($url,$win_name,$height,$width,$l,$t,$status,$toolbar,$menubar,$location,$scrollbars,$resizable) {
	var $status='height='+$height+',width='+$width+',status='+$status+',toolbar='+$toolbar+',menubar='+$menubar+',location='+$location+',resizable='+$resizable+',scrollbars='+$scrollbars+',screenX='+$l+',screenY='+$l+',left='+$l+',top='+$l;
	window.open($url,$win_name,$status);
}

function set_volume( vol ) {
	
    kigen = new Date();
    kigen.setTime( kigen.getTime() + ( 365 * 1000 * 60 * 60 * 24 ) );
    kigen2 = kigen.toGMTString();
　　document.cookie = "volume=" + vol + ";expires=" + kigen2;
	
}

function set_mute( vol ) {
	
    kigen = new Date();
    kigen.setTime( kigen.getTime() + ( 365 * 1000 * 60 * 60 * 24 ) );
    kigen2 = kigen.toGMTString();
　　document.cookie = "mute=" + vol + ";expires=" + kigen2;
	
}

function GetShuffle( arr ){
    var copy = new Array();
    for( var i=0; i<arr.length; i++ ) copy[i] = arr[i]; //配列の複製
    Shuffle( copy );
    return copy;
}

function Shuffle( arr ){
    for( var i=0; i<arr.length; i++ ){
        var backup = arr[i];
        var rand = Math.floor( Math.random() * arr.length );
        arr[i] = arr[rand];
        arr[rand] = backup;
    }
}

function writeFlashHTML
( 
  /**
   * 引数
   */
   
     _swf      // フラッシュのURL
    ,_quality  // 画質
    ,_loop     // 繰り返し
    ,_bgcolor  // 背景色
    ,_wmode    // 背景透明(WinIEのみ)
    ,_play     // 自動再生
    ,_menu     // 右クリックメニュー
    ,_scale    // 幅高さが%の時の縦横比等
    ,_salign   // 表示領域内表示位置
    ,_height   // ムービーの高さ
    ,_width    // ムービーの幅
    ,_hspace   // まわりの余白(水平方向)
    ,_vspace   // まわりの余白(垂直方向)
    ,_align    // 表示位置
    ,_class    // クラス
    ,_id       // ID名
    ,_name     // ムービー名
    ,_style    // スタイル
    ,_declare  // 読み込まれるだけで実行しない

)
{
  /**
   * スクリプト
   */

  // タグ用文字列生成
  var htm = ""
  
  htm+="<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'"
  htm+="        codebase='http://download.macromedia.com/pub/shockwave/"
                    htm+="cabs/flash/swflash.cab'"
  htm+="        width    = '" + _width   + "'"
  htm+="        height   = '" + _height  + "'"
  htm+="        hspace   = '" + _hspace  + "'"
  htm+="        vspace   = '" + _vspace  + "'"
  htm+="        align    = '" + _align   + "'"
  htm+="        class    = '" + _class   + "'"
  htm+="        id       = '" + _id      + "'"
  htm+="        name     = '" + _name    + "'"
  htm+="        style    = '" + _style   + "'"
  htm+="                    " + _declare  
  htm+="        >"
  htm+="<param  name     = 'movie'   value ='" + _swf     + "'>"
  htm+="<param  name     = 'quality' value ='" + _quality + "'>"
  htm+="<param  name     = 'loop'    value ='" + _loop    + "'>"
  htm+="<param  name     = 'bgcolor' value ='" + _bgcolor + "'>"
  htm+="<param  name     = 'play'    value ='" + _play    + "'>"
  htm+="<param  name     = 'menu'    value ='" + _menu    + "'>"
  htm+="<param  name     = 'scale'   value ='" + _scale   + "'>"
  htm+="<param  name     = 'salign'  value ='" + _salign  + "'>"
  htm+="<param  name     = 'wmode'   value ='" + _wmode   + "'>"
  htm+=""
  htm+="<embed                          "
  htm+="        pluginspage='http://www.macromedia.com/go/getflashplayer'"
  htm+="        width    = '" + _width   + "'"
  htm+="        height   = '" + _height  + "'"
  htm+="        hspace   = '" + _hspace  + "'"
  htm+="        vspace   = '" + _vspace  + "'"
  htm+="        align    = '" + _align   + "'"
  htm+="        class    = '" + _class   + "'"
  htm+="        id       = '" + _id      + "'"
  htm+="        name     = '" + _name    + "'"
  htm+="        style    = '" + _style   + "'"
  htm+="        type     = 'application/x-shockwave-flash' "
  htm+="                    " + _declare  
  htm+="        src      = '" + _swf     + "'"
  htm+="        quality  = '" + _quality + "'"
  htm+="        loop     = '" + _loop    + "'"
  htm+="        bgcolor  = '" + _bgcolor + "'"
  htm+="        play     = '" + _play    + "'"
  htm+="        menu     = '" + _menu    + "'"
  htm+="        scale    = '" + _scale   + "'"
  htm+="        salign   = '" + _salign  + "'"
  htm+="        wmode    = '" + _wmode  + "'"
  htm+="></embed>"
  htm+="</object>"

  //書き出し処理
  document.write(htm)
}

function writeFlashHtmlParam
( 
  /**
   * 引数
   */
   
     _swf      // フラッシュのURL
    ,_quality  // 画質
    ,_loop     // 繰り返し
    ,_bgcolor  // 背景色
    ,_wmode    // 背景透明(WinIEのみ)
    ,_play     // 自動再生
    ,_menu     // 右クリックメニュー
    ,_scale    // 幅高さが%の時の縦横比等
    ,_salign   // 表示領域内表示位置
    ,_height   // ムービーの高さ
    ,_width    // ムービーの幅
    ,_hspace   // まわりの余白(水平方向)
    ,_vspace   // まわりの余白(垂直方向)
    ,_align    // 表示位置
    ,_class    // クラス
    ,_id       // ID名
    ,_name     // ムービー名
    ,_style    // スタイル
    ,_declare  // 読み込まれるだけで実行しない
    ,_flashvars  // 変数

)
{
  /**
   * スクリプト
   */

  // タグ用文字列生成
  var htm = ""
  
  htm+="<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'"
  htm+="        codebase='http://download.macromedia.com/pub/shockwave/"
                    htm+="cabs/flash/swflash.cab'"
  htm+="        width    = '" + _width   + "'"
  htm+="        height   = '" + _height  + "'"
  htm+="        hspace   = '" + _hspace  + "'"
  htm+="        vspace   = '" + _vspace  + "'"
  htm+="        align    = '" + _align   + "'"
  htm+="        class    = '" + _class   + "'"
  htm+="        id       = '" + _id      + "'"
  htm+="        name     = '" + _name    + "'"
  htm+="        style    = '" + _style   + "'"
  htm+="        flashvars    = '" + _flashvars   + "'"
  htm+="                    " + _declare  
  htm+="        >"
  htm+="<param  name     = 'movie'   value ='" + _swf     + "'>"
  htm+="<param  name     = 'quality' value ='" + _quality + "'>"
  htm+="<param  name     = 'loop'    value ='" + _loop    + "'>"
  htm+="<param  name     = 'bgcolor' value ='" + _bgcolor + "'>"
  htm+="<param  name     = 'play'    value ='" + _play    + "'>"
  htm+="<param  name     = 'menu'    value ='" + _menu    + "'>"
  htm+="<param  name     = 'scale'   value ='" + _scale   + "'>"
  htm+="<param  name     = 'salign'  value ='" + _salign  + "'>"
  htm+="<param  name     = 'wmode'   value ='" + _wmode   + "'>"
  htm+=""
  htm+="<embed                          "
  htm+="        pluginspage='http://www.macromedia.com/go/getflashplayer'"
  htm+="        width    = '" + _width   + "'"
  htm+="        height   = '" + _height  + "'"
  htm+="        hspace   = '" + _hspace  + "'"
  htm+="        vspace   = '" + _vspace  + "'"
  htm+="        align    = '" + _align   + "'"
  htm+="        class    = '" + _class   + "'"
  htm+="        id       = '" + _id      + "'"
  htm+="        name     = '" + _name    + "'"
  htm+="        style    = '" + _style   + "'"
  htm+="        flashvars   = '" + _flashvars  + "'"
  htm+="        type     = 'application/x-shockwave-flash' "
  htm+="                    " + _declare  
  htm+="        src      = '" + _swf     + "'"
  htm+="        quality  = '" + _quality + "'"
  htm+="        loop     = '" + _loop    + "'"
  htm+="        bgcolor  = '" + _bgcolor + "'"
  htm+="        play     = '" + _play    + "'"
  htm+="        menu     = '" + _menu    + "'"
  htm+="        scale    = '" + _scale   + "'"
  htm+="        salign   = '" + _salign  + "'"
  htm+="        wmode    = '" + _wmode  + "'"
  htm+="></embed>"
  htm+="</object>"

  //書き出し処理
  document.write(htm)
}

//PlayerWindow add L 2010.06.10->2010.06.16
function openPlayer($id) {

	var $status='height=548,width=902,status=yes,toolbar=n,menubar=no,location=no,resizable=no,scrollbars=no,screenX=0,screenY=0,left=0,top=0';
	if(navigator.userAgent.indexOf("Chrome") != -1){ // 文字列に「Safari」が含まれている場合

		if(navigator.userAgent.indexOf("Windows") == -1){
			 $status='height=600,width=905,status=yes,toolbar=n,menubar=no,location=no,resizable=no,scrollbars=no,screenX=0,screenY=0,left=0,top=0';
		}
	}
	
	var $url = 'http://emimusic.jp/emitv/player/?bctid=' + $id;
	window.open($url,'emitv',$status);
}
