  var loaderindicator=0;  
   function audiofunctinallity(id,source,dataobject,onLoadcallback,loadCallBackArgs){
   _thisAud= this;
   this.id=id;
   this.dataobject=dataobject;
   this.source=source;
   this._audioPlayer=null;
   this.loadprogress=null;
   this.startTime=0;
   this.endTime=0;
   this.callbackplay=null;
   this.counter=0;
   this.timer=[];
   this.timeiterator=0;
   this.audiosarray=[];
   windowcounter=0;   
   this.init=function(){
	   this._audioPlayer = document.createElement('audio');
	  if(!! this._audioPlayer.canPlayType('audio/mpeg') === true){
		   this._audioPlayer.setAttribute('src', this.source+".mp3");
	  }else{
		 this._audioPlayer.setAttribute('src', this.source+".ogg");
	  }
	   this._audioPlayer.setAttribute('id', this.id);
	  $('body').append( this._audioPlayer);
		this._audioPlayer=document.getElementById(this.id);	  
			this._audioPlayer.addEventListener("timeupdate",this.playProgress,false);
		   this._audioPlayer.load();	  
	 if(navigator.userAgent.match(/ipad/i)!= null)
	  {
	  this.loadprogress =  window.setInterval(function(){_thisAud.getPercentProg()},50);
	  
		}
	 }  
  this.isPaused=function()
  {
	  return  (_thisAud._audioPlayer.paused)?1:0;
  }
    this.getPercentProg=function(){
  
			  var endBuf =  _thisAud._audioPlayer.buffered.end(0);
		   console.log(endBuf);
			  var soFar = parseInt(((endBuf /  _thisAud._audioPlayer.duration) * 100));
			   console.log(soFar);
			  if(soFar == 100){
			  clearInterval( _thisAud.loadprogress);
			  loaderindicator=1;
			    if(typeof onLoadcallback != "undefined"){				  
				  if(typeof loadCallBackArgs!="undefined")
				  {					  
				   onLoadcallback(loadCallBackArgs);
				   }
				   else
				   onLoadcallback();
				   
				  }
		  }
   }
      
   this.playBackToBack=function(audioarray,callbackplayer){
   if(! _thisAud._audioPlayer.paused){
	_thisAud._audioPlayer.pause();
   }
   this.counter=0;
   this.audiosarray.length=0;
   this.audiosarray=audioarray;
   windowcounter=0;
   this.timeiterator=0;
   for (var i = 0; i < this.timer.length; i++) {
	  clearTimeout(this.timer[i]);} 
  if(this.audiosarray.length>0)
  {
	  while(this.counter<audioarray.length)
	  {
	  
	  var timeings=this.dataobject[audioarray[this.counter]];
	  if(timeings==null)
	  {
	  return;
	  }
  this.timer[this.counter]= setTimeout(function(){
		  extendedFun();
		  
	  },this.timeiterator*1000);
	  this.timeiterator=this.timeiterator+parseFloat(timeings.split("-")[1])-parseFloat(timeings.split("-")[0]);
	  this.counter++
	 }
  }
  else
  {
	  if(typeof callbackplayer !="undefined")
	 this.callbackplay=callbackplayer;
	 else
	 this.callbackplay=null;
  }	  
   }   
   window.extendedFun=function()
   {
	  window.CollisionAudio.play(window.CollisionAudio.audiosarray[windowcounter++],1);
   }   
  this.pauseBackToBack=function()
  {
	  for (var i = 0; i < this.timer.length; i++) {
	  clearTimeout(this.timer[i]);
  }
	if(! _thisAud._audioPlayer.paused){
	_thisAud._audioPlayer.pause();
   }
  }   
  this.play=function(key,notifieraud,callbackplayer){
  
  if(typeof notifieraud =="undefined" || notifieraud!=0)
  {
  for (var i = 0; i < this.timer.length; i++) {
	  clearTimeout(this.timer[i]);
  }
  }  
   if(! _thisAud._audioPlayer.paused){
	_thisAud._audioPlayer.pause();
   }
  
   var timeings=this.dataobject[key];
  
   if(timeings==null)
   {
	  return;
   }
   timeings=timeings.split("-");
	 this.startTime= parseFloat(timeings[0]);
	 this.endTime=parseFloat(timeings[1]);
	 this._audioPlayer.currentTime=this.startTime;
	 this._audioPlayer.play();
	 if(typeof callbackplayer !="undefined")
	 this.callbackplay=callbackplayer;
	 else
	 this.callbackplay=null;
  }   
   this.playProgress=function(){
	  if(_thisAud._audioPlayer.currentTime >= _thisAud.endTime){
	  
		  
				  _thisAud._audioPlayer.pause() ;
				  
				   if(_thisAud.callbackplay != null)
				  _thisAud.callbackplay();
					  _thisAud.pause();
			  }
   }   
   this.pause=function(){   
	  for (var i = 0; i < this.timer.length; i++) {
	  clearTimeout(this.timer[i]);
  }
	  if(! _thisAud._audioPlayer.paused){
	  _thisAud._audioPlayer.pause()
	  }
   }
   
   this.init();
   return _thisAud;
   }