 function audiofunctinallity(id,source,dataobject,onLoadcallback){
_this= 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.playlist=null;
 this.curerntitem=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('progress', this.getPercentProg, false);
this._audioPlayer.addEventListener("timeupdate",this.playProgress,false);

	   this._audioPlayer.load();
       
       if(navigator.userAgent.match(/ipad/i)!= null)
       {
	this.loadprogress=setInterval(function(){
	 _this.getPercentProg();
	 },50);
     }
     else
     {
     if(typeof onLoadcallback != "undefined"){
			     onLoadcallback();
				}
     }
     }
 
 this.getPercentProg=function(){

            var endBuf = this._audioPlayer.buffered.end(0);
            
            var soFar = parseInt(((endBuf / this._audioPlayer.duration) * 100));
            
			if(soFar == 100){
			clearInterval(this.loadprogress);
			if(typeof onLoadcallback != "undefined"){
			     onLoadcallback();
				}
		}
 }
 
 this.play=function(key,callbackplayer){

 if(! _this._audioPlayer.paused){
  _this._audioPlayer.pause();
  this.curerntitem=0;
 }
 
 this.playlist=key;
 _this.backToBackPlay();
 
   if(typeof callbackplayer !="undefined")
   this.callbackplay=callbackplayer;
   else
   this.callbackplay=null;
 }
 
 this.backToBackPlay=function(){
 
if(this.playlist!=null)
{
	alert(this.playlist[this.currentitem])
   if(this.curerntitem <   this.playlist.length){
 var timeings=this.dataobject[this.playlist[this.curerntitem]];
 timeings=timeings.split("-");
    
   this.startTime= parseFloat(timeings[0]);
   this.endTime=parseFloat(timeings[1]);
    
   this._audioPlayer.currentTime=this.startTime;
   
   this._audioPlayer.play();
   }else{
   this.playlist=null;
   this.curerntitem=0;
    if(_this.callbackplay != null)
				_this.callbackplay();
            }
}
   }
 
 this.playProgress=function(){
    if(_this._audioPlayer.currentTime >= _this.endTime)
    {
                _this._audioPlayer.pause() ;
                _this.curerntitem++;
                _this.backToBackPlay();
				
 }
 }
 
 this.pause=function(){
    if(! _this._audioPlayer.paused){
	_this._audioPlayer.pause()
	}
    this.curerntitem=0;
 }
 
 this.init();
 return _this;
 }