
var movie_view_current_number = 1;
var movie_current_category = "all";


$(function(){
	var url_hash = location.hash;
	if ( url_hash == "#menu" ) movie_area_hide();
	else movie_area_show();
});


// 動画エリア表示
function movie_area_show()
{
	location.hash = "";
	
	$("#container").fadeOut("normal", function(){
		$("#movie_area").fadeIn("normal");
	});
	return false;
}

// 動画エリア非表示
function movie_area_hide()
{
	//var url = location.href.split("#");
	//location.href = url[0];
	location.hash = "menu";

	$("#movie_area").fadeOut("normal", function(){
		$("#container").fadeIn("normal");
	});
	return false;
}

// 動画カテゴリ変更
function changeMovieCategory( category )
{
	movie_current_category = category;
	
	var c = movies[category]["movie_id"].length;
	var html = "";
	
	$("#movie_list_ul").html("");
	
	for ( var i = 1; i <= c; i++ ) {
		html += '<li class="movie_list_box" id="movie_list_box' + i + '">' +
				'	<a href="#" onclick="changeMovie(\'' + movies[category]["movie_id"][i-1] + '\');return false;">' +
				'	<img src="' + movies[category]["image"][i-1] + '" align="left" width="70" />' +
				'	<p class="m_title">' + movies[category]["title_s"][i-1] + '</p>' +
				'	<p class="m_description">' + movies[category]["description_s"][i-1] + '</p>' +
				'	</a>' +
				'</li>';
	}
	$("#movie_list_ul").html( html );

	return false;
}

// 動画一覧 次へ
function nextMovieList()
{
	var max_count = movies[movie_current_category]["image"].length;
	
	if ( movie_view_current_number + 3 >= max_count ) return false;
	
	$("li.movie_list_box").css( "display", "none" );
	
	for ( var i = movie_view_current_number + 4; i < 8 + movie_view_current_number; i++ ) {
		$("#movie_list_box"+i).css( "display", "block" );
	}
	movie_view_current_number = movie_view_current_number + 4;
	
	return false;
}
// 動画一覧 前へ
function prevMovieList()
{
	var max_count = movies[movie_current_category]["image"].length;

	if ( movie_view_current_number <= 1 ) return false;
	
	$("li.movie_list_box").css( "display", "none" );
	
	for ( var i = movie_view_current_number - 4; i < movie_view_current_number; i++ ) {
		$("#movie_list_box"+i).css( "display", "block" );
	}
	movie_view_current_number = movie_view_current_number - 4;
}

// 動画変更
function changeMovie( mid )
{
	var before_url = $("#youtube_movie embed").attr("src");
	var after_url = before_url.replace(/\/v\/.+?\&/, "/v/"+mid+"&");
	
	$("#youtube_movie embed").attr("src", after_url);
	$("#youtube_movie param:eq(0)").attr("value", after_url);
	
	$("#youtube_movie").html( $("#youtube_movie").html() );

	//alert($("#youtube_movie param:eq(0)").attr("value"))
	return false;
}


