
//developed by: Basavaraj

"use strict";
var Game = function($) {

	return {

		config : {
			width : 320,
			height : 480,
			
		},

		/**
		 * Initializes Quiz application
		 */
		initialize : function() {
			
			
			/*Crafty.viewport.absoluteScale = function (scaleFactor1, scaleFactor2) {
				var ctx = Crafty.canvas.context;
				console.log("absolute scale function is called ", scaleFactor1, scaleFactor2)
				
				// Clear entire canvas; scaling invalidates dirty rects and leaves artifacts behind.
				ctx.save();
				ctx.setTransform(1,0,0,1,0,0);
				ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
				ctx.restore();
				
				// Trick Crafty.viewport.scale into operating in absolute mode.
				Crafty.stage.inner.style['transform'] =
				    Crafty.stage.inner.style[Crafty.support.prefix + "Transform"] = 'scale(1, 1)';
				Crafty.viewport._zoom = 1;
				Crafty.viewport.scale(scaleFactor1/scaleFactor2);
			    };
			
			
			Crafty.init();
			Crafty.canvas.init();
			
			var scaler = function() {
			var current = { w: Crafty.viewport.width, 
					  h: Crafty.viewport.height };
			
			  // This will reset the scale when it adjusts the canvas element
			  // dimensions, so do it right before setting the scale we want.
			  Crafty.viewport.reload();
			  console.log("current width and height, ", current.w, current.h)
			
			  if ( current.w > current.h ) {
			    // Landscape, scale to fit height
			    Crafty.viewport.absoluteScale( current.h , 480 );
			    
			  } else {
			    // Portrait, scale to fit width
			    Crafty.viewport.absoluteScale( current.w , 320 )
			  }
			  if (Crafty.viewport.width > 320) {
				//code
				Crafty.viewport.x = -110;
				Crafty.viewport.y = -150;
			  }
			  
			};
			
			// Avoid drawing entities before we're ready to scale.
			Crafty.removeEvent( Crafty, window, 'resize', Crafty.viewport.reload );
			
			// Adjust scale to fit inside resized window.
			Crafty.addEvent( Crafty, window, 'resize', scaler );
			
			// Run the scaler after scene changes, since they reset the scale.
			Crafty.bind( 'SceneChange', scaler );*/
			//---------------------------------------------------

			// init Crafty
			// Crafty.init(this.config.width, this.config.height);
			Crafty.init();
// 						Crafty.init(320,480);
			Crafty.canvas.init();

			
			// // set bacgroundd
			Crafty.background('rgb(255,255,255)')
			// Crafty.background("url('images/game_bg.png')");

			
			screen.mozLockOrientation("portrait");

				if(Crafty.mobile){
					console.log("MOBILE VERSION");
					Crafty.stage.fullscreen=true;
				}
				else {
					console.log("NOT MOBILE VERSION");
				}
				 initializeDB();

				Crafty.sprite(19, "images/number.png", {
                    number0: [0, 0],
                    number1: [1, 0],
                    number2: [2, 0],
                    number3: [3, 0],
                    number4: [4, 0],
                    number5: [5, 0],
                    number6: [6, 0],
                    number7: [7, 0],
                    number8: [8, 0],
                    number9: [9, 0]
                  });
                
                 Crafty.sprite(66, "images/selectballSprite.png", {
                    targetSelectedBall: [0,0]
                  });
                
                
                Crafty.load([ "images/lock.png", "images/game_grid.png", "images/game_bg.png", "images/menu_playBtn.png", "images/sound_on.png", "images/sound_off.png", "images/menu_help.png", "images/menu_aboutUs.png", "images/pause_btn.png"], 
                                function() { 
                                   console.log("***************************************")
                                   console.log(" all assets are loaded ")
                                   console.log("***************************************")
                                    loadAudio();
                                    Crafty.scene('TTSplash');
                                   
                                },
                
                                function(e) {
                                    console.log("progress ", e.total, e.loaded)
                                }
                               ) 


                // Crafty.scene('GameSplash');


			    // alert("Width and Height are "+ Crafty.viewport.width +" "+ Crafty.viewport.height);
			
		},

	};
    
}($);





