// We'll start our custom code when the page DOM will be totally loaded
jQuery(document).ready(function () {
	App.eligoInited();
});

// This is our custom code wrapper
var App = {
	
	// options
	doAntiAlias: false,
	antialiasPasses: 4,
	hideCursor: false,
	flipRender: false,
	
	// internals
	isTracking: false,
	
	
	modelLoaded: function() {
			
			var self = this;
			
			// comment out the following line if
			// you don't want to go in AR mode immediately
			this.eligo.setArMode(1);
			
			
			if ( this.doAntiAlias )
			{
				this.eligo.setAntialiasEnabled(1);
				this.eligo.setAntialiasPasses( this.antialiasPasses );
			}
			else
			{
				this.eligo.setAntialiasEnabled(0);
			}
			
			var self = this;
			
			
	},
	
	onArStop: function() {
		this.isTracking = false;
		
	},
	
	onArStart: function() {
		this.isTracking = true;
	},
	
	eligoInited: function() {
	
		this.eligo = document.getElementById("LinceoVRViewer");
		
		if ( $.browser.msie )
		{
			$("body").append(
				"<script>"+
					"function LinceoVRViewer::ARStartedTracking() { window.App.onArStart(); }"+
					"function LinceoVRViewer::ARStoppedTracking() { window.App.onArStop(); }"+
				"</script>"
			);
			
		}
		else
		{
			
			var self = this;
			this.eligo.ARStartedTracking = function() { window.App.onArStart(); };
			this.eligo.ARStoppedTracking = function() { window.App.onArStop(); };
		}
			
        
		// disable GUI context menu
		//this.eligo.setGUIEnabled( 0 );
		
		this.eligo.setHideCursor( this.hideCursor );
		
		this.eligo.setWindowBackground( 0, 0, 0 );
		
		var self = this;
		
		if ( this.flipRender )
		{
			setTimeout( function() { 
				self.eligo.setFlipRenderHorizontally(1);
				
			}, 500 );
		}
		
		
		// timeout is necessary for chrome ( and firefox? )
		setTimeout( function() { self.modelLoaded(); }, 200 );
		
	}
	
};

