/* ------------------------------------------ *
 * slide()
/* ------------------------------------------ */

var timer = null;

slide = function(objID,childObjId) {
	var obj = document.getElementById(objID);
	obj.style.overflow = 'hidden';
	var childObjId = childObjId;
	/* ------------------------------------------ *
	 * up()
	/* ------------------------------------------ */

	this.up = function(obj,ori,speed,childObjID) {
		var present = getElementSize(obj).oh;
		var moveValue = speed + 3;
		
		present = present-moveValue;
	
		if(present > 0) {
			obj.style.height = present + 'px';
			timer = window.setTimeout(function(){ this.up(obj,ori,speed) }, 10);
		}
	
		else {
			obj.style.height = ori + 'px';
			obj.style.display = 'none';
			timer = null;
		};

	document.getElementById(childObjId).style.backgroundColor = "#FFFFFF";

	}
	
	
	/* ------------------------------------------ *
	 * down()
	/* ------------------------------------------ */
	
	this.down = function(obj,limit,slow,childObjID) {
		var present = getElementSize(obj).oh;
		var distance = limit-present;
		var moveValue = Math.max(Math.floor(distance / slow),slow);
	
		if(present < limit) {
			obj.style.height = (present+moveValue) + 'px';
			timer = setTimeout(function(){ this.down(obj,limit,slow) }, 10);
		}
		
		else {
			obj.style.height = limit + 'px';
			timer = null;
		};
		
	document.getElementById(childObjId).style.backgroundColor = "#DDDDDD";
	}


	/* ------------------------------------------ *
	 * start
	/* ------------------------------------------ */

	var o = getElementSize(obj);
	var slow = 3;
	var speed = 30;
	
	if(obj.offsetHeight == 0) {
		obj.style.display = 'block';
		obj.style.height = 0;

		if(timer == null) this.down(obj,o.oh,slow,childObjId);
	}
	
	else {
		if(timer == null) this.up(obj,o.oh,speed,childObjId);
	}
	
}


/* ------------------------------------------ *
 * getElementSize()
/* ------------------------------------------ */

getElementSize = function(elm) {
	var oSize = new Object();
	var elm2 = elm.cloneNode(true);

	if(-1 == navigator.userAgent.indexOf('MSIE 5')){
		elm2.style.padding = '0';
		elm2.style.border = '0';
	}
	elm2.style.display = 'block';
	elm2.style.position = 'absolute';

	elm.parentNode.appendChild(elm2);
	oSize.oh = elm2.clientHeight;
	oSize.ow = elm2.clientWidth;
	elm.parentNode.removeChild(elm2);
	
	return oSize;
}


/* ------------------------------------------ *
 * getElementsByClass()
/* ------------------------------------------ */

getElementsByClass = function(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

/* ------------------------------------------ *
 * onload()
/* ------------------------------------------ */

//function setPosition() {
//	var target = getElementsByClass('slidemenu',document,'a');
//	for(i=0; i<target.length; i++) 
//	{
//		target[i].onclick = function(){ slide('samplemenu') };
//	}
//};

function setPosition() {

	idList 		= [ 'KIHON','REF140','TVSET','BEDSET','AIRCONSET','RICESET','AV','KADEN','SHUNO','SEIKATSU' ];
	childIdList = [ 'left_merchandise_kihon','left_merchandise_140REF','left_merchandise_tvset','left_merchandise_bedset','left_merchandise_airconset','left_merchandise_riceset','left_merchandise_av','left_merchandise_kaden','left_merchandise_shuno','left_merchandise_seikatsu' ];

		if( document.getElementById( 'KIHON' ) )
			{
			document.getElementById( 'left_merchandise_kihon' ).onclick 	= function(){ slide( 'KIHON','left_merchandise_kihon' ); return false;}
			document.getElementById( 'closeKIHON' ).onclick 				= function(){ slide( 'KIHON','left_merchandise_kihon' ); return false;}
			}
		if( document.getElementById( 'REF140' ) )
			{
			document.getElementById( 'left_merchandise_140REF' ).onclick 	= function(){ slide( 'REF140','left_merchandise_140REF' ); return false;}
			document.getElementById( 'close140REF' ).onclick 				= function(){ slide( 'REF140','left_merchandise_140REF' ); return false;}
			}
		if( document.getElementById( 'TVSET' ) )
			{
			document.getElementById( 'left_merchandise_tvset' ).onclick		 	= function(){ slide( 'TVSET','left_merchandise_tvset' ); return false;}
			document.getElementById( 'closeTVSET' ).onclick 					= function(){ slide( 'TVSET','left_merchandise_tvset' ); return false;}
			}
		if( document.getElementById( 'BEDSET' ) )
			{
			document.getElementById( 'left_merchandise_bedset' ).onclick 	= function(){ slide( 'BEDSET','left_merchandise_bedset' ); return false;}
			document.getElementById( 'closeBEDSET' ).onclick 				= function(){ slide( 'BEDSET','left_merchandise_bedset' ); return false;}
			}
		if( document.getElementById( 'AIRCONSET' ) )
			{
			document.getElementById( 'left_merchandise_airconset' ).onclick 	= function(){ slide( 'AIRCONSET','left_merchandise_airconset' ); return false;}
			document.getElementById( 'closeAIRCONSET' ).onclick 				= function(){ slide( 'AIRCONSET','left_merchandise_airconset' ); return false;}
			}
		if( document.getElementById( 'RICESET' ) )
			{
			document.getElementById( 'left_merchandise_riceset' ).onclick 	= function(){ slide( 'RICESET','left_merchandise_riceset' ); return false;}
			document.getElementById( 'closeRICESET' ).onclick 				= function(){ slide( 'RICESET','left_merchandise_riceset' ); return false;}
			}
		if( document.getElementById( 'AV' ) )
			{
			document.getElementById( 'left_merchandise_av' ).onclick 		= function(){ slide( 'AV','left_merchandise_av' ); return false;}
			document.getElementById( 'closeAV' ).onclick 					= function(){ slide( 'AV','left_merchandise_av' ); return false;}			
			}
		if( document.getElementById( 'KADEN' ) )
			{
			document.getElementById( 'left_merchandise_kaden' ).onclick 	= function(){ slide( 'KADEN','left_merchandise_kaden' ); return false;}
			document.getElementById( 'closeKADEN' ).onclick 				= function(){ slide( 'KADEN','left_merchandise_kaden' ); return false;}
			}
		if( document.getElementById( 'SHUNO' ) )
			{
			document.getElementById( 'left_merchandise_shuno' ).onclick 	= function(){ slide( 'SHUNO','left_merchandise_shuno' ); return false;}
			document.getElementById( 'closeSHUNO' ).onclick 				= function(){ slide( 'SHUNO','left_merchandise_shuno' ); return false;}
			}
		if( document.getElementById( 'SEIKATSU' ) )
			{
			document.getElementById( 'left_merchandise_seikatsu' ).onclick 	= function(){ slide( 'SEIKATSU','left_merchandise_seikatsu' ); return false;}
			document.getElementById( 'closeSEIKATSU' ).onclick 				= function(){ slide( 'SEIKATSU','left_merchandise_seikatsu' ); return false;}
			}
};
window.onload = setPosition;




