//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
//
//	初期設定
//
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
$("body").ready(function(ev){
	$('*[id*="img_list"]').css({"margin":"2px 2px 0 0", "display":"block", "float":"left", "width":"108px", "height":"108px"});
	$("#prapper").hide();
});


//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
//
//	カーソル表示
//
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
function OnImg(id){
	$("#img-"+id).show();
}


//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
//
//	カーソル非表示
//
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
function OffImg(id){
	$("#img-"+id).hide();
}


//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
//
//	拡大イメージ表示
//
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
function BgOn(img_src, cat, name, title, cnt, width, height){
	
	//ＢＧの設定
	$("#prapper").css({"z-index":"10", "background-image":"url(img/boxbg.jpg)", "background-position":"center center", "filter":"alpha(opacity=75)", "-moz-opacity":"0.75", "opacity":"0.75"}).show();

	//ウインドウサイズの中心を求める
	wbody = $("body").width() >> 1;
	hbody = $("body").height() >> 1;

	//ボディ内にイメージボックスを作る
	$("body").prepend('<div id="img_box"></div>');

	//次と前の絵を見るスイッチを配置
	var pre = cnt;	pre--;
	var nxt = cnt;	nxt++;
	prev_door = $('#img-' + pre).attr("name");//イメージのnameの中にデータが仕込まれている
	backing = '<img src="Showcase/back_off.gif" id="backer" />';
	if(prev_door){
		backing = '<img src="Showcase/back_on.gif" id="backer" style="cursor:pointer;" onclick="PrevNext(prev_door);" />';
		$("#backer").attr({"onclick": prev_door});
		$("#backer").css('cursor','pointer');
	}

	next_door = $('#img-' + nxt).attr("name");
	nexting = '<img src="Showcase/next_off.gif" id="nexter" />';
	if(next_door){
		nexting = '<img src="Showcase/next_on.gif" id="nexter" style="cursor:pointer;" onclick="PrevNext(next_door);"/>';
		$("#nexter").attr({"onclick": next_door});
	}

	//イメージＢＯＸの設定
	$("#img_box").html(backing + '<img src="images/jacket/' + img_src + '" id="sw_case"  onclick="BgOff();"/><div id="author"><table border="0" cellpadding="0" cellspacing="0" onclick="BgOff();"><tr><td><img src="img/Data.gif" border="0" /><div class="DTN">' + title + '<br/>' + name + '</div></td></tr></table></div>' + nexting);

	$(".DTN").css({"position":"absolute", "left":75, "top":58});
	wl = wbody - 455;
	$('#backer').css({ "position":"absolute", "left":wl, "top":hbody, "z-index":"300" });
	wl = wbody + 390;
	$('#nexter').css({ "position":"absolute", "left":wl, "top":hbody, "z-index":"300" });

	wl = (wbody >> 1) + 182;
	hl = hbody >> 1;
	$("#author").css({ "position":"absolute", "left":wl, "top":hl, "z-index":300, "fontSize":"16px", "text-align":"left", "color":"#000000"});

	wl = wbody - (width >> 1);
	hl = hbody - (height >> 1);
	$("#sw_case").css({"position":"absolute", "left":wl, "top":-1000, "z-index":"100"});
	$("#sw_case").animate({ "left":wl, "top":hl}, 500, function(){
		$("#author").animate({ "left":"30", "top":"600" }, 300);
	});

}


//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
//
//	前後のイメージ表示処理
//
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
function PrevNext(src){
	$("#sw_case").animate({"top":1000}, 500, function(){
		$("#prapper").hide();
		$("#img_box").hide().empty();
		imager = explode("[idat]", src);
		BgOn(imager[0], imager[1], imager[2], imager[3], imager[4], imager[5], imager[6]);
	});
}


//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
//
//	拡大イメージの消去
//
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
function BgOff(){
	$("#prapper").hide();
	$("#img_box").hide().empty();
}



//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
//
//	カテゴリのセレクト
//
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
function SelCat(no, page){
	$("#prapper").hide();
	$("#img_box").hide().empty();
	$("#imglist").load("selcat.php?cat="+ no + "&page" + page , function(img){
		imager = explode("[data]", img);
		$("#imglist").html(imager[0]);
		$('*[id*="img_list"]').css({"margin":"2px 2px 0 0", "display":"block", "float":"left", "width":"108px", "height":"108px"});
		$("#cat_photo").html("登録数" + imager[1] + "枚&nbsp;&nbsp;&nbsp;&nbsp;1～" + imager[1] + "枚表示");
   });
}


//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
//
//	ページ処理
//
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
function NextStage(page, vmax){
	no = $("#cat").val();
	$("#imglist").load("selcat.php?cat="+ no + "&page=" + page , function(img){
		imager = explode("[data]", img);
		$("#imglist").html(imager[0]);
		$('*[id*="img_list"]').css({"margin":"2px 2px 0 0", "display":"block", "float":"left", "width":"108px", "height":"108px"});
		pic_cnt = page * 40 + 1;
		pic_cnt2 = imager[1];
		$("#cat_photo").html("登録数" + vmax + "枚&nbsp;&nbsp;&nbsp;&nbsp;" + pic_cnt + "～" + pic_cnt2 + "枚表示");

		pre_s = page-1;
		$("#back_page").html("");
		if(0 != page)$("#back_page").html("<img src=\"Showcase/back_on.gif\" alt=\"前\" width=\"65\" height=\"76\" onclick=\"NextStage("+ pre_s + "," + vmax +");\" style=\"cursor:pointer;\" />");

		nxt_s = page+1;
		$("#next_page").html("");
		if((pic_cnt+39) < vmax)$("#next_page").html("<img src=\"Showcase/next_on.gif\" alt=\"次\" width=\"65\" height=\"76\" onclick=\"NextStage(" + nxt_s + "," + vmax + ");\" style=\"cursor:pointer;\"/>");

	});

}

function explode( delimiter, string ) {
    // Split a string by string
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_explode/
    // +       version: 802.107
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: kenneth
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: explode(' ', 'Kevin van Zonneveld');
    // *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}

    var emptyArray = { 0: '' };

    if ( arguments.length != 2
        || typeof arguments[0] == 'undefined'
        || typeof arguments[1] == 'undefined' )
    {
        return null;
    }

    if ( delimiter === ''
        || delimiter === false
        || delimiter === null )
    {
        return false;
    }

    if ( typeof delimiter == 'function'
        || typeof delimiter == 'object'
        || typeof string == 'function'
        || typeof string == 'object' )
    {
        return emptyArray;
    }

    if ( delimiter === true ) {
        delimiter = '1';
    }

    return string.toString().split ( delimiter.toString() );
}