
"use strict";
var Game = function($) {
    return {
        config : {
            width : 480,
            height : 280,   
        },
		
        initialize : function() {
            Crafty.init();
			Crafty.canvas.init();
			Crafty.stage.fullscreen=true;
			Crafty.background('rgb(255,255,255)')
			screen.mozLockOrientation("landscape-primary");

			if(Crafty.mobile){
				//console.log("MOBILE VERSION");
			}
			else {
				//console.log("NOT MOBILE VERSION");
			}
			
            initializeDB();
            
            //  car wheel image
            Crafty.sprite(23, "images/wheelAnimation1.png", {
                Wheel: [0,0]
            });
            
            //  speedometer needle image
            Crafty.sprite(26, 23, "images/needle.png", {
                Needle0: [0,0],
                Needle1: [1,0],
                Needle2: [2,0],
                Needle3: [3,0],
                Needle4: [4,0],
                Needle5: [5,0],
                Needle6: [6,0],
                Needle7: [7,0],
                Needle8: [8,0]
            });
            
            //  countDown text
            Crafty.sprite(150, 82, "images/start.png", {
                Start: [0,0]
            });
            
            //  car accelerator image
            Crafty.sprite(40,74, "images/accelerator.png", {
                Accelerator1: [0,0],
                Accelerator2: [1,0]
            });
            
            //  nos image
            Crafty.sprite(65, "images/nos_button.png", {
                Nos1: [0,0],
                Nos2: [1,0]
            });
				
            //  mainmenu buttons background 
            Crafty.sprite(203,38, "images/button_back.png", {
                Menuback1: [0,0],
                Menuback2: [1,0]
            });
            
            //  game mode buttons background
            Crafty.sprite(228,46, "images/menu_button_back.png", {
                Modeback1: [0,0],
                Modeback2: [1,0]
            });
            
            //  back button image
            Crafty.sprite(46,46, "images/back.png", {
                BackBtn1: [0,0],
                BackBtn2: [1,0]
            });
            
            //  pause button image
            Crafty.sprite(46,46, "images/pause.png", {
                PauseBtn1: [0,0],
                PauseBtn2: [1,0]
            });
            
            //  select button image
            Crafty.sprite(46,46, "images/select.png", {
                Select1: [0,0],
                Select2: [1,0]
            });
            
            //  exit button image
            Crafty.sprite(46,46, "images/exit.png", {
                Exit1: [0,0],
                Exit2: [1,0]
            });
            
            //  left arrow image
            Crafty.sprite(34,53, "images/left_pointer.png", {
                Left1: [0,0],
                Left2: [1,0]
            });
            
            //  right arrow image
            Crafty.sprite(34,53, "images/right_pointer.png", {
                Right1: [0,0],
                Right2: [1,0]
            });
            
            //  pause menu buttons background image
            Crafty.sprite(156,38 , "images/pausebutton.png", {
                PauseBack1: [0,0],
                PauseBack2: [1,0]
            });
            
            //  sound_on button
            Crafty.sprite(85,37 , "images/on.png", {
                SoundOn1: [0,0],
                SoundOn2: [1,0]
            });
            
            //  sound_off button
            Crafty.sprite(85,37 , "images/off.png", {
                SoundOff1: [0,0],
                SoundOff2: [1,0]
            });
            
           
            Crafty.load(["images/tt_Logo.png",  "images/title.png",
                         "images/trackBg1/gameBg1.png",  "images/trackBg1/gameBg11.png",        
                         "images/trackBg2/gameBg1.png",  "images/trackBg2/gameBg11.png",        
                         "images/trackBg3/gameBg1.png",  "images/trackBg3/gameBg11.png",        
                         "images/trackBg4/gameBg1.png",  "images/trackBg4/gameBg11.png",        
                         "images/trackBg5/gameBg1.png",  "images/trackBg5/gameBg11.png",  
                         "images/ingame/cat1/0.png", "images/ingame/cat1/1.png", "images/ingame/cat1/2.png",
                         "images/ingame/cat1/3.png", "images/ingame/cat1/4.png", "images/ingame/cat1/5.png",
                         "images/ingame/cat1/6.png", "images/ingame/cat1/7.png", "images/ingame/cat1/8.png",
                         "images/ingame/cat2/0.png", "images/ingame/cat2/1.png", "images/ingame/cat2/2.png",
                         "images/ingame/cat2/3.png", "images/ingame/cat2/4.png", "images/ingame/cat2/5.png",
                         "images/ingame/cat2/6.png", "images/ingame/cat2/7.png", "images/ingame/cat2/8.png",
                         "images/ingame/cat3/0.png", "images/ingame/cat3/1.png", "images/ingame/cat3/2.png",
                         "images/ingame/cat3/3.png", "images/ingame/cat3/4.png", "images/ingame/cat3/5.png",
                         "images/ingame/cat3/6.png", "images/ingame/cat3/7.png", "images/ingame/cat3/8.png",
                         "images/ingame/cat4/0.png", "images/ingame/cat4/1.png", "images/ingame/cat4/2.png",
                         "images/ingame/cat4/3.png", "images/ingame/cat4/4.png", "images/ingame/cat4/5.png",
                         "images/ingame/cat4/6.png", "images/ingame/cat4/7.png", "images/ingame/cat4/8.png",
                         "images/select/cat1/0.png", "images/select/cat1/1.png", "images/select/cat1/2.png",
                         "images/select/cat1/3.png", "images/select/cat1/4.png", "images/select/cat1/5.png",
                         "images/select/cat1/6.png", "images/select/cat1/7.png", "images/select/cat1/8.png",
                         "images/select/cat2/0.png", "images/select/cat2/1.png", "images/select/cat2/2.png",
                         "images/select/cat2/3.png", "images/select/cat2/4.png", "images/select/cat2/5.png",
                         "images/select/cat2/6.png", "images/select/cat2/7.png", "images/select/cat2/8.png",
                         "images/select/cat3/0.png", "images/select/cat3/1.png", "images/select/cat3/2.png",
                         "images/select/cat3/3.png", "images/select/cat3/4.png", "images/select/cat3/5.png",
                         "images/select/cat3/6.png", "images/select/cat3/7.png", "images/select/cat3/8.png",
                         "images/select/cat4/0.png", "images/select/cat4/1.png", "images/select/cat4/2.png",
                         "images/select/cat4/3.png", "images/select/cat4/4.png", "images/select/cat4/5.png",
                         "images/select/cat4/6.png", "images/select/cat4/7.png", "images/select/cat4/8.png",
                         "images/small/cat1/0.png", "images/small/cat1/1.png", "images/small/cat1/2.png",
                         "images/small/cat1/3.png", "images/small/cat1/4.png", "images/small/cat1/5.png",
                         "images/small/cat1/6.png", "images/small/cat1/7.png", "images/small/cat1/8.png",
                         "images/small/cat2/0.png", "images/small/cat2/1.png", "images/small/cat2/2.png",
                         "images/small/cat2/3.png", "images/small/cat2/4.png", "images/small/cat2/5.png",
                         "images/small/cat2/6.png", "images/small/cat2/7.png", "images/small/cat2/8.png",
                         "images/small/cat3/0.png", "images/small/cat3/1.png", "images/small/cat3/2.png",
                         "images/small/cat3/3.png", "images/small/cat3/4.png", "images/small/cat3/5.png",
                         "images/small/cat3/6.png", "images/small/cat3/7.png", "images/small/cat3/8.png",
                         "images/small/cat4/0.png", "images/small/cat4/1.png", "images/small/cat4/2.png",
                         "images/small/cat4/3.png", "images/small/cat4/4.png", "images/small/cat4/5.png",
                         "images/small/cat4/6.png", "images/small/cat4/7.png", "images/small/cat4/8.png",
                         "images/about_us_back.png", "images/about_us_text.png", "images/aboutus1.png", 
                         "images/acc.png", "images/accelerator.png", "images/back.png", "images/button_back.png",
                         "images/car_back.png", "images/dashboard.png", "images/endLine.png", "images/exit.png",
                         "images/endLineHover.png", "images/exit_back.png", "images/exit_msg.png",
                         "images/help_button_p.png", "images/help_text.png", "images/help1.png",
                         "images/left_pointer.png", "images/loading.png", "images/lossing.png",
                         "images/lost.png", "images/lost_tournament.png", "images/main_menu.png",
                         "images/main_menu_button.png", "images/menu_back.png", "images/menu_bg.png",
                         "images/menu_button_back.png", "images/needle.png", "images/newgame1.png",
                         "images/next_race_button.png", "images/nos_bar.png", "images/nos_button.png", 
                         "images/off.png", "images/on.png", "images/one_on-_one.png", "images/option.png", 
                         "images/pause_back.png", "images/pause.png", "images/options_button.png",
                         "images/option_back.png", "images/pausebutton.png", "images/resume_button.png",
                         "images/right_pointer.png", "images/select.png", "images/select_car.png",
                         "images/select_color.png", "images/select_game.png", "images/select_level.png",
                         "images/select_mode.png", "images/select_tab.png", "images/sound.png",
                         "images/start.png", "images/start_girl.png", "images/startLine.png", 
                         "images/status_back.png", "images/status_button_back.png", "images/tap_msg.png",
                         "images/tournament.png", "images/try_again_button.png", "images/wheelAnimation1.png",
                         "images/winning.png", "images/won.png", "images/won_tournament.png", "images/lock.png",
                         "images/allcar_unlocked.png", "images/category_unlock.png", "images/next2.png",
                         "images/tournament_unlock.png", "images/unlocked_newcar.png",
                         "images/unlockedCar/1.png", "images/unlockedCar/2.png", "images/unlockedCar/3.png",
                         "images/unlockedCar/4.png", "images/unlockedCar/5.png", "images/unlockedCar/6.png",
                         "images/unlockedCar/7.png", "images/unlockedCar/8.png", "images/unlockedCar/9.png",
                         "images/unlockedCar/10.png", "images/unlockedCar/11.png", "images/unlockedCar/12.png",],
		                
                         function() { 
                             console.log("***************************************")
                             console.log(" all assets are loaded ")
                             console.log("***************************************")
                             Crafty.scene('TTSplash');
                         },
                        
                         function(e) {
                             // console.log("progress ", e.total, e.loaded)
                         },

                         function(e) {
                             //console.log("")
                         }

            ) 
    
            loadAudio();
	   		
         },
    };

}($);

