 isAudioStart=true;
 function changeAudio(obj){
 if(isAudioStart){
	obj.src="media/crops_new_UI/audio_off.png";
	isAudioStart=false;
	var oo=document.getElementsByTagName('Audio');
	for(var i=0;i<oo.length;i++){
		if(!oo[i].paused)
			oo[i].pause();
	}
 }
 else{
 obj.src="media/crops_new_UI/audio_on.png";
 isAudioStart=true;
 }
}
 


function startGame(){
//activeDevelopment();
activeMinified();
switchToGameCanvas();
CollisionAudio.load();
}	
var detect = new checkBrowsers();
var currentInstructionStatus=1;
	
	var value_json={
	"ball1_worth":1,
	"ball10_worth":10,
	"ball100_worth":100,
	"initail_Score":0,
	"target_score":22,
	"multiplication_factor":1
	}
	
	var AudioArray=[
	"GobblingGlobs_1",
	"GobblingGlobs_2",
	"GobblingGlobs_3",
	"GobblingGlobs_4",
	"GobblingGlobs_5",
	"GobblingGlobs_6",
	"GobblingGlobs_7",
	"GobblingGlobs_8",
	"GobblingGlobs_9",
	"GobblingGlobs_10",
	"GobblingGlobs_11",
	];
	var aud={};
	var path="media/sound/";
	function preloadAudios(){
	
	for(var i=0;i<AudioArray.length;i++){
	aud["index_"+i]=document.createElement('audio');
	if(detect.isFirefox)
	aud["index_"+i].setAttribute('src',path+AudioArray[i]+'.ogg');	
	else
	aud["index_"+i].setAttribute('src',path+AudioArray[i]+'.mp3');	
	 $('body').append(aud["index_"+i]);
	}	
	}
	if(!detect.isIpad)
	{}
	//preloadAudios();
	else{

	
	}
	var AudioStartCount=0;
	/*
	function loadAudioForIpad(){
	
	var ipadAudio = document.createElement('audio');
    if(!!ipadAudio.canPlayType('audio/mpeg') === true){
        ipadAudio.setAttribute('src',path+AudioArray[AudioStartCount]+".mp3");
    }else{
	  ipadAudio.setAttribute('src',path+AudioArray[AudioStartCount]+".ogg");
	}
    ipadAudio.setAttribute('id','ipadAudio');
    $('body').append(ipadAudio);
    ipadAudio.load();
	ipadAudioControl=document.getElementById('ipadAudio');
	AudioStartCount++;
}
	*/
	
	/*Ipad related audio code*/
	
	
var instructionSequence=[
"You control this bubble. Your value is 0.",
"Click anywhere to move your bubble.",
"Click near your bubble to move slowly.",
"Click far away to move fast.",
"Click and hold to speed up. Whee!",
"Click on your bubble exactly to stop.",
"The yellow globs are worth 1. Move your bubble to gobble a 1 and increase your value.",
"Now your value is 1!",
"The pink globs are worth 10. Move your bubble to gobble a 10 and increase your value.",
"1 + 10 = 11 \n\nNow your value is 11!",
"Gobble more globs until you have the same value as the target.",
];   

	var _playvalue=0;
	var _audio = document.createElement('audio');
    if(!!_audio.canPlayType('audio/mpeg') === true){
        _audio.setAttribute('src',"media/sound/GobblingGlobs_1to10.mp3");
    }else{
	  _audio.setAttribute('src',"media/sound/GobblingGlobs_1to10.ogg");
	}
    _audio.setAttribute('id','_audio');
    $('body').append(_audio);
   
    var _audio=document.getElementById('_audio');
	 _audio.load();
    _audio.addEventListener("timeupdate",function(){
        if(_playvalue==1)
        {
            if(_audio.currentTime >=4){
                _audio.pause() ;
				 _playvalue=0;
            }
        }
        if(_playvalue==2)
        {
            if(_audio.currentTime >=7.5 ){
                _audio.pause();
				_playvalue=0;
            }
        }
        if(_playvalue==3)
        {
           if(_audio.currentTime >= 11.5){
                _audio.pause();
				_playvalue=0;
            }
        }
		if(_playvalue==4){
		 if(_audio.currentTime >= 14.4){
                _audio.pause();
				_playvalue=0;
            }
		}
			if(_playvalue==5){
		 if(_audio.currentTime >= 17.8){
                _audio.pause();
				_playvalue=0;
            }
		}
				if(_playvalue==6){
		 if(_audio.currentTime >= 25){
                _audio.pause();
				_playvalue=0;
            }
		}
		
		if(_playvalue==7){
		 if(_audio.currentTime >= 32.5){
                _audio.pause();
				_playvalue=0;
            }
		}
		
		if(_playvalue==8){
		 if(_audio.currentTime >= 35.5){
                _audio.pause();
				_playvalue=0;
            }
		}
		if(_playvalue==9){
		 if(_audio.currentTime >= 42.5){
                _audio.pause();
				_playvalue=0;
            }
		}
		if(_playvalue==10){
		 if(_audio.currentTime >= 48.5){
                _audio.pause();
				_playvalue=0;
            }
		}
		if(_playvalue==11){
		 if(_audio.currentTime>= 53.3){
                _audio.pause();
				_playvalue=0;
            }
		}
		if(_playvalue==12){
		 if(_audio.currentTime>= 53.3){
                _audio.pause();
				_playvalue=0;
            }
		}
		if(_playvalue==13){
		 if(_audio.currentTime>=53.3){
                _audio.pause();
				_playvalue=0;
            }
		}
    },true);

    function step1(){
          _playvalue=1;
        _audio.currentTime=0;
       if(isAudioStart)
		_audio.play();	
    }
function step2(){
          _playvalue=2;
        _audio.currentTime=4.5;
        if(isAudioStart)
			_audio.play();
	
    }function step3(){
          _playvalue=3;
        _audio.currentTime=8;
        if(isAudioStart)
			_audio.play();
	
    }function step4(){
          _playvalue=4;
        _audio.currentTime=11.5;
        if(isAudioStart)
			_audio.play();
	
    }function step5(){
          _playvalue=5;
        _audio.currentTime=14.5;
        if(isAudioStart)
			_audio.play();
	
    }function step6(){
          _playvalue=6;
        _audio.currentTime=21.5;
        if(isAudioStart)
			_audio.play();
	
    }function step7(){
          _playvalue=7;
        _audio.currentTime=25.5;
        if(isAudioStart)
			_audio.play();
	
    }function step8(){
          _playvalue=8;
        _audio.currentTime=33;
        if(isAudioStart)
			_audio.play();
	
    }function step9(){
          _playvalue=9;
        _audio.currentTime=36                                                                    ;
        if(isAudioStart)
			_audio.play();
	
    }function step10(){
          _playvalue=10;
        _audio.currentTime=43;
        if(isAudioStart)
			_audio.play();
	
    }function step11(){
          _playvalue=11;
        _audio.currentTime=49;
        if(isAudioStart)
			_audio.play();
	}
   
	function step12(){
          _playvalue=12;
        _audio.currentTime=49;
        if(isAudioStart)
			_audio.play();
	}
   function step13(){
          _playvalue=13;
        _audio.currentTime=49;
        if(isAudioStart)
			_audio.play();
	}
   
	
	/*ipad related audio code ends*/
	
	function stopAllAudio(){
	for(key in aud){
	if(! aud[key].paused)
	aud[key].pause();
	}
	var o=document.getElementsByTagName('audio');
	for(var i=0;i<o.length;i++){
	if(!o[i].paused)
	o[i].pause();
	}
	}
	var AudioCount=0;
	var isInstructionChangeInProgress=false;

/*utility method for checking browser*/

function checkBrowsers(){
var ua = navigator.userAgent.toLowerCase();
this.isIpad = (ua.indexOf('ipad') != -1);
this.isAndroid = ua.indexOf('android') != -1;
this.isIE = ua.indexOf('msie') != -1;
this.isWebkit = ua.indexOf('webkit') != -1;
this.isFirefox = ua.indexOf('firefox') != -1;
this.isSafari=ua.indexOf('safari')!=-1;
}

jQuery(function(){    
	/*adding click event to play next*/
	$('#next_step_ok').bind('click touchstart',function(){
	ActivateGameSequenceWise(currentInstructionStatus);
	CollisionAudio.load();
	//_audio.load();
	});
	
	$('#startTut').bind('click touchstart',function(){
		$('#preloader_image').show();
	_audio.load();
	_audio.addEventListener('canplaythrough',function(){
		$('#preloader_image').hide();
	ActivateGameSequenceWise(currentInstructionStatus);
	
	});
	
	});
	
	$('#play_next').bind('click touchstart',function(){
  //  _audio.load();
	ActivateGameSequenceWise(currentInstructionStatus);	
	});
	$('.close').bind('click touchstart',function(){
	window.close();
	});
		
	
		//originalPosition
		$("#green_box").draggable({	//drag and drop for desktop.
             revert : "false",
             containment : "canvas_drop",
             start : function(event, ui) {
               
             },drag:function(event,ui){
        
             },
             stop:function(event, ui){
             if(ui.offset.left+24<0 ||ui.offset.left>ig.system.width-$(event.target).width()+20||ui.offset.top>ig.system.height-$(event.target).height()+21 ||ui.offset.top+21<0)   {
             $(event.target).css({'left':ui.originalPosition.left,'top':ui.originalPosition.top}); 
            }
           }
         });
	if(detect.isIpad || detect.isAndroid)
		{
		document.addEventListener("touchstart",function(e){e.preventDefault();},false);
		init();
		}
    startGame();
	
	
});

function touchHandler(event)
{
    var touches =event.changedTouches;
    var first=touches[0];
    var type = "";
         switch(event.type)
{
        case "touchstart":
        case "mousedown" :
        type = "mousedown"; break;
        case "touchmove": 
        case "mousemove" :
        type="mousemove"; break;        
        case "touchend": 
        case "mouseup" :
        type="mouseup"; break;
        default: return;
}
    var simulatedEvent = document.createEvent("MouseEvent");
    simulatedEvent.initMouseEvent(type, true, true, window, 1,first.screenX, first.screenY,first.clientX,first.clientY,false,false, false, false, 0/*left*/, null);
    first.target.dispatchEvent(simulatedEvent);
    event.preventDefault();
}

function init() 
{
 document.getElementById('green_box').addEventListener("touchstart", touchHandler, true);
 document.getElementById('green_box').addEventListener("touchmove", touchHandler, true);
 document.getElementById('green_box').addEventListener("touchend", touchHandler, true);
 document.getElementById('green_box').addEventListener("touchcancel", touchHandler, true);    
}

function changeInstrutionInHtml(text){
document.getElementById('instruction_box').innerHTML=(text=='undefined' ||text==null)?'':text;
}

function ActivateGameSequenceWise(num){
    if(num=='undefined' || num==0)
	{
	return false;
	}
	if(isInstructionChangeInProgress){
	return false;
	}
	isInstructionChangeInProgress=true;
    switch(num){
    case 1:
	document.getElementById('startTut').style.display="none";
	document.getElementById('next_step_ok').style.display="block";
    TutorialStart();
    changeInstrutionInHtml(instructionSequence[currentInstructionStatus-1]);
     currentInstructionStatus++;
	 isInstructionChangeInProgress=false;	
		stopAllAudio();	 
	 if(!detect.isIpad || detect.isIpad){
	/* ipadAudioControl.addEventListener("canplaythrough",function(){
		if(isAudioStart)	
		ipadAudioControl.play();
	 },false);
	 */
	 step1();
	 }else{
	 aud.index_0.load();
	 aud.index_0.addEventListener("canplaythrough",function(){
	if(isAudioStart)	
		aud.index_0.play();
	 },false);
	 
	 } 
	 
    break;
    case 2:

        document.getElementById('next_step_ok').style.display='none';
        arrow1_Sprite.stop(arrow1_Sprite);
        arrow2_Sprite.stop(arrow2_Sprite);
    
        var arrowList=document.getElementsByClassName('arrow');
        for(var i=0;i<arrowList.length;i++){
        arrowList[i].style.display='none';    
        }

        changeInstrutionInHtml(instructionSequence[currentInstructionStatus-1]);
        ig.game.BindKey();
        var player=ig.game.getEntitiesByType(EntityPlayer)[0];
        if(typeof player!='undefined'){
      /*  if(player!=0){
        player.friction={x:0,y:0};
    }*/
    }
     currentInstructionStatus++;
		isInstructionChangeInProgress=false;
		stopAllAudio();
	 if(!detect.isIpad || detect.isIpad){
		 step2();
		}else{
		aud.index_1.load();
	  aud.index_1.addEventListener("canplaythrough",function(){
	   if(isAudioStart)
	  aud.index_1.play();
	 },false);
	 }
    break;
 
	case 3:
	 setTimeout(function(){
	changeInstrutionInHtml(instructionSequence[currentInstructionStatus-1]);
	currentInstructionStatus++;
	isInstructionChangeInProgress=false;
	stopAllAudio();
	 if(!detect.isIpad || detect.isIpad){
		 step3();
		}else{
	 aud.index_2.load();
     aud.index_2.addEventListener("canplaythrough",function(){
	   if(isAudioStart)
	 aud.index_2.play();
	 },false);
	}
	},800);
	break;
	
    case 4:
	 setTimeout(function(){
	changeInstrutionInHtml(instructionSequence[currentInstructionStatus-1]);
	currentInstructionStatus++;
	isInstructionChangeInProgress=false;
		stopAllAudio();
	 if(!detect.isIpad || detect.isIpad){
		 step4();
		}else{
		 aud.index_3.load();
     aud.index_3.addEventListener("canplaythrough",function(){
	   if(isAudioStart)
	 aud.index_3.play();
	 },false);
	 }
	 },800);
	break;
    case 5:
	 setTimeout(function(){
	changeInstrutionInHtml(instructionSequence[currentInstructionStatus-1]);
	currentInstructionStatus++;
	isInstructionChangeInProgress=false;
			stopAllAudio();
		 if(!detect.isIpad || detect.isIpad){
		 step5();
		}else{
		 aud.index_4.load();
		aud.index_4.addEventListener("canplaythrough",function(){
		if(isAudioStart)
		aud.index_4.play();
		},false);
		}
	},800);
	break;
    case 6:	
    setTimeout(function(){
	changeInstrutionInHtml(instructionSequence[currentInstructionStatus-1]);
	currentInstructionStatus++;
	isInstructionChangeInProgress=false;
		stopAllAudio();
		 if(!detect.isIpad || detect.isIpad){
		 step6();
		}else{
		 aud.index_5.load();
		aud.index_5.addEventListener("canplaythrough",function(){
		if(isAudioStart)
		aud.index_5.play();
		},false);
		}
	},800);
    break;
   
   case 7:
    setTimeout(function(){
    changeInstrutionInHtml(instructionSequence[currentInstructionStatus-1]);
	
    var aa=ig.game.static_entity_creator(EntityBall1,0,false);
   if(typeof aa!='undefined'){
    aa.vel.x=0;
    aa.vel.y=0;
    }
    currentInstructionStatus++;
    isInstructionChangeInProgress=false;
		stopAllAudio();
	 if(!detect.isIpad || detect.isIpad){
		 step7();
		}else{
		 aud.index_6.load();
		aud.index_6.addEventListener("canplaythrough",function(){
		if(isAudioStart)
		aud.index_6.play();
		},false);
		}
	},800);
    break;  
  case 8:
    setTimeout(function(){
	changeInstrutionInHtml(instructionSequence[currentInstructionStatus-1]);
    document.getElementById('next_step_ok').style.display='block'
	 $('#arr1').css({'background-position':'-1206px 0','margin':'103px 0px 0px 791px','display':'block'});
    currentInstructionStatus++;
   isInstructionChangeInProgress=false;
  	stopAllAudio();
	 if(!detect.isIpad || detect.isIpad){
		 step8();
		}else{
		 aud.index_7.load();
		aud.index_7.addEventListener("canplaythrough",function(){
		if(isAudioStart)
		aud.index_7.play();
		},false);
		}
	},800);
    ig.game.unbindKey();
   break;

   case 9:
	ig.game.BindKey();
      document.getElementById('next_step_ok').style.display='none'
      changeInstrutionInHtml(instructionSequence[currentInstructionStatus-1]);
	  $('#arr1').css({'display':'none'});
     var aa=ig.game.static_entity_creator(EntityBall10,1,false);
	if(typeof aa!='undefined'){
        aa.vel.x=0;
        aa.vel.y=0;
        }
		
		currentInstructionStatus++;
	  isInstructionChangeInProgress=false;
	 	stopAllAudio();
	 if(!detect.isIpad || detect.isIpad){
		 step9();
		}else{
		 aud.index_8.load();
		aud.index_8.addEventListener("canplaythrough",function(){
		if(isAudioStart)
		aud.index_8.play();
		},false);
	}
    break;
   
   case 10:
    setTimeout(function(){
	ig.game.unbindKey();
	changeInstrutionInHtml(instructionSequence[currentInstructionStatus-1]);
    document.getElementById('next_step_ok').style.display='block';
	
	 $('#arr1').css({'background-position':'-1206px 0','margin':'103px 0px 0px 791px','display':'block'});
	currentInstructionStatus++;
	isInstructionChangeInProgress=false;
		stopAllAudio();
		 if(!detect.isIpad || detect.isIpad){
		 step10();
		}else{
		 aud.index_9.load();
		aud.index_9.addEventListener("canplaythrough",function(){
		if(isAudioStart)
		aud.index_9.play();
		},false);
	}
    },800);
    break;
   
   case 11:
    setTimeout(function(){
	ig.game.BindKey();
    document.getElementById('next_step_ok').style.display='none';
    document.getElementById('play_next').style.display='block'
	document.getElementById('arr1').style.display='none';
	document.getElementById('arrow_target').style.display='block'
    changeInstrutionInHtml(instructionSequence[currentInstructionStatus-1]);
    currentInstructionStatus++;
	isInstructionChangeInProgress=false;
		 if(!detect.isIpad || detect.isIpad){
		 step11();
		}else{
		stopAllAudio();
		 aud.index_10.load();
		aud.index_10.addEventListener("canplaythrough",function(){
		if(isAudioStart)
		aud.index_10.play();
		},false);
	}
    },800)
    break;
   
   case 12:
   isInstructionChangeInProgress=false;
     window.close();
    }
}

 function TutorialStart(){
 $('.disable').removeClass('disable');
 arrow1_Sprite= new sprites(document.getElementById('arr1'),2000,31,30,1);
 arrow2_Sprite= new sprites(document.getElementById('arr2'),2000,31,30,1);
 arrow1_Sprite.start(arrow1_Sprite,0,[a]);
 arrow2_Sprite.start(arrow2_Sprite,0,[a])
 }

  	var playvalue=0;
	var audioPlayer = document.createElement('audio');
    if(!!audioPlayer.canPlayType('audio/mpeg') === true){
        audioPlayer.setAttribute('src',"media/sound/MathGame_combined_SFX.mp3");
    }else{
	  audioPlayer.setAttribute('src',"media/sound/MathGame_combined_SFX.ogg");
	}
    audioPlayer.setAttribute('id','CollisionAudio');
    $('body').append(audioPlayer);
    audioPlayer.load();
    var CollisionAudio=document.getElementById('CollisionAudio');
    CollisionAudio.addEventListener("timeupdate",function(){
        if(playvalue==1)
        {
            if(CollisionAudio.currentTime >= 2){
                CollisionAudio.pause() ;
				 playvalue=0;
            }
        }
        if(playvalue==2)
        {
            if(CollisionAudio.currentTime >= 6){
                CollisionAudio.pause();
				playvalue=0;
            }
        }
        if(playvalue==3)
        {
           if(CollisionAudio.currentTime >= 10){
                CollisionAudio.pause();
				playvalue=0;
            }
        }
		if(playvalue==4){
		 if(CollisionAudio.currentTime >= 12){
                CollisionAudio.pause();
				playvalue=0;
            }
		}
    },true);

    function PlayCollision() {
          playvalue=1;
        CollisionAudio.currentTime=1;
        if(isAudioStart)
CollisionAudio.play();
	
    }

    function playLevelComplete(){
	setTimeout(function(){
        playvalue=2;
          CollisionAudio.currentTime=3.5;
         if(isAudioStart)
CollisionAudio.play();
				},900);
    }

    function playGameComplete() {
		setTimeout(function(){
        playvalue=3;
        CollisionAudio.currentTime=7;
       if(isAudioStart)
CollisionAudio.play();
			},200);
    }

	function playIncorrect() {

	setTimeout(function(){
        playvalue=4;
        CollisionAudio.currentTime=11;
 if(isAudioStart)
CollisionAudio.play();
		},600);
    }
    function textHighlight() {
        $('#score').animate({"font-size":"42pt"},200,function(){
            $(this).animate({'font-size':'64pt'},200,function(){
                $(this).animate({'font-size':'45pt'},100,function(){});

            });
        });
    }
 function a(){}
 
    function activeDevelopment(){

        var fileref=document.createElement('script')
        fileref.setAttribute("type","text/javascript")
        fileref.setAttribute("src","lib/impact/impact.js");
        document.getElementsByTagName("head")[0].appendChild(fileref)
        fileref=document.createElement('script')
        fileref.setAttribute("type","text/javascript")
        fileref.setAttribute("src","lib/game/main.js");
        document.getElementsByTagName("head")[0].appendChild(fileref);   
    }
function activeMinified(){
      var fileref=document.createElement('script');
        fileref.setAttribute("type","text/javascript");
        fileref.setAttribute("src","game.min.js");
        document.getElementsByTagName("head")[0].appendChild(fileref);
}

    function switchToGameCanvas(){
        document.getElementById("Container").style.display="none";
		document.getElementById("canvas_background").style.display="block";
   	
	};

	window.onorientationchange = detectIPadOrientation;
    window.onload = detectIPadOrientation;
    function detectIPadOrientation(){
        if((navigator.userAgent.indexOf('iPad') != -1)) {            
       if(window.orientation % 180 == 0 ) {
       $('meta[name=viewport]').attr('content','width=768, height=1024, initial-scale=0.75, maximum-scale=0.75, user-scalable=no');
       }  else if(window.orientation % 90 == 0) {
       $('meta[name=viewport]').attr('content','width=1024, height=768, initial-scale=1, maximum-scale=1.0, user-scalable=no');
       }
      }
  }
  
var sprites = function(domelement1, duriation, numberofsprites, harizontalsprites, verticalsprites) {
    this.domelement = domelement1;
    //refer to element that we want animate
    this.timeslice = duriation;
    //time for animation
    this.numberofsprites = numberofsprites;
    //number of small images in the sprite image
    this.harizontalsprites = harizontalsprites;
    //number of horizontal images
    this.verticalsprites = verticalsprites;
    //number of vertical images
    this.setinterval//setInterval for animation
    this.moveinterval//setInterval for motion
    this.spritecount = 0;
    this.xposition
    this.yposition
    this.width
    this.height
    this.positions
    this.noofloops
    this.z = 1;
    this.movement
    this.shift
    this.whichsprite
};

// prototypes for sprite class
sprites.prototype = {
    start : function(element, numberofloops, callback) {
        element.noofloops = numberofloops;
        element.spritecount = 1;
        element.setinterval = setInterval(function() {
            if (detect.isFirefox) {
                element.positions = element.domelement.style.backgroundPosition;
                element.xposition = element.positions.split(" ")[0].split("p")[0];
                element.yposition = element.positions.split(" ")[1].split("p")[0];
            } else {
                element.xposition = element.domelement.style.backgroundPositionX.split("p")[0];
                element.yposition = element.domelement.style.backgroundPositionY.split("p")[0];
            }
            element.xposition = parseInt(element.xposition);
            element.yposition = parseInt(element.yposition);
            element.width = parseInt(element.domelement.style.width.split("p")[0]);
            element.xposition = element.xposition - element.width;
            if (-(element.xposition) > (element.harizontalsprites - 1) * element.width) {
                element.xposition = 0;
                element.height = element.domelement.style.height.split("p")[0];
                element.yposition = element.yposition - element.height;
                if (-(element.yposition) > (element.verticalsprites * element.height)) {
                    element.yposition = 0;
                }
            }
            element.spritecount++;
            if (detect.isFirefox) {
                element.domelement.style.backgroundPosition = element.xposition + "px" + " " + element.yposition + "px";
            } else {
                element.domelement.style.backgroundPositionX = element.xposition + "px";
                element.domelement.style.backgroundPositionY = element.yposition + "px";
            }
            if (element.spritecount >= element.numberofsprites) {
                element.spritecount = 1;
                if (element.noofloops == 0) {
                    element.reset(element);
                }
                if (element.noofloops != 0) {
                    if (element.z == element.noofloops) {
                        element.setinterval = clearInterval(element.setinterval);
                        this.callback = callback;
                        if ( typeof this.callback != 'undefined') {
                            if (this.callback.length != 0) {
                                this.firstelement = this.callback[0];
                                this.callback.reverse();
                                this.callback.pop();
                                this.callback.reverse();
                                this.firstelement();
                            }
                        }
                    } else {
                        element.z++;
                    }
                }
            }
        }, Math.floor(element.timeslice / element.numberofsprites));
    },
    stop : function(element) {
        if (element.setinterval != "undefined")
            element.setinterval = clearInterval(element.setinterval);
    },
    reset: function(element) {
        if (detect.isFirefox) {
            element.domelement.style.backgroundPosition = "0px 0px";
        } else {
            element.domelement.style.backgroundPositionX = "0px";
            element.domelement.style.backgroundPositionY = "0px";
        }
    }
};
	
numberWithCommas=function(x){
    return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
		