/* Popup inner window */
/* Ver.0.8*/


var mochi_ani = null;
var stl;
var deletePop = function (){return false};

	var stl = {};
	stl.name = 'styling';
	
	stl.height = 600;
	stl.width = 680;
	stl.shadow = 'http://www.nk-craft.net/products/img/photoframe/base.png';
	stl.white = 'http://www.nk-craft.net/products/img/photoframe/white.gif';


function createFloatElements(){
	
	var float_wrp = DIV({'id':'float-wrp','style':'position:absolute;top:-1000px;left:-1000px; width:700px; height:600px; z-index:110'});
		float_wrp.appendChild( IMG({
								'id':'float-base-img',
								'src':stl.shadow,
								'width':stl.width,
								'height':stl.height,
								'class':"scaling",
								'style':'position:absolute;top:0px;left:0px;visibility:hidden;behavior:expression(IEPNGFIX.fix(this));'
								})
						   );		
		float_wrp.appendChild( IMG({
								'id':'float-white-img',
								'src':stl.white,
								'width':stl.width,
								'height':stl.height,
								'class':"scaling",
								'style':'position:absolute;top:0px;left:0px;visibility:hidden;'
								})
						   );		
	
		var conts_wrp = DIV({ 'id':"float-conts-wrp",'class':"scaling",'style':'position:absolute; top:6px; width:700px; height:535px; padding:5px 0'});
		
	float_wrp.appendChild(conts_wrp);
	
	return float_wrp;
}

/* Hide Float Window */
function hiddenPop(){
	$('photoframe-wrp').setAttribute('onclick', null);
	
	mochi_ani.cancel();
	if(Boolean($('ProductSheet'))){
		$('ProductSheet').style.visibility = "visible";
		//$('slideshow').style.visibility = 'hidden'; 
	}
	var op = $('float-wrp').style.opacity;
	//alert(op);
	if(op > 0.05){
	
		if(BrowserDetect.browser == "Explorer"){
			$('float-white-img').style.visibility = "visible";
			$('float-base-img').style.visibility = "hidden";
		}
		
		setDisplayForElement('none','float-close');
		var node = document.getElementById('float-wrp');
		var inodes = getElementsByTagAndClassName('img','scaling', node);
		inodes = inodes.concat(getElementsByTagAndClassName('div','scaling', node));
		var p = [];
		p.push(Opacity('float-wrp',{from:1.0,to:0.0,duration:0.5}));
		
		Parallel(p, {
				 		afterFinish:function(){
				 								$('photoframe-wrp').style.display = "none";
												removeElement($('float-wrp'));
												}
					});
	}
}
/* Show Float Window */
function showPop1(_product_name){
	if(mochi_ani){
		mochi_ani.cancel();
	}
	//alert('---');
	//var float_wrp = DIV({'id':'hidden-div','style':'position:absolute;top:0px;left:0px;width:100%;height:100%;display:none'});
	if($('float-wrp')){
		removeElement($('float-wrp'));
	}
	
	var child = createFloatElements();
	
	$('photoframe-wrp').appendChild(child);
	$('photoframe-wrp').style.display = "block";
	$('float-wrp').style.visibility = "visible";
	$('float-wrp').style.opacity = 0.01;
	$('float-wrp').style.filter = "alpha(opacity=0)";
	
	var node = $('float-wrp');
	var inodes = getElementsByTagAndClassName('img','scaling', node);
	inodes = inodes.concat(getElementsByTagAndClassName('div','scaling', node));
		
	var p = [];
	
	for(var i=0; i<inodes.length;i++){
		p.push(Scale(inodes[i], 10, {scaleFromCenter:true,duration:0.1}));
			
	}
	
	p.push(Scale('float-wrp', 10,{scaleFromCenter: true,duration:0.1}));
	p.push(Opacity('float-wrp',{from:1,to:0.1,duration:0.1}));
	mochi_ani = Parallel(p,{afterFinish:function(){showPop2(_product_name)}});
		
	
}
function showPop2(_product_name){
	var point_from = MochiKit.Position.cumulativeOffset($("a-"+_product_name));

	if(BrowserDetect.browser != "Explorer"){
		$('float-base-img').style.visibility = "visible";
		var set_posi =  MochiKit.Position.realOffset('float-wrp');
		point_from.x = point_from.x-225;
		point_from.y = point_from.y-215;
		
	}else{
		$('float-white-img').style.visibility = "visible";
	}
	
	var op = $('float-wrp').style.opacity;
	if(op <= 0.5){
		
		var ani_duration = 0.5;
		var ani_fps = 30;
		
		var point_to = {};
		
		var v_p = getViewportPosition();
		var v_d = getViewportDimensions();
		var f_s = stl;
		//横
		if(f_s.width >= v_d.w){
			point_to.x = v_p.x;
		}else{
			point_to.x = ((v_d.w-f_s.width)/2)+v_p.x;
		}
		
		//縦
		if(f_s.height >= v_d.h){
			point_to.y = v_p.y;
		}else{
			point_to.y = ((v_d.h-f_s.height)/2)+v_p.y;
		}
		point_to.duration = ani_duration;
		point_to.mode = 'absolute';
		point_to.fps = ani_fps;
		
		
		$('float-wrp').style.left = point_from.x+'px';
		$('float-wrp').style.top = point_from.y+'px';
		
		var node = $('float-wrp');
		var inodes = getElementsByTagAndClassName('img','scaling', node);
		inodes = inodes.concat(getElementsByTagAndClassName('div','scaling', node));
		var p = [];
		for(var i=0; i<inodes.length;i++){
			p.push(Scale(inodes[i], 1000, {scaleFromCenter:true,duration:ani_duration,fps:ani_fps}));
			
		}
		p.push(Scale('float-wrp', 1000,{scaleFromCenter:true,duration:ani_duration,fps:ani_fps}));
		p.push(Opacity('float-wrp',{from:0.0,to:1,duration:1.5,fps:ani_fps}));
		p.push(Move('float-wrp',point_to));
		mochi_ani = Parallel(p, {		
						beforeUpdate:function(){	
													

						},
												
						afterUpdate:function(){
													//var fw = MochiKit.Position.positionedOffset($('white-base'));
													
													//var stl = getFloatStyles();
													//dump(  $('float_wrp').style.width+ " : "+$('float_wrp').style.height + "<br>"  );
													
						},
						beforeFinish:function(){
						                      
												//dump(  );
												//var fw = MochiKit.Position.positionedOffset($('white-base'));
												/*
												var stl = getFloatStyles();
												$('float_wrp').style.width = stl.width;
												$('float_wrp').style.height = stl.height;
												*/
												if(Boolean($('ProductSheet'))){
													$('ProductSheet').style.visibility = "hidden";
												}
						},
						afterFinish:function(){
												
						            if(BrowserDetect.browser == "Explorer"){
													$('float-base-img').style.visibility = "visible";
													$('float-white-img').style.visibility = "hidden";
													$('float-white-img').style.behavior = "expression(IEPNGFIX.fix(this))";
                        }
                        
                        $('float-conts-wrp').style.width = stl.width +"px";
												$('float-conts-wrp').style.top = (parseInt($('float-base-img').style.top) + 6) +"px";
												$('float-conts-wrp').style.left = parseInt($('float-base-img').style.left) +"px";
												
												$('float-conts-wrp').style.margin = "auto";
												var main_conts = DIV({'class':'main-conts','id':'main-conts','style':'top:0;left:0'});
												
												$('float-conts-wrp').appendChild(main_conts);
												main_conts.innerHTML = itemManager.getMainContent(_product_name);
												
												$('photoframe-wrp').setAttribute('onclick', 'hiddenPop()');
												
												//$('float-base-img').style.behavior='expression(IEPNGFIX.fix(this))';
						}
											  
					});
	 }
}

/** 
*product search 
*
**/

var itemManager = {
	
	getMainContent:function(id){
		var dir;
		var title;
		if(typeof(item_code) != "undefined"){
			dir = '/board_images/open/'+item_code+'/500/';
			title = $('item-title').innerHTML;
		}else {
			dir = '/products/img/anniversary/';
			title = $('title-' + id).innerHTML;
		}
		var tmpl = '<div id="conts-head" style="width:500px;margin:auto">	<div id="close-btn" style="float:right;margin-top:5px"><a href="javascript:hiddenPop()"><img src="/products/img/photoframe/close_btn.gif" border="0" /></a></div><h2 id="photo-title" style="overflow:hidden;height:37px;line-height:37px; text-align:left; background:url(/products/img/photoframe/title_head.gif) left center no-repeat"><span style="display:block;overflow:hidden;height:30px;font-size:21px;font-family:Times;margin-left:40px;">' + title +'</span></h2></div><div id="photo-main"style="margin:auto;width:500px;overflow:hidden"><img src="' + dir + id+'.jpg"></div>';
		return toHTML(tmpl);
	}

};

