var descr_loadstate = new Object(); // 読み込み中？
var descr_show = new Object(); // 表示すべき？

function hidePhotoPopup(id){
	$('Description_popup_' + id).style.display='none';
	descr_show[id]=false;
}

function showPhotoPopup(e, id, tate_flg, group_no){
	$('Description_popup_' + id).style.left = "0";
	$('Description_popup_' + id).style.top  = "0";

	var src_id = 'popup_img_src_' + id;
	var img_src = Element.classNames(src_id);
	var size = group_no>0 ? 
		(tate_flg == 1 ?  'height="300"' : 'width="300"') :
		(tate_flg == 1 ?  'height="360"' : 'width="360"');
	var html_code = '<img src="' + img_src + '" ' + size + ' />';
	Element.update(src_id, html_code);

	var target_id = 'popup_img_vars_' + id;
	if($(target_id) && Element.empty(target_id)){
		var myAjax = new Ajax.Updater(target_id, '/search/', {
			method: 'get', 
			parameters:{
				rm:"popup",img_no:id
			},
			onComplete:function(req){	

			}

		});
	}

 	$('Description_popup_' + id).style.display = 'block';
	movePhotoPopup(e, id);
}

function showMoviePopup(e, id, aspect, group_no){
	$('Description_popup_' + id).style.left = "0";
	$('Description_popup_' + id).style.top  = "0";

	var src_id = 'popup_img_src_' + id;
	var flv_src = Element.classNames(src_id);

/*

	var img_src = Element.classNames(src_id);
	var size = group_no>0 ? 
		(tate_flg>0 ?  'height="300"' : 'width="300"') :
		(tate_flg>0 ?  'height="360"' : 'width="360"');
	var html_code = '<img src="' + img_src + '" ' + size + ' >';
	Element.update(src_id, html_code);
*/
	var width = 370;
	var height = aspect ? 232 : 301;

	var html_code;
	html_code  = '<a href="' + flv_src + '" style="display:block;width:' + width + 'px;height:' + height + 'px" class="myPlayer"></a>';
	html_code += '<script>';
	html_code += 'flowplayer("a.myPlayer", "/image/flvplayer/flowplayer.commercial-3.1.5.swf",';
	html_code += '{';
	html_code += 'key: "#$b08860157131db48d55",';
	html_code += 'plugins:  {';
	html_code += 'controls:  {';		
	html_code += 'sliderColor: "#000000",';
	html_code += 'buttonColor: "#333333",';
	html_code += 'progressGradient: "medium",';
	html_code += 'progressColor: "#888888",';
	html_code += 'borderRadius: "0",';
	html_code += 'bufferColor: "#444444",';
	html_code += 'tooltipTextColor: "#333333",';
	html_code += 'durationColor: "#ffffff",';
	html_code += 'tooltipColor: "#bbbbbb",';
	html_code += 'backgroundGradient: "high",';
	html_code += 'volumeSliderGradient: "medium",';
	html_code += 'sliderGradient: "medium",';
	html_code += 'timeBgColor: "#666666",';
	html_code += 'backgroundColor: "#cccccc",';
	html_code += 'volumeSliderColor: "#666666",';
	html_code += 'bufferGradient: "medium",';
	html_code += 'buttonOverColor: "#ad1207",';
	html_code += 'timeColor: "#ffffff",';
	html_code += 'height: 24,';
	html_code += 'opacity: 1.0,';
	html_code += 'all:false,'; 
	html_code += 'scrubber:true,';
	html_code += 'time:true,';
	html_code += 'mute:false,';
	html_code += 'bufferLength:1.5,';
	html_code += 'volume:false, ';
	html_code += 'play:false,'; 
	html_code += 'fullscreen:false';	
	html_code += '}'; // controls
	html_code += '},'; // plugins
	html_code += 'clip: {';
	html_code += 'onBegin: function () {';
	html_code += 'this.getPlugin("play").css({opacity: 0});';
	html_code += '},';
	html_code += 'onFinish: function () {';
	html_code += 'this.getPlugin("play").css({opacity: 0});';
	html_code += '},';
	html_code += 'onBeforeFinish: function() {';
	html_code += 'return false;';
	html_code += '},';
	html_code += 'fadeInSpeed:0';
	html_code += '}'; //clip
	html_code += '});';
	html_code += '</script>';
	
	Element.update(src_id, html_code);
	var target_id = 'popup_img_vars_' + id;
	if($(target_id) && Element.empty(target_id)){
		var myAjax = new Ajax.Updater(target_id, '/search/', {
			method: 'get', 
			parameters:{
				rm:"popup",img_no:id
			},
			onComplete:function(req){	

			}

		});
	}

 	$('Description_popup_' + id).style.display = 'block';
	movePhotoPopup(e, id);
}


function movePhotoPopup(e, id){
	var w = $('Description_popup_' + id).clientWidth ;
	var h = $('Description_popup_' + id).clientHeight ;

	var scrollY = document.body.scrollTop || document.documentElement.scrollTop;
	var nx = (getMouseSX(e) < getINNERWIDTH() / 2)?(getMouseX(e) + 16 - 0):(getMouseX(e) - 16 - w);
	var ny = Math.floor((getINNERHEIGHT() - h) / 2) + scrollY;

	$('Description_popup_' + id).style.left = nx+"px";
	$('Description_popup_' + id).style.top  = ny+"px";
}

function moveMoviePopup(e, id){
	var w = $('Description_popup_' + id).clientWidth ;
	var h = $('Description_popup_' + id).clientHeight ;

	var scrollY = document.body.scrollTop || document.documentElement.scrollTop;
	var nx = (getMouseSX(e) < getINNERWIDTH() / 2)?(getMouseX(e) + 32 - 0):(getMouseX(e) - 32 - w);
	var ny = Math.floor((getINNERHEIGHT() - h) / 2) + scrollY;

	$('Description_popup_' + id).style.left = nx+"px";
	$('Description_popup_' + id).style.top  = ny+"px";
}


/* RequeestSelection用 ********************************/
function setDescrPopupReq( e , img_no ){
	moveDescrPopupReq(e, img_no);
 	$( 'Description_popup_' + img_no ).style.display='block';
	var ajax = new Ajax.Request (
		'/request/photo/',
		{
			method : 'post' ,
			parameters : 'img_no=' + img_no ,
			onSuccess : function ( res ) {
				var w_data;
				if( res.responseText == '0' ){
					w_data = 'err';
				} else{
					$( 'Description_popup_' + img_no ).innerHTML = res.responseText;
				}
			}
		}
	);
}

function moveDescrPopupReq(e,no){
	var w = $('Description_popup_'+no).offsetWidth ;
	var h = $('Description_popup_'+no).offsetHeight ;
	/*
	var nx = getMouseX(e)+40;
	var ny = getMouseY(e)+16;
	if(getMouseSX(e)+w+40 > getINNERWIDTH() )
		nx=getMouseX(e)-40-w;
	if(getMouseSY(e)+h+16 > getINNERHEIGHT() ) {
		ny=getMouseY(e)-16-h;
	}
	ny = 0;
	*/
	var nx = (getMouseSX(e) < getINNERWIDTH()  / 2)?(getMouseX(e) + 16):(getMouseX(e) - 16 - w);
//	var ny = (getMouseSY(e) < getINNERHEIGHT() / 2)?(getMouseY(e) + 16):(getMouseY(e) - 16 - h);
	var ny = Math.floor((getINNERHEIGHT() - h) / 2) + document.documentElement.scrollTop;
	$('Description_popup_'+no).style.left=nx+"px";
	$('Description_popup_'+no).style.top =ny+"px";
}

