var baseurl = 'http://player.doxamedia.net/';
var playlistwidget = {
    defaults:{
        station     : 'KCAQ', //KSBL-FM, KTYD-FM
        stationname : 'KCAQ',
        frequency   : 'FM 104.7',
        textcolor   : '333333',
        refeshtime  : 10000, // miliseconds
        width       : 400,
        height      : 230,
        recentsnumber: 5,
        showplaying : 0
    },
    init: function(options){
        //this.addSource('css', 'html5audio.css');
        var settings    = this.extend(this.defaults, options);
        var source      = baseurl + 'playlist.php';
                
        source += '?station=' + settings.station + '&textcolor=' + settings.textcolor.replace('#', '') + '&recentsnumber=' + settings.recentsnumber;
        source += '&refeshtime=' + settings.refeshtime + '&stationname=' + settings.stationname + '&frequency=' + settings.frequency;
        source += '&showplaying=' + settings.showplaying;
        
        iframe = '<iframe allowTransparency="true" style="width:100%;" name="nowplaying" frameborder="0" align="top,left" scrolling="no"';
        iframe += 'width="' + settings.width + '" height="' + settings.height + '" src="' + source + '">';
        iframe += '</iframe>';
        window.onload = function(){
            document.getElementById("radioplayer").innerHTML = iframe;
        };
    },
    extend: function(destination,source){
        for(property in source){
            destination[property]=source[property];
        }
        return destination;
    },
    addSource: function(type, source){
        if (type=="js"){ //if filename is a external JavaScript file
            var fileref = document.createElement('script');
            fileref.setAttribute("type","text/javascript");
            fileref.setAttribute("src", baseurl + 'js/' + source);
        }
        else if (type=="css"){
            var fileref = document.createElement("link");
            fileref.setAttribute("rel", "stylesheet");
            fileref.setAttribute("type", "text/css");
            fileref.setAttribute("href", baseurl + 'css/' + source);
        }
        if (typeof(fileref) != "undefined")
            document.getElementsByTagName('head')[0].appendChild(fileref);
    }
}
