this.crehabjs = this.crehabjs || {};
(function(cjs, cr){	
	var mBgms = {};
	var mSound = {};
	var that;
	function Common(){
		that=this;
		throw "Common cannot be instantiated";
	};
	//--------------------------------------------------------------------
	var p = Common;	
	//--------------------------------------------------------------------
	//--------------------------------------------------------------------
	p.getSeriesNum=function(startNum,endNum){
		var ran=new Array();
		for(var i=0;i<endNum-startNum;i++){
			ran[i]=startNum+i;
		}
		var result=this.getRandomArray(ran);
		return result;
	};
	//--------------------------------------------------------------------
	p.getRandomArray=function(array){
		var len=array.length;
		var result=new Array();
		while(len>0){
			var j=Math.floor(Math.random()*1000000%len);
			result.push(array[j]);
			if (j>-1) {
				array.splice(j, 1);
			}
			len--;
		}
		return result;
	};
	//--------------------------------------------------------------------
	p.getRandomArraySeriesNum=function(startNum,endNum){
		var ran=new Array();
		for(var i=0;i<endNum-startNum;i++){
			ran[i]=startNum+i;
		}
		var result=this.getRandomArray(ran);
		var ranResult=p.getRandomArray(result);
		return ranResult;
	};
	//--------------------------------------------------------------------
	p.addBasicEvent=function(objs,inThat){
		if (inThat===undefined){
			if (Array.isArray(objs)==true){
				inThat=objs[0].parent.parent;
			}else{
				inThat=objs.parent.parent;
			}
		}
		if (Array.isArray(objs)==true){
			for(var i=0;i<objs.length;i++){
				objs[i].on('click', inThat.onClick, inThat);
				objs[i].on('rollover', inThat.onRollover,inThat);
				objs[i].on('rollout', inThat.onRollout,inThat);
			}
		}else{
			objs.on('click', inThat.onClick, inThat);
			objs.on('rollover', inThat.onRollover,inThat);
			objs.on('rollout', inThat.onRollout,inThat);
		}
	};
	//--------------------------------------------------------------------
	p.addMeshBox = function(object,geometry, material, position,castShadow) {
		var bodyGeometry = new THREE.BoxGeometry(geometry[0], geometry[1], geometry[2]);
		var bodyMaterial = new THREE.MeshStandardMaterial(material);
		var body = new THREE.Mesh(bodyGeometry, bodyMaterial);
		body.position.set(position[0], position[1], position[2]);
		if (castShadow === undefined) castShadow = false;
		body.castShadow = castShadow;
		object.add(body);
		return body;
	};
	//--------------------------------------------------------------------
	p.addMeshCylinder = function(object,geometry, material, position,castShadow) {
		var bodyGeometry = new THREE.CylinderGeometry(geometry[0], geometry[1], geometry[2], geometry[3]);
		var bodyMaterial = new THREE.MeshStandardMaterial(material);
		var body = new THREE.Mesh(bodyGeometry, bodyMaterial);
		body.position.set(position[0], position[1], position[2]);
		if (castShadow === undefined) castShadow = false;
		body.castShadow = castShadow;
		object.add(body);
		return body;
	};
	//--------------------------------------------------------------------
	p.addMeshRoundedBox = function(object, geometry, material, position, castShadow) {
		var bodyGeometry = new THREE.RoundedBoxGeometry(geometry[0], geometry[1], geometry[2], geometry[3], geometry[4]);
		var bodyMaterial = new THREE.MeshStandardMaterial(material);
		var body = new THREE.Mesh(bodyGeometry, bodyMaterial);
		body.position.set(position[0], position[1], position[2]);
		if (castShadow === undefined) castShadow = false;
		body.castShadow = castShadow;
		object.add(body);
		return body;
	};
	
	// Finally
	cr.Common = Common;
}(createjs, crehabjs));