/*------------------------------------------------------------------
[クラス名]:	common.js
[機能]:		全体の制御
[履歴]:		2010/12/08:v1.00
------------------------------------------------------------------*/
$(function() {

	// opening check
	/*
	var opening = $.cookie("opening");
	if (opening != "1") {
		$.cookie("opening", "1");
		window.location.href = "/scarface.html";
	}
	*/

	// scarface icon
	scarfaceIcon();

	// blank window
	$(".blank a").bind("click", windowOpen);

	// history back
	$(".back a").bind("click", historyBack);
	$(".button .edit a").bind("click", historyBack);

	// pageup	
	$("#pageup a").bind("click", pageupHandler);
	
});


/*------------------------------------------------------------------
[機能]:		HOMEイメージのフェード
[履歴]:		2010/12/08:v1.00
------------------------------------------------------------------*/

/* cover initialize
----------------------------------------------- */
function coverInitialize() {	
	$("#cover img").hide();
	$(window).bind("load", coverOpen);
}

/* cover open
----------------------------------------------- */
function coverOpen() {
	$("#cover img").show();
	$("#cover img").css({ opacity:0 });
	$("#cover img").delay(500).animate({ opacity:1 }, 1000, "easeInOutCirc");
}



/*------------------------------------------------------------------
[機能]:		Scaface Flashの表示
[履歴]:		2010/12/08:v1.00
------------------------------------------------------------------*/
var scarface_flashvars;
var scarface_params;
var scarface_attributes;

/* scarface icon
----------------------------------------------- */
function scarfaceIcon() {
	scarface_params = { menu:"false", bgcolor:"#000000" };
	swfobject.embedSWF("/common/icon.swf", "scarface_icon", "40", "80", "10.0.0", "", scarface_flashvars, scarface_params, scarface_attributes);
}

/* scarface opening
----------------------------------------------- */
function scarfaceOpening() {	
	scarface_params = { menu:"false", bgcolor:"#000000" };
	swfobject.embedSWF("/common/opening.swf", "opening", "900", "500", "10.0.0", "", scarface_flashvars, scarface_params, scarface_attributes);
}



/*------------------------------------------------------------------
[機能]:		LOOK イメージのページング
[履歴]:		2010/12/09:v1.00
------------------------------------------------------------------*/
var look_num = 0;
var look_count = 0;
var look_page = 0;
var look_pages = 0;
var look_flag = 0;

/* look initialize
----------------------------------------------- */
function lookInitialize() {	
	$("#image li").hide();
	$(window).bind("load", lookLoad);
}

/* look load
----------------------------------------------- */
function lookLoad() {

	$(window).unbind("load", lookLoad);

	var i;
	var hash = window.location.hash;

	look_num = $("#image li").length;
	look_pages = look_num;

	if (hash != "") {
		look_page = hash.replace("#", "") - 1;
	}

	$("#pager .previous").bind("click", lookPrevious);
	$("#pager .next").bind("click", lookNext);
	$("#image a").bind("click", lookNext);

	lookOpen();
}

/* look open
----------------------------------------------- */
function lookOpen() {

	var i;
	var htmls;
	var page_start;
	var page_end;

	look_flag = 1;

	/* ページセット */
	htmls = "";
	for (i = 0; i < look_pages; i++) {
		var num = i + 1;
		if (i == look_page) {
			htmls += '<li class="this"><a href="#' + num + '">' + num + '</a></li>';
		}
		else {
			htmls += '<li><a href="#' + num + '">' + num + '</a></li>';
		}
	}
	
	$("#pagenumber ul").html(htmls);	
	$("#pagenumber ul li a").bind("click", lookPage);

	/* イメージ一覧 */
	$("#image li").animate({ opacity:0 }, 250, "easeInCirc", function() {
		$("#image li").hide();
		$("#image li").eq(look_page).show();
		$("#image li").eq(look_page).css({ opacity:0 });
		$("#image li").eq(look_page).animate({ opacity:1 }, 250, "easeOutCirc", function() {
			look_flag = 0;
		});
	});
}

/* look page
----------------------------------------------- */
function lookPage() {
	if (look_flag == 0) {
		look_page = $(this).text() - 1;
		lookOpen();
	}
}

/* look previous
----------------------------------------------- */
function lookPrevious() {
	if (look_flag == 0) {

		var num;
		
		look_page--;
		if (look_page < 0) {
			look_page = look_pages - 1;
		}
		num = look_page + 1;
		window.location.href = "#" + num;
	
		lookOpen();
	}
	return false;
}

/* look next
----------------------------------------------- */
function lookNext() {
	if (look_flag == 0) {

		var num;
		
		look_page++;
		if (look_page >= look_pages) {
			look_page = 0;
		}
		num = look_page + 1;
		window.location.href = "#" + num;
	
		lookOpen();
		return false;
	}
}



/*------------------------------------------------------------------
[機能]:		ITEM 一覧のページング
[履歴]:		2010/12/08:v1.00
------------------------------------------------------------------*/
var items_num = 0;
var items_page = 0;
var items_pages = 0;
var items_max = 12;

/* items initialize
----------------------------------------------- */
function itemsInitialize() {
	$("#items .item").hide();
	$(window).bind("load", itemsLoad);
}

/* items load
----------------------------------------------- */
function itemsLoad() {

	$(window).unbind("load", itemsLoad);

	var i;
	var hash = window.location.hash;

	items_num = $("#items .item").length;
	items_pages = Math.floor(items_num / items_max + 0.99);

	if (hash != "") {
		items_page = hash.replace("#", "") - 1;
	}

	for (i = 0; i < items_num; i++) {
		$("#items .item").eq(i).append('<p class="mask"></p>');
	}

	$("#pager .previous").bind("click", itemsPrevious);
	$("#pager .next").bind("click", itemsNext);

	itemsOpen();
}

/* items open
----------------------------------------------- */
function itemsOpen() {

	var i;
	var htmls;
	var page_start;
	var page_end;
	
	/* ページセット */
	htmls = "";
	for (i = 0; i < items_pages; i++) {
		var num = i + 1;
		if (i == items_page) {
			htmls += '<li class="this"><a href="#' + num + '">' + num + '</a></li>';
		}
		else {
			htmls += '<li><a href="#' + num + '">' + num + '</a></li>';
		}
	}
	
	$("#pagenumber ul").html(htmls);	
	$("#pagenumber ul li a").bind("click", itemsPage);

	/* アイテム一覧 */
	page_start = items_page * items_max;
	page_end = page_start + items_max;
	if (page_end > items_num) {
		page_end = items_num;
	}

	$("#items .item").hide();
	for (i = page_start; i < page_end; i++) {
		$("#items .item").eq(i).show();
	}

	$("#items").stop();
	$("#items").css({ opacity:0 });
	$("#items").delay(500).animate({ opacity:1 }, 1000);
	$("#items .item").bind("click", itemsDetail);
	$("#items .item").hover(itemsMaskOver, itemsMaskOut);
}

/* items page
----------------------------------------------- */
function itemsPage() {
	items_page = $(this).text() - 1;
	itemsOpen();
}

/* items previous
----------------------------------------------- */
function itemsPrevious() {

	var num;
	
	items_page--;
	if (items_page < 0) {
		items_page = items_pages - 1;
	}
	num = items_page + 1;
	window.location.href = "#" + num;

	itemsOpen();
	return false;
}

/* items next
----------------------------------------------- */
function itemsNext() {

	var num;
	
	items_page++;
	if (items_page >= items_pages) {
		items_page = 0;
	}
	num = items_page + 1;
	window.location.href = "#" + num;

	itemsOpen();
	return false;
}

/* items detail
----------------------------------------------- */
function itemsDetail() {
	var url = $("a", this).attr("href");
	window.location.href = url;
}

/* items mask over
----------------------------------------------- */
function itemsMaskOver() {
	$(".mask", this).stop();
	$(".mask", this).animate({ opacity:0 }, 500);
}

/* items mask out
----------------------------------------------- */
function itemsMaskOut() {

	var ua = navigator.userAgent.toLowerCase();

	$(".mask", this).stop();
	if (ua.indexOf("msie") == -1) {
		$(".mask", this).animate({ opacity:1 }, 500);
	}
	else {
		$(".mask", this).animate({ opacity:0.8 }, 500);
	}
}



/*------------------------------------------------------------------
[機能]:		ITEM イメージプレビュー
[履歴]:		2010/12/08:v1.00
------------------------------------------------------------------*/
var item_num = 0;

/* item initialize
----------------------------------------------- */
function thumbnailInitialize() {

	//$("#info").hide();

	//$(window).bind("load", itemLoad);
	
	item_num = $("#image li").length;

	$("#image ul").width(415*item_num);
	$("#thumbnail li a").eq(0).css({ opacity:0.7 });
	$("#thumbnail li a").bind("click", thumbnailClick);
}

/* item load
----------------------------------------------- */
function itemLoad() {

	$(window).unbind("load", itemLoad);
	
	$("#info").show();
	$("#info").css({ opacity:0 });
	$("#info").delay(500).animate({ opacity:0.5 }, 500);
	$("#info").hover(itemInfoOver, itemInfoOut);
}

function itemInfoOver() {
	$("#info").stop();
	$("#info").animate({ opacity:1 }, 250);
}

function itemInfoOut() {
	$("#info").stop();
	$("#info").animate({ opacity:0.5 }, 500);
}

/* thumbnail click
----------------------------------------------- */
function thumbnailClick() {

	var num = $("#thumbnail li a").index(this);
	var move = 415 * num * -1;

	$("#thumbnail li a").css({ opacity:1 });
	$(this).css({ opacity:0.7 });

	$("#image ul").stop();
	$("#image ul").animate({ left:move }, 1000, "easeInOutQuart");
	
	return false;
}



/*------------------------------------------------------------------
[機能]:		CLIP 一覧のページング
[履歴]:		2010/12/21:v1.00
------------------------------------------------------------------*/
var clip_num = 0;
var clip_page = 0;
var clip_pages = 0;
var clip_max = 6;

/* clips initialize
----------------------------------------------- */
function clipInitialize() {
	$("#movies .movie").hide();
	$(window).bind("load", clipLoad);
}

/* clip load
----------------------------------------------- */
function clipLoad() {

	$(window).unbind("load", clipLoad);

	var i;
	var hash = window.location.hash;

	clip_num = $("#movies .movie").length;
	clip_pages = Math.floor(clip_num / clip_max + 0.99);

	if (hash != "") {
		clip_page = hash.replace("#", "") - 1;
	}

	$("#pager .previous").bind("click", clipPrevious);
	$("#pager .next").bind("click", clipNext);

	clipOpen();
}

/* clip open
----------------------------------------------- */
function clipOpen() {

	var i;
	var htmls;
	var page_start;
	var page_end;
	
	/* ページセット */
	htmls = "";
	for (i = 0; i < clip_pages; i++) {
		var num = i + 1;
		if (i == clip_page) {
			htmls += '<li class="this"><a href="#' + num + '">' + num + '</a></li>';
		}
		else {
			htmls += '<li><a href="#' + num + '">' + num + '</a></li>';
		}
	}
	
	$("#pagenumber ul").html(htmls);	
	$("#pagenumber ul li a").bind("click", clipPage);

	/* アイテム一覧 */
	page_start = clip_page * clip_max;
	page_end = page_start + clip_max;
	if (page_end > clip_num) {
		page_end = clip_num;
	}

	$("#movies .movie").hide();
	for (i = page_start; i < page_end; i++) {
		$("#movies .movie").eq(i).show();
	}

	$("#movies").stop();
	/*
	$("#movies").css({ opacity:0 });
	$("#movies").delay(500).animate({ opacity:1 }, 1000);
	*/
	$("#movies .movie").bind("click", clipDetail);
	//$("#movies .movie").hover(clipMaskOver, clipMaskOut);
}

/* clip page
----------------------------------------------- */
function clipPage() {
	clip_page = $(this).text() - 1;
	clipOpen();
}

/* clip previous
----------------------------------------------- */
function clipPrevious() {

	var num;
	
	clip_page--;
	if (clip_page < 0) {
		clip_page = clip_pages - 1;
	}
	num = clip_page + 1;
	window.location.href = "#" + num;

	clipOpen();
	return false;
}

/* clip next
----------------------------------------------- */
function clipNext() {

	var num;
	
	clip_page++;
	if (clip_page >= clip_pages) {
		clip_page = 0;
	}
	num = clip_page + 1;
	window.location.href = "#" + num;

	clipOpen();
	return false;
}



/*------------------------------------------------------------------
[機能]:		サブウィンドウ
[履歴]:		2010/12/08:v1.00
------------------------------------------------------------------*/
function windowOpen() {
	var url = $(this).attr("href");
	var w = window.open(url);
	w.focus();
	return false;
}



/*------------------------------------------------------------------
[機能]:		ヒストリーバック
[履歴]:		2010/12/08:v1.00
------------------------------------------------------------------*/
function historyBack() {
	history.back();
	return false;
}



/*------------------------------------------------------------------
[機能]:		ページアップ
[履歴]:		2010/12/08:v1.00
------------------------------------------------------------------*/
function pageupHandler() {
	var time = $(window).height() / 1000;
	$("html, body").animate({scrollTop: 0}, 1000 * time, "easeInOutQuint");
	return false;
}

