var AudioCheck = new Class({
    formats : ["ogg","mp3", "aiff", "wav"],
    check   : function(type){
        if(!!type)
            return this.canPlay(type);
        return this.isSupported();
    },
    isSupported : function(){
        if(!!(document.createElement('audio').canPlayType) == false)
            return false;

        var a = new Audio("");
        return !!( !!(a.canPlayType) ? a.play : false);
        
    },
    canPlay : function(type){
        if(!this.isSupported())
            return false;
        
        type = type.toLowerCase();
        switch(type){
            case "mp3":
                type = "mpeg";
                break;
            case "au":
                type = "basic";
                break;
            case "snd":
                type = "basic";
                break;
            case "wav":
                type = "x-wav";
                break;
            case "aif":
                type = "aiff";
                break;
            case "aifc":
                type = "aiff";
                break;
        }
        
        type = "audio/" + type;            

        var a = new Audio("");
        if (a.canPlayType) {
            return ("no" != a.canPlayType(type)) && ("" != a.canPlayType(type))
        }
        
        return false;
    },
    determineFormat : function(formats){
        dbug.log("AudioCheck::determineFormat(%o)",formats);
        if(!formats) formats = this.formats;
        
        for(var i = 0; i < formats.length; i++){
            if(this.check(formats[i])){
                return formats[i];
            }
        }
    }
});
