LG.wb.Class.Browser = new Class({
	maxele:10,
	maxx:950,
	miny:-950,
	
	ini_xpos:-850,
	ini_ypos:850,
	ini_zpos:0,

	xpos: -850,
	ypos: 850,
	zpos: 0,

	xdis:410,
	ydis:410,
	zdis:500,
	
	items:{},
	initialize: function(ele,width,height){
		this.isShiftDown=false;
		this.width=width;
		this.height=height;
		this.alurl='http://access.alchemyapi.com/calls/url/URLGetRankedNamedEntities';
		this.wpurl = 'http://en.wikipedia.org/w/api.php';	
		this.projector = new THREE.Projector();
		this.renderer = new THREE.CanvasRenderer();
		this.renderer.setSize( this.width,this.height );

		ele.innerHTML= "";
		ele.appendChild(this.renderer.domElement) ;
		ele.onBlur=function(){
			LG.wb.App.Browser.isShiftDown = false;
		};
		
		this.ctarget = new THREE.Object3D();
		this.ctarget.position.x=0;
		this.ctarget.position.y=0;
		this.ctarget.position.z=0;
		
		this.camera = new THREE.Camera( 33, this.width / this.height, 1, 10000, this.ctarget);
        	this.camera.position.z = 1900;
        	this.camera.position.x = 0;

        	this.scene = new THREE.Scene();
		this.ray = new THREE.Ray( this.camera.position, null )

		this.pointLight = new THREE.PointLight( 0xFFFFFF );
		this.pointLight.position.x = 300;
		this.pointLight.position.y = 1000;
		this.pointLight.position.z = 630;
		this.scene.addLight(this.pointLight); 

		// grid
		plane = new THREE.Mesh( new THREE.PlaneGeometry( 2200, 2200, 20, 20 ), new THREE.MeshBasicMaterial( { color: 0x339933, wireframe: true } ) );
		plane.rotation.x = - 90 * Math.PI / 180;
		plane.position.y=-170;
		this.scene.addObject( plane );
		
		// Update proportions
		this.resized();
		$("#ac").focus();	

	},
	resized: function(){
		var c = $("canvas:last");
		this.offset = c.offset();
	},

    render: function () {
		for(index in this.items){
			this.items[index].animate();
		}
        this.renderer.render( this.scene, this.camera );
    },
	animate:  function () {
        requestAnimationFrame( animatecb );
        this.render();
    },
    reset: function(){
		//alert('reset pushed');
		var tmp=this.items;
		// remove from scene
		for(index in this.items){
			this.scene.removeChild(this.items[index].model);
		}   
		// empty array
		this.items={};	
		this.xpos = this.ini_xpos;
		this.ypos = this.ini_ypos;
		this.zpos = this.ini_zpos;
		$("#ac").val('');	
		this.render();
		$("#ac").focus();	
		 
	},
	display: function(wpage){
	//	if (this.items.length > this.maxele ) return;
		
		
		// take a wiki page and initialize an Item Object from the data obtained
		var s =str_clean(wpage) ;
		if(this.items[s] !== undefined) return;
		this.items[s]= new LG.wb.Class.Item(this, wpage);
	  	this.scene.addObject( this.items[s].model );

	
		this.items[s].model.position.x += this.xpos;
		this.items[s].model.position.z += this.ypos;
		this.items[s].model.position.y += this.zpos;

		// advance position
		this.xpos += this.xdis;
		if (this.xpos > this.maxx) {
			this.xpos = this.ini_xpos;
			this.ypos -= this.ydis;
		}		
		if(this.ypos < this.miny){
			this.xpos = this.ini_xpos;
			this.ypos = this.ini_ypos;
			this.zpos += this.zdis;
		}	
	},
}); // End of LG.wb.Class.Browser

